Rajan
Rajan

Reputation: 322

Loadind system shared library runtime in Android

I need to write an application, which will be using a shared library. I need that application to be installed on devices with Android 1.6 and above. I have added the shared library information on the manifest file as follows:

<uses-library android:name="com.google.android.maps" android:required="false" />

Now, the android:required field is added from Android 2.1 above and this tag will be ignored by the Android 1.6, and hence the application will fail to install saying " INSTALL_FAILED_MISSING_SHARED_LIBRARY".

My question is that, is there any way by which, I need not define the shared library information in the manifest and instead I can load the system library ("com.google.android.maps" in my case) dynamically and use reflection to access the class and methods of the library?

Upvotes: 1

Views: 537

Answers (2)

Rajan
Rajan

Reputation: 322

I got this solved. It is not required to mentioned the uses-library in the manifest file. The library can be loaded dynamically and we can get the class and methods loaded from that.

The above mentioned solution of loading the library with System.loadlibray did not work. Instead I used this method to achive it:

new DexClassLoader("/system/framework/google_sample.jar", "/tmp", null, myService.me.getClassLoader());

After this an application can load the class and call the method.

Thanks for the help..

Upvotes: 1

user1103589
user1103589

Reputation:

I searched a bit, and I found this piece of code,

    static {
try {
    System.loadLibrary("DsmShared");
    System.loadLibrary("DsmTestLib");
}
catch( UnsatisfiedLinkError e ) {
     System.err.println("Native code library failed to load.\n" + e);
 }
} 

Also, is your system shared library writen in c++?

Upvotes: 1

Related Questions