Integrating FFMPEG using cmake: dlopen failed: lib

2019-08-04 14:08发布

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/']

1条回答
forever°为你锁心
2楼-- · 2019-08-04 14:39

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

查看更多
登录 后发表回答