gpt4 book ai didi

android - java.lang.UnsatisfiedLinkError : dlopen failed: library "libopencv_java3.so" not found 错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:49:21 30 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,该应用程序应该检测是否有人脸在相机前面,然后根据它执行一些操作。我正在使用 open cv 进行人脸检测,但我需要一些 costume C++ 功能。所以我试图将 OpenCV 的东西导入我自己的 C++ 文件 myLib.cpp。然后我想在我的 mainActivity 中调用 myLib 中定义的函数。

当我构建项目时,一切正常,但一旦我在我的设备(Oneplus x - Android 22)上运行它,它就会立即崩溃并显示以下错误消息:

04-12 10:28:38.494 11114-11114/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lunaticcoding.opencvtest, PID: 11114
java.lang.UnsatisfiedLinkError: dlopen failed: library "libopencv_java3.so" not found
at java.lang.Runtime.loadLibrary(Runtime.java:371)
at java.lang.System.loadLibrary(System.java:988)
at com.lunaticcoding.opencvtest.MainActivity.<clinit>(MainActivity.java:19)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.access$900(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:139)
at android.app.ActivityThread.main(ActivityThread.java:5298)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)

我的 OpenCV build.gradle:

apply plugin: 'com.android.library'

android {
compileSdkVersion 27



defaultConfig {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
}
}

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jni.srcDirs = [jni.srcDirs, 'src/sdk/native/jni/include']
jniLibs.srcDirs = [jniLibs.srcDirs, 'src/sdk/native/3rdparty/libs', 'src/sdk/native/libs']
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

我的 OpenCV CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)
set(OpenCV_DIR "/Users/lunaticcoding/Documents/OpenCV-android-sdk/sdk/native/jni")
find_package(OpenCV REQUIRED java)
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
include_directories(${OpenCV_INCLUDE_DIRS})

问题是 libopencv_java3.so 没有在我的构建中创建。所以问题一定出在OpenCV工程的CMakeLists.txt中。有谁知道如何将 libopencv_java3.so 文件导出到我的应用程序构建中?

最佳答案

您必须在您的设备上安装 OpenCV 管理器。

然后像这样启动管理器

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);

BaseLoaderCallback 是

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};

参见 reference page

关于android - java.lang.UnsatisfiedLinkError : dlopen failed: library "libopencv_java3.so" not found 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49799221/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com