1

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?

Rajan
  • 292
  • 2
  • 10

2 Answers2

1

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++?

  • Hi Arno, Thanks for the reply. The API that you mentioned will not work as, that will look for the libarary in the current application's directory. If it is not found, that will throw exception. The library I want to link to is the system shared library (google maps library per say) and I do not have any other information about it. In that case how to dynamically load and link the library with my application is my question. – Rajan Jun 14 '12 at 03:29
  • Hi Rajan, I see, what you can do is download the library on first run, and then load it with this method, here is how you load it: http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog and then you check it with this method. Hope you can figure it out ;) –  Jun 15 '12 at 14:15
1

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..

Rajan
  • 292
  • 2
  • 10