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

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.

Answer

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.