Using JavaCV and Realm together causes “java.lang.UnsatisfiedLinkError”

前提是你 提交于 2019-12-08 17:05:56

问题


I have recently been getting the following error by attempting to start an instance of JavaCV's FFmpegFrameGrabber:

java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:324)
    at org.bytedeco.javacpp.Loader.load(Loader.java:413)
    at org.bytedeco.javacpp.Loader.load(Loader.java:381)
    at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2597)
    at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:386)
    at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:380)...

While solutions to this problem exist, none worked for me.

Through many trials i have discovered that weirdly enough, if i do not include Realm in my project, i no longer receive this error.

Here is the part of my build.gradle file in which I include all of these libraries:

compile group: 'org.bytedeco', name: 'javacv', version: '1.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.1', classifier: 'android-x86'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.8.1-1.1', classifier: 'android-x86'

// ORM
compile 'io.realm:realm-android:0.87.2' // Tested NOT OK - Causes JavaCV to crash
//

I am thinking that there may be a solution to this problem that i am not aware of. I found no mention anywhere on the internet about library incompatibility or why this behaviour may occur.

I will edit this post with any additional details that anyone might need.

Any help would be greatly appreciated.

EDIT

I attempted to apply the fix described here. Now my packaging options look like this:

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
    exclude 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
    exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
    exclude 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'

    exclude "lib/arm64-v8a/librealm-jni.so"
}

Unfortunately, this change has no effect. I'm still stuck.


回答1:


With the help of one of my coleagues i have been able to solve this issue.

In adition to the steps described in the question, we:

  • Copyed all of the .so files in the app/src/main/jniLibs/armeabi and app/src/main/jniLibs/armeabi-v7a folders
  • Added

    ndk { abiFilters "armeabi-v7a" }

    to the defaultConfig part of the module's build.gradle file

  • Added

    lintOptions { abortOnError false }

    to the android part of the module's build.gradle file

I will try to provide further clarifications to anyone that needs them if i am able.




回答2:


Firstly this issue occurs because of Gradle doesn't resolve dependencies properly from maven profile ..In my case only x86 depdendecies shipped to APK. that means code above works only on x86 cpu architecture. solution should be done on Android Studio. but as workaround I did this:

  1. Download binary javacv-platform-1.3.1-bin.zip. It's from: https://github.com/bytedeco/javacv
  2. Inside directory javacv-bin copy these jars to new directory

    1. ffmpeg-android-arm.jar
    2. opencv-android-arm.jar
    3. ffmpeg-android-x86.jar
    4. opencv-android-x86.jar
  3. For 2.1 2.2 files, Extract these jars and go to lib then or armeabi. Then copy all *.so files into your project under:

    1. app/src/main/jniLibs/armeabi/
    2. app/src/main/jniLibs/armeabi-v7a/
  4. you might do the same with 2.3 * 2.4 jars by copying dependencies into app/src/main/jniLibs/x86/ . just check your apk if it really doesn't have them.

That's it.



来源:https://stackoverflow.com/questions/35066470/using-javacv-and-realm-together-causes-java-lang-unsatisfiedlinkerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!