Search code examples
androidandroid-source

Utilising system shared libraries in Android


In Android the PackageManager class has the function getSharedLibraries which returns a list of shared libraries which are built into the os.

What I want to be able to do is use one of these libraries via reflection in order to call some functionality.

Some background, I will be implementing my own system library in AOSP in the future but for now am trying to test how I would implement the above functionality.

In my build of Android there is a system shared library called android.ext.services which I am testing with. I have tried loading via System.loadLibrary("android.ext.services") but this throws an UnsatisfiedLinkError.

What am I missing in order to load the android.ext.services library and access it via reflection?

I have come across various sources that somewhat imply I would have to have a local copy of the library in my project though I don't see why I can't get that from the os.


Solution

  • Turns out you can all you need to do is link the library in the applications manifest. This will tell the system to include the library's code in the class loader for the package.

    https://developer.android.com/guide/topics/manifest/uses-library-element