I have an Android activity where I'm executing NDK compiled code (command line program) with:
Runtime.getRuntime().exec(myCommand);
and load the needed shared libraries with:
static {
System.loadLibrary(myLib);
}
but when running my project and printing the output from error stream I get the following error:
link_image[1963]: 7520 could not load needed library 'libmyLib.so' for './myCommand'
(load_library[1105]: Library 'libmyLib.so' not found)CANNOT LINK EXECUTABLE
I assure libmyLib.so
does exist in my project under libs/armeabi/
directory and it's copied to my Android device under /data/data/myProject.path.package/lib/
directory. Owner and group of both executable and library are system:system
and permissions are ok as well.
When executing the command from adb shell in the beginning I get the same error but then I can set LD_LIBRARY_PATH
and it runs ok:
./adb shell
export LD_LIBRARY_PATH=/data/data/myProject.path.package/lib:$LD_LIBRARY_PATH
/data/data/myProject.path.package/myCommand
So the question is, how to do that from java Android project?
Note: I'm using Linux, Eclipse + Sequoyah, NDK-r5b, Android 2.3.6 (API 10) on GT-P1010.
Solved: you can use exec(String prog, String[] envp)
. In my case this was:
String[] envp = {"LD_LIBRARY_PATH=/data/data/cse.ecg.dcmtk/lib:$LD_LIBRARY_PATH"};
Runtime.getRuntime().exec(myCommand, envp);
The issue now is that with exec()
the process executed can't resolve hostnames (it does from adb shell; Internet permission is set). Any hint about that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With