vitakot
vitakot

Reputation: 3844

Load native shared library from another Android application

I need to distribute an application (a player), which depends on a native library built for a given ARM version and extension (Tegra, Neon). This native library is quite large so I can’t distribute all its versions in one universal package. So I decided to split the application into one small universal .apk and more specialized .apks – plug-ins without any activities.

How can I access a specialized native shared library in the plug-in app from the main host application? Is it possible to use simply

System.loadLibrary("path_to_library"); 

If so, how can I get the path to that library?

How to solve this problem in case it is not possible?

Upvotes: 7

Views: 4313

Answers (2)

Alex Cohn
Alex Cohn

Reputation: 57173

Eight years later, the major concerns of the TS have been addressed: there are splits that can produce smaller APK for each ABI, there are app bundles that allow easier packaging, there are extensions that even allow to delay download of a native library until it is really needed by the app…

Still, the same technique to System.load("/data/data/{app-package}/lib/lib{library-name}.so") still works, and may be useful in some scenarios.

Upvotes: 1

Renate
Renate

Reputation: 811

System.loadLibrary() takes a library name and maps it to a full path somehow.

foo => libfoo.so

The system normally checks the apk itself and then usually /system/lib/

If you have a full path, use System.load()

In any case it will be a hassle to manage the location of your lib unless it's either in the apk or with all the system libs.

I'd just pack the specific lib with the apk.

Upvotes: 1

Related Questions