java.lang.UnsatisfiedLinkError:dlopen 失败:找不到库“../../lib/libopencv_core.so”
Posted
技术标签:
【中文标题】java.lang.UnsatisfiedLinkError:dlopen 失败:找不到库“../../lib/libopencv_core.so”【英文标题】:java.lang.UnsatisfiedLinkError: dlopen failed: library "../../lib/libopencv_core.so" not found 【发布时间】:2020-07-28 05:58:26 【问题描述】:我正在使用 android 和 openCV 开发人脸识别应用程序。我的 android studio 版本是 3.5.3,openCV 版本是 3.4.10。我正在运行我的应用程序的手机是 arm64-v8a,我收到此错误:
2020-04-15 15:00:40.425 15788-15788/com.example.opencvdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.opencvdemo, PID: 15788
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.example.opencvdemo-o8BNe1NoZik-avIk3otJaw==/lib/arm64/libjniopencv_contrib.so" is 32-bit instead of 64-bit
at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:586)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.opencv_contrib.<clinit>(opencv_contrib.java:97)
at com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(Native Method)
at com.example.opencvdemo.CtrRecognizer.<init>(CtrRecognizer.java:40)
at com.example.opencvdemo.MainActivity$1.onManagerConnected(MainActivity.java:94)
at org.opencv.android.AsyncServiceHelper$3.onServiceConnected(AsyncServiceHelper.java:319)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1956)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1988)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.example.opencvdemo-o8BNe1NoZik-avIk3otJaw==/lib/arm64/libopencv_contrib.so" is 32-bit instead of 64-bit
at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:577)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.opencv_contrib.<clinit>(opencv_contrib.java:97)
at com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(Native Method)
at com.example.opencvdemo.CtrRecognizer.<init>(CtrRecognizer.java:40)
at com.example.opencvdemo.MainActivity$1.onManagerConnected(MainActivity.java:94)
at org.opencv.android.AsyncServiceHelper$3.onServiceConnected(AsyncServiceHelper.java:319)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1956)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1988)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
2020-04-15 15:00:40.427 15788-15788/com.example.opencvdemo E/MQSEventManagerDelegate: failed to get MQSService.
build.gradle
apply plugin: 'com.android.application'
android
compileSdkVersion 28
//buildToolsVersion "29.0.0"
defaultConfig
applicationId "com.example.opencvdemo"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
sourceSets
main
jni.srcDirs = ['src/main/jniLibs']
jniLibs.srcDir 'src/main/libs'
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar','*.so'])
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.github.markushi:circlebutton:1.1'
implementation project(path: ':openCV3410')
为了消除此错误,我对 build.gradle 进行了如下更改:
apply plugin: 'com.android.application'
android
compileSdkVersion 28
//buildToolsVersion "29.0.0"
defaultConfig
applicationId "com.example.opencvdemo"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
externalNativeBuild
cmake
cppFlags "-frtti -fexceptions"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
sourceSets
main
jni.srcDirs = ['src/main/jniLibs']
jniLibs.srcDir 'src/main/libs'
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar','*.so'])
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'com.intuit.ssp:ssp-android:1.0.6'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.github.markushi:circlebutton:1.1'
implementation project(path: ':openCV3410')
现在我收到此错误:
2020-04-15 15:11:19.353 17892-17892/com.example.opencvdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.opencvdemo, PID: 17892
java.lang.UnsatisfiedLinkError: dlopen failed: library "../../lib/libopencv_core.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:586)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.opencv_contrib.<clinit>(opencv_contrib.java:97)
at com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(Native Method)
at com.example.opencvdemo.CtrRecognizer.<init>(CtrRecognizer.java:40)
at com.example.opencvdemo.MainActivity$1.onManagerConnected(MainActivity.java:94)
at com.example.opencvdemo.MainActivity.onResume(MainActivity.java:233)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1454)
at android.app.Activity.performResume(Activity.java:8050)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4236)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4278)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "../../lib/libopencv_core.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:577)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.opencv_contrib.<clinit>(opencv_contrib.java:97)
at com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer(Native Method)
at com.example.opencvdemo.CtrRecognizer.<init>(CtrRecognizer.java:40)
at com.example.opencvdemo.MainActivity$1.onManagerConnected(MainActivity.java:94)
at com.example.opencvdemo.MainActivity.onResume(MainActivity.java:233)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1454)
at android.app.Activity.performResume(Activity.java:8050)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4236)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4278)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
2020-04-15 15:11:19.361 17892-17892/com.example.opencvdemo E/MQSEventManagerDelegate: failed to get MQSService.
【问题讨论】:
【参考方案1】:根据堆栈跟踪:java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.example.opencvdemo-o8BNe1NoZik-avIk3otJaw==/lib/arm64/libjniopencv_contrib.so" 是 32-位而不是 64 位
所以我想你的库没有 arm64-v8a 的资源,要解决这个问题,你必须将 arm64-v8a arch 的 opencv .so 文件添加到你的项目中
【讨论】:
在 jniLibs 目录中创建一个名为 arm64-v8a 的文件夹并复制 .so 文件会有帮助吗? 你能告诉我你在 jniLibs 文件夹中有哪些 floders 和文件吗? 好的,现在确保你的 arm64-v8a 文件夹中有一个名为“libjniopencv_contrib.so”的文件,如果它在那里,那么你能告诉我你的“lib”文件夹中有什么文件吗?以上是关于java.lang.UnsatisfiedLinkError:dlopen 失败:找不到库“../../lib/libopencv_core.so”的主要内容,如果未能解决你的问题,请参考以下文章