KeepSafe / ReLinker

A robust native library loader for Android.
Apache License 2.0
3.23k stars 371 forks source link

ReLinkerInstance SingleInstance #69

Closed hjf900202 closed 3 years ago

hjf900202 commented 4 years ago

Currently load library use "new ReLinkerInstance().loadLibrary()", so "ReLinkerInstance.loadedlibraries" will be invalid. Can support ReLinkerInstance SingleInstance?

consp1racy commented 4 years ago

ReLinkerInstance.loadedLibraries will be empty every call, but library was loaded from first call, so it can be referenced from second call.

Example 1: I have two libraries, libTwo.so depends on libOne.so. I call ReLinker.loadLibrary(context, "one"). libOne.so is now loaded and can be referenced. I call ReLinker.loadLibrary(context, "two"). libTwo.so is now loaded and can be referenced.

Example 2: I have two libraries, libTwo.so depends on libOne.so. I call ReLinker.loadLibrary(context, "two"). I get java.lang.UnsatisfiedLinkError because libOne.so is not loaded.

What you can do in your classes:

class MyClassWhichNeedsNativeLibrary {

    private static boolean isNativeInit = false;

    public MyClassWhichNeedsNativeLibrary(Context context) {
        if (!isNativeInit) {
            ReLinker.loadLibrary(context, "mylib");
            isNativeInit = true;
        }
    }

    public void doSomething() {
        // ...
    }
}

Why do you want singleton?