Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best approach to load multiple native libraries in Android App

I have an app which makes use of 3 different JAR libraries...lets call them a.jar, b.jar and c.jar. Each of these JARS have an accompanied native C++ shared object.

Now, both a.jar and b.jar import and use c.jar.

So, my question is - what is the best approach when loading the native libs using system.loadLibrary ? Can I just load them all from my app code or do they have to be loaded by the respective JAR ? If I load them from the respective JAR file, will load in a separate thread?

like image 346
Drake Amara Avatar asked Nov 04 '22 10:11

Drake Amara


1 Answers

It is Classes' responsibility to load native libraries.

Let's assume every jar file also has classes called A, B and C. All those classes needs to load their native companions most probably via a static way.

class A { 
    static { 
        System.loadLibrary(“A”); 
    }

    C c;
} 

class C { 
     static { 
         System.loadLibrary(“C”); 
     }
} 

In such structure it will be the class loader who loads and initialize class C when you access class A.

like image 55
auselen Avatar answered Nov 09 '22 04:11

auselen