Android~集成opencv问题

dlopen failed: library “libopencv_java4.so” not found

 E  FATAL EXCEPTION: main
	Process: com.cv.monitor, PID: 4371
	java.lang.UnsatisfiedLinkError: dlopen failed: library "libopencv_java4.so" not found: 	
	needed by /data/app/~~KwL8rjD8_by_YVAyU82UCA==/com.cv.monitor-TgIKXkGXGh5-h0ommPaC0Q==/lib/arm64/libnativelib.so in namespace classloader-namespace
	at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
	at java.lang.Runtime.loadLibrary0(Runtime.java:998)
	at java.lang.System.loadLibrary(System.java:1656)
	at com.cv.nativelib.NativeLib.<clinit>(NativeLib.kt:36)

原因: jni路径指定错误
解决办法: 正确指定so库路径

sourceSets.all {
	jniLibs.srcDir("src/main/cpp/libs")
}

dlopen failed: library “libc++_shared.so” not found

 E  FATAL EXCEPTION: main
	Process: com.cv.monitor, PID: 3119
	java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found: 
	needed by /data/app/~~6i0h5RXhgJj-SnKplwM3yA==/com.cv.monitor-16Yywq6GKO
	aLfnkgE2jyA==/lib/arm64/libopencv_java4.so in namespace classloader-namespace
	at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
	at java.lang.Runtime.loadLibrary0(Runtime.java:998)
	at java.lang.System.loadLibrary(System.java:1656)
	at com.cv.nativelib.NativeLib.<clinit>(NativeLib.kt:36)

原因:CMake插件构建的NDK需要指定-DANDROID_STL=c++_shared
解决办法:defaultConfig下面新增如下代码

externalNativeBuild {
    cmake {
        arguments.add("-DANDROID_STL=c++_shared")
        cppFlags("")
    }
}

参考:https://www.jianshu.com/p/1169602c2fac

你可能感兴趣的:(#,Android,android,opencv,人工智能)