错误:
Process: com.example.syafiq.opencvoi, PID: 7760
java.lang.UnsatisfiedLinkError: Couldn't load native_sample from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.syafiq.opencvoi-13.apk,libraryPath=/data/app-lib/com.example.syafiq.opencvoi-13]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.example.syafiq.opencvoi.Sample3Native$1.onManagerConnected(Sample3Native.java:79)
at org.opencv.android.AsyncServiceHelper$3.onServiceConnected(AsyncServiceHelper.java:319)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1114)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1131)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
sample3Native.java第79行是:
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
// Load native library after(!) OpenCV initialization
System.loadLibrary("native_sample");
AsyncServiceHelper.Java第319行是
mUserAppCallback.onManagerConnected(status);
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include ../../sdk/native/jni/OpenCV.mk
LOCAL_MODULE := native_sample
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
和application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a
LOCAL_ARM_NEON := true
代码中没有错误。我尝试了几种解决方案,但结果仍然相同,代码是从开源网站获得的。我对android studio不够好,我还在学习。我希望你们能帮助我解决这个错误。我非常感谢您的帮助和考虑,以帮助我解决我的错误。我很感激你的时间:)。
答案 0 :(得分:0)
从我的角度来看,“native_sample”库的版本有问题。正如它在documentation
中所写的那样如果Java虚拟机无法找到合适的内容,则抛出该异常 声明为native的方法的本地语言定义。
您的类路径中可能存在两个版本,并且jvm加载了错误的版本。所以它找到了库,但是在类加载过程中发现不一致,可能在后来的lib版本中添加了所需的方法。
我建议尝试这个:
System.load(String path) //with an absolute path to needed lib
另见:Difference between System.load() and System.loadLibrary in Java
答案 1 :(得分:0)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.syafiq.opencvoi"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
// jniLibs.srcDirs = ['libs']
main{
jniLibs{
srcDir 'libs'
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':libraries:opencv')
}