2

This question is a subsequent thread following this other question of mine.

After finally managing to successfully building the apk file using gradle and cmake to integrate FFMPEG into an Android project I am facing a new exception which is thrown when calling System.loadLibrary.

java.lang.UnsatisfiedLinkError: dlopen failed: library "libavutil.so.56" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
        at java.lang.System.loadLibrary(System.java:1657)
        at com.hmomeni.canto.activities.EditActivity.<init>(EditActivity.kt:26)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

This is the part of code which is causing the error:

class EditActivity : AppCompatActivity(), View.OnClickListener {

    init {
        System.loadLibrary("Canto")
    }
...
}

I tried moving the .so files inside the PROJECT/app/jniLibs and then adding the following line to build.gradle file to no avail.

sourceSets.main.jniLibs.srcDirs = ['./jniLibs/']
shizhen
  • 12,251
  • 9
  • 52
  • 88
2hamed
  • 8,719
  • 13
  • 69
  • 112

1 Answers1

3

If you configure your jniLibs.srcDirs as below:

sourceSets.main.jniLibs.srcDirs = ['./jniLibs/']

Then your path app/jniLibs/ffmpeg/{ANDROID_ABI}/lib is not correct and your .so files won't be found and packaged by your build system.

Try to make your jniLibs structure be as below:

jniLibs
│   ├── x86
│   ├── x86_64
│   ├── arm64-v8a
│   ├── armeabi-v7a

Dont add lib behind {ANDROID_ABI}/.


---Edit---

And after manually loading the libraries using System.loadLibrary I encountered a new error which indicates that libavutil has text relocations and it seems that for API-23 and above it is not permitted.

Maybe you should try to build your ffmpeg with option --disable-asm and -fPIC to have a binary without text relocation. See here https://stackoverflow.com/a/39965908/8034839, but it looks there still some issue with NEON.

Another discussion for your information: https://stackoverflow.com/a/50207091/8034839

shizhen
  • 12,251
  • 9
  • 52
  • 88
  • I changed the directory structure to `app/jniLibs/{ANDROID_ABI}/libavutil.so.56` but I'm still getting the same result. The library can not be found. – 2hamed Nov 25 '18 at 08:06
  • Remove “.56” from your lib name – shizhen Nov 25 '18 at 08:54
  • Actually all versions of the file names are present in the directory. Check this image to see for yourself. https://imgur.com/a/j7s6Eka – 2hamed Nov 25 '18 at 09:01
  • Have you analyzed your apk? Try to check whether your .so are packaged inside. I am using mobile, please forgive my brievity of reply. – shizhen Nov 25 '18 at 09:03
  • Probably you need to explicitly load all the.so from init{} just like “Canto” – shizhen Nov 25 '18 at 09:07
  • I appreciate you taking time to help me. I checked the apk and realized that the `.so` files are present in it. – 2hamed Nov 25 '18 at 09:20
  • And after manually loading the libraries using `System.loadLibrary` I encountered a new error which indicates that `libavutil has text relocations` and it seems that for API-23 and above it is not permitted. – 2hamed Nov 25 '18 at 09:27
  • Then, I think the ffmpeg lib you compiled could not be dlopen by Android, meaning that it’s not compatible and cause unsatisfied link errors – shizhen Nov 25 '18 at 09:45