I get a java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil error when I include the realm dependency in my Android Studio project built using gradle. Without the realm dependency, everything works fine.
I've read all of these answers:
I've tried using the solutions, but I still get the same error. Not sure if I'm doing it wrong. This is what my build file looks like:
android {
compileSdkVersion 25
buildToolsVersion '24.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode versionCode
versionName libraryVersion
// Android has problems including the javacv native libraries, so we must include them
// manually rather than using gradle.
// https://github.com/bytedeco/javacpp-presets/wiki/The-UnsatisfiedLinkError-X-File-(a-real-experience)
// Compile the *.so files extracted from javacpp-presets:ffmpeg:3.1.2-1.2:android-*.jar
ndk { abiFilters "armeabi", "armeabi-v7a", "x86" }
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude "lib/arm64-v8a/librealm-jni.so"
}
}
// https://github.com/bytedeco/javacpp-presets/wiki/Issues-with-Build-Tools
configurations {
all*.exclude group: 'org.bytedeco', module: 'javacpp-presets'
}
dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:support-v4:25.0.0'
//noinspection GradleDynamicVersion
compile 'com.android.support:support-annotations:+'
compile 'com.github.rahatarmanahmed:circularprogressview:2.5.0'
compile 'com.getkeepsafe.relinker:relinker:1.2.2'
compile group: 'org.bytedeco', name: 'javacpp', version: '1.2.5'
compile group: 'org.bytedeco', name: 'javacv', version: '1.2''android-arm'
}
src\main\jniLibs\armeabi and src\main\jniLibs\armeabi-v7src\main\jniLibs\x86I am testing it on a Samsung Galaxy S5. I used https://play.google.com/store/apps/details?id=com.xh.nativelibsmonitor.app&hl=en to verify that the .so files are included in the binary.
I also tried using relinker, and interestingly relinker says it was able to relink the files:
12-04 20:37:53.799 5223-5711/com.amosyuen.videorecorder.demo E/Relinker: Beginning load of avutil...
12-04 20:37:53.829 5223-5711/com.amosyuen.videorecorder.demo E/Relinker: Loading the library normally failed: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.amosyuen.videorecorder.demo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.amosyuen.videorecorder.demo-1/lib/arm, /data/app/com.amosyuen.videorecorder.demo-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libavutil.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.getkeepsafe.relinker.SystemLibraryLoader.loadLibrary(SystemLibraryLoader.java:24)
at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal(ReLinkerInstance.java:163)
at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:136)
at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:92)
at com.amosyuen.videorecorder.FFmpegRecorderActivity$SaveVideoTask.doInBackground(FFmpegRecorderActivity.java:611)
at com.amosyuen.videorecorder.FFmpegRecorderActivity$SaveVideoTask.doInBackground(FFmpegRecorderActivity.java:570)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
12-04 20:37:53.829 5223-5711/com.amosyuen.videorecorder.demo E/Relinker: avutil (null) was not loaded normally, re-linking...
12-04 20:37:53.839 5223-5488/com.amosyuen.videorecorder.demo D/AudioRecorderThread: Stop AudioRecord
12-04 20:37:53.849 5223-5711/com.amosyuen.videorecorder.demo E/Relinker: avutil (null) was re-linked!
But the javacv Loader still fails and throws the same exception.
I used https://stackoverflow.com/questions/8740859/how-to-detect-which-native-shared-libraries-are-loaded-by-android-application to verify if the library was linked. Before relinker, no avutil libraries were linked, but after running relinker it looked like they were relinked by relinker. This was the output from that code snippet:
12-04 20:37:54.369 5223-5711/com.amosyuen.videorecorder.demo D/Ldd: /data/data/com.amosyuen.videorecorder.demo/app_lib/libjniavutil.so
12-04 20:37:54.379 5223-5711/com.amosyuen.videorecorder.demo D/Ldd: /data/data/com.amosyuen.videorecorder.demo/app_lib/libavutil.so
You forgot to list the dependency for the Java wrappers themselves:
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.1.2-1.2'
I still get the same error after adding compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version:
'3.1.2-1.2'
What about ProGuard? https://github.com/bytedeco/javacv/wiki/Configuring-Proguard-for-JavaCV
I have those exact lines in my proguard file. But I'm testing it in debug build which doesn't use proguard anyways.
Ok, could you set the org.bytedeco.javacpp.logger.debug system property to true and copy/paste what you get in the log with that? Thanks!
This is the output:
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error'/system/framework/com.qti.location.sdk.jar': I/O Error
I/System.out: Loading class org.bytedeco.javacpp.avutil
I/System.out: Loading class org.bytedeco.javacpp.avutil
I/System.out: Loading library c
I/System.out: Loading library m
I/System.out: Loading library z
I/System.out: Loading library dl
I/System.out: Failed to load for dl#: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__cxa_finalize" referenced by "/system/lib/libdl.so"...
I/System.out: Loading library gcc
I/System.out: Failed to load for gcc#: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.amosyuen.videorecorder.demo-2/base.apk"],nativeLibraryDirectories=[/data/app/com.amosyuen.videorecorder.demo-2/lib/arm, /data/app/com.amosyuen.videorecorder.demo-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libgcc.so"
I/System.out: Loading library gnustl_static
I/System.out: Failed to load for gnustl_static#: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.amosyuen.videorecorder.demo-2/base.apk"],nativeLibraryDirectories=[/data/app/com.amosyuen.videorecorder.demo-2/lib/arm, /data/app/com.amosyuen.videorecorder.demo-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libgnustl_static.so"
I/System.out: Loading library log
[ 12-05 23:59:30.760 2752: 3557 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
[ 12-05 23:59:30.770 2752: 3557 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
[ 12-05 23:59:30.770 2752: 3557 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
I/System.out: Loading library avutil
I/System.out: Failed to load for [email protected]: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.amosyuen.videorecorder.demo-2/base.apk"],nativeLibraryDirectories=[/data/app/com.amosyuen.videorecorder.demo-2/lib/arm, /data/app/com.amosyuen.videorecorder.demo-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libavutil.so"
[ 12-05 23:59:30.780 2752: 3557 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
[ 12-05 23:59:30.790 2752: 3557 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
[ 12-05 23:59:30.800 2752: 3557 W/ ]
Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory
W/art: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
I/System.out: Loading library jniavutil
I/System.out: Failed to load for jniavutil: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.amosyuen.videorecorder.demo-2/base.apk"],nativeLibraryDirectories=[/data/app/com.amosyuen.videorecorder.demo-2/lib/arm, /data/app/com.amosyuen.videorecorder.demo-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libjniavutil.so"
I/System.out: Loading class org.bytedeco.javacpp.avutil
I/art: Rejecting re-init on previously-failed class java.lang.Class<org.bytedeco.javacpp.avutil>
It says right there 'couldn't find "libjniavutil.so"'. You're going to need to figure out how to install those files on your device.
All the tools I'm using are indicating the *.so files are installed with the App, but not sure why they aren't being found.
I also notice in the output it's trying to load libgcc.so and libgnustl_static.so. Is that expected?
Yes, you can ignore the failed loads of things like gcc and stl.
Fudge. I made a stupid typo error. I put the files in src\main\jniLibs\armeabi-v7 instead of src\main\jniLibs\armeabi-v7a. Previously it was loading the armv5 files, but then when realm is included it loads the armv7 files, but since I misplaced the .so files the armv7 files were not correctly included. Thanks for the help, it works now!
Most helpful comment
Fudge. I made a stupid typo error. I put the files in
src\main\jniLibs\armeabi-v7instead ofsrc\main\jniLibs\armeabi-v7a. Previously it was loading the armv5 files, but then when realm is included it loads the armv7 files, but since I misplaced the .so files the armv7 files were not correctly included. Thanks for the help, it works now!