0

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)

N0un
  • 868
  • 8
  • 31
  • What's inside your final apk file? Do you have both **x86** and **armeabi-v7a** directories with necessary libraries? If not - look at ABI filters in java module. – c4pQ Jul 20 '16 at 12:13
  • Yes I have both in the generated .apk, with libraries inside @user1056837 – N0un Jul 20 '16 at 12:17
  • I can suggest to use java function `System.loadLibrary()` at application start and catch its exception. In exception message there would be information, where the system tries to find your library. It could be useful. – c4pQ Jul 20 '16 at 12:28
  • I believed, it should have printed the list of directories, where it couldn't find the library. Then next question. Do you have in your apk file only two directories with native libs (i.e. x86, armeabi-v7a)? And is your `loadLibrary` sequence correct (I believe it is, but maybe there's some strange behavior on x86; I mean swscale is loaded before ffmpeg)? – c4pQ Jul 20 '16 at 12:45
  • Ok I update my post (again...). I have correct "armeabi-v7a" libraries in my emulator, but loadLibrary still failing. I just call it like that (surrounded by a "try/catch") **System.loadLibrary("NativeFFMPEG");** – N0un Jul 20 '16 at 12:52
  • Try to load **swscale** and other libs manually before loading **NativeFFMPEG**. So you'll have several `loadLibrary`calls for each of your shared libraries. – c4pQ Jul 20 '16 at 12:55
  • Strange exception : it seems like it detect that swscale depended from avutil, but when I want to load avutil, it produces an exception similar to NativeFFMPEG loading (show edit) @user1056837 – N0un Jul 20 '16 at 13:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117817/discussion-between-user1056837-and-n0un). – c4pQ Jul 20 '16 at 13:07

1 Answers1

1

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.

N0un
  • 868
  • 8
  • 31