Reputation: 7866
I am currently porting a library from Linux to Android and I am having some trouble.
The lib has an extension system : it will look for all the files with a particular extension in the folder /usr/local/lib/{thelibname}/extensions/
, check if they are dynamic libraries, and load them and call a handler if it is the case.
However, I don't think it is possible to tinker with the base filesystem folders in Android. I looked into assets but they did not convince me, it looks like they are more intended for images, audio, etc...
Is there another way to embed some files in an .apk and load them afterwards by enumerating a DIR*
and calling dlopen
?
The other possibility would be to put the extensions with the app data but I don't know if there is a standard path for this that I could hardcode in the lib, is there? And I don't how to put some stuff in the data at the installation of the apk ? (I use QtCreator for the generation of the APK)
Upvotes: 1
Views: 2371
Reputation: 57173
You can easily load extension libraries from anywhere in the file system, including shared folders like /sdcard/
and her children. Any app (and native libraries therein) can gain full read access to /sdcard/
with READ_EXTERNAL_STORAGE permission.
This way you can establish a folder where the extensions will be updated not necessarily by a single APK (note the changes for WRITE_EXTERNAL_STORAGE in KitKat).
If you want to deploy all extension libraries as part of the APK, it's easiest to put them in the standard folder that is used to pack the APKs (for ADT, it's ${project_root}/libs/armeabi
) and then they will be automagically installed in /data/app-lib/${app_package}
. This approach allows to prepare an APK for multiple architectures, preparing appropriate files in ${project_root}/libs/x86
, etc.
Note that all libraries must have lib prefix and .so suffix, so e.g. mylib.so
or libcrypto.so.6
will not work, even though theoretically such libraries can be loaded by dlopen()
.
Your app has read access to the /data/app-lib/${app_package}
directory, so you can scan it either from C code, or from Java. In Java, its easy to resolve the ${app_package}
even if you don't want to hardcode this name. Simply call getApplicationContext().getPackageName()
.
In C, you can use /proc/${pid}
to find the full path to your shared library, and this way you will also know the path to the extensions.
Upvotes: 0
Reputation: 7866
Okay, I found another question which helped me to solve my problem :
How to integrate native runtime library with dlopen on NDK?
Upvotes: 1