N0un N0un - 3 months ago 37
Android Question

Why "x86" library is installed on a "armeabi-v7a" emulator instead of "armeabi-v7a" library?

To introduce my problem, I have an application using NDK compiled only for "armeabi-v7a" and "x86" ABIs. So compilation gives me:

Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersion 10 in /home/**********/AndroidManifest.xml
[armeabi-v7a] Gdbserver : [arm-linux-androideabi-4.9] libs/armeabi-v7a/gdbserver
[armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup
[x86] Gdbserver : [x86-4.9] libs/x86/gdbserver
[x86] Gdbsetup : libs/x86/gdb.setup
[armeabi-v7a] Install : libNativeFFMPEG.so => libs/armeabi-v7a/libNativeFFMPEG.so
[armeabi-v7a] Install : libavcodec-56.so => libs/armeabi-v7a/libavcodec-56.so
[armeabi-v7a] Install : libavutil-54.so => libs/armeabi-v7a/libavutil-54.so
[armeabi-v7a] Install : libswscale-3.so => libs/armeabi-v7a/libswscale-3.so
[x86] Install : libNativeFFMPEG.so => libs/x86/libNativeFFMPEG.so
[x86] Install : libavcodec-57.so => libs/x86/libavcodec-57.so
[x86] Install : libavutil-55.so => libs/x86/libavutil-55.so
[x86] Install : libswscale-4.so => libs/x86/libswscale-4.so


My problem is maybe indicated by this warning? (This is not the same ffmpeg library version on the two target ABIs but I don't think it is the problem)

Then, I create an emulator with CPU/ABI = (ARM) armeabi-v7a and my lib is not loaded when the application started (but with an "x86" based device, "x86" lib is loaded and works). When I explore it (the emulator) with a shell, I can see that:

lrwxrwxrwx install 2016-07-20 10:06 lib -> /data/app/com.**********/lib/x86


Only "x86" lib is installed... Explanations please?

(I have the same problem testing on a Samsung Galaxy S3, the CPU should be a ARM Cortex-A9 and this CPU implements ARMv7-A architecture. But my library is not find either...)

&&&&&&&&&&&&&& AFTER SOME MANIP I FIX ERROR IN ANDROID.MK &&&&&&&&&&&&&&

If you're interested by exception generated when I call System.loadLibrary(), this is following:

07-20 12:31:23.360: D/dalvikvm(3671): Trying to load lib /data/app-lib/com.**********/libNativeFFMPEG.so 0x40cdc118
07-20 12:31:23.370: W/System.err(3671): java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libswscale-3.so" needed by "libNativeFFMPEG.so"; caused by load_library(linker.cpp:745): library "libswscale-3.so" not found
07-20 12:31:23.370: W/System.err(3671): at java.lang.Runtime.loadLibrary(Runtime.java:371)
...


But when I look into /data/app-lib/com.**********, I find my "armeabi-v7a" libs!!

root@android:/data/app-lib/com.********** # ls
gdbserver
libNativeFFMPEG.so
libavcodec-56.so
libavutil-54.so
libswscale-3.so


But it still the exception!
When I try to load swscale like System.loadLibrary("swscale-3"); I've got following exception:

07-20 12:56:36.351: E/dalvikvm(4174): dlopen("/data/app-lib/com.**********/libswscale-3.so") failed: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libavutil-54.so" needed by "libswscale-3.so"; caused by load_library(linker.cpp:745): library "libavutil-54.so" not found
07-20 12:56:36.361: W/System.err(4174): java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libavutil-54.so" needed by "libswscale-3.so"; caused by load_library(linker.cpp:745): library "libavutil-54.so" not found
07-20 12:56:36.361: W/System.err(4174): java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libavutil-54.so" needed by "libswscale-3.so"; caused by load_library(linker.cpp:745): library "libavutil-54.so" not found


And when I try the same to load avutil-54, I have the same exception of "NativeFFMPEG" (but with libavutil-54.so)

Answer

Finally resolved my problem with @user1056837's help.

Strange thing I need to search about is that :

For ABI "x86" (at least?), when you want to use a libmylib.so which depends on other libraries, you just have to load libmylib.so:

System.loadLibrary("mylib");

But for ABI "armeabi-v7a" (at least?), you have to manually load your lib, your lib's dependencies, and your lib's dependence's dependencies...

System.loadLibrary("dep1");
System.loadLibrary("dep2");
System.loadLibrary("mylib");

I don't have the clear explanation for now, but I'll find it. I hope it can help someone.

EDIT: The problem is not about the target arch but about my native code/libraries compilation.