KeepSafe/ReLinker

ReLinkerInstance SingleInstance

hjf900202 opened this issue · 1 comments

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

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?