java.lang.UnsatisfiedLinkError:dlopen失败: [英] java.lang.UnsatisfiedLinkError: dlopen failed:

查看:3852
本文介绍了java.lang.UnsatisfiedLinkError:dlopen失败:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我将.so文件添加到项目中时,我正面临另一个问题,我尝试了不同的解决方案,但没有任何解决方案可以帮助我.

I am facing the issue while I am adding the .so file in my project, from the other ans, I have tried with different solutions but not any solution help me out.

情况:1 我试图将.so放入src/main/jniLibs和gradle文件中,我在下面几行中添加了内容,但出现相同的错误.

case: 1 I had tried to put my .so in src/main/jniLibs and in the gradle file I had added below lines, but getting the same error.

 android {
     sourceSets.main.jni.srcDirs = []
}

情况:2 我已经使用native-lib.cpp添加了cpp文件夹,并在gradle中添加了以下代码:

case:2 I had added cpp folder with native-lib.cpp and in gradle added below code:

defaultConfig {
 ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
  }
   }

情况:3 我创建了一个新的具有c/c ++支持的新项目,并在cpp文件夹下的gradle中添加了一个.so文件:

case:3 I had created new fresh project with c/c++ support and add a .so file under cpp folder and in the gradle added below code:

defaultConfig {
  externalNativeBuild {
        cmake {
            cppFlags "-std=c++11"

        }
    }
}

我的项目架构

错误代码:

FATAL EXCEPTION: main
Process: ai.kitt.snowboy.demo, PID: 15175
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ai.kitt.snowboy.demo-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libsnowboy-detect-android.so" 
 at java.lang.Runtime.loadLibrary(Runtime.java:366)
 at java.lang.System.loadLibrary(System.java:988)
 at ai.kitt.snowboy.audio.RecordingThread.<clinit>(RecordingThread.java:20)
 at ai.kitt.snowboy.Demo.onCreate(Demo.java:49)
 at android.app.Activity.performCreate(Activity.java:6010)
 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
 at android.app.ActivityThread.access$800(ActivityThread.java:155)  
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:135)
 at android.app.ActivityThread.main(ActivityThread.java:5343)
 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:905)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

我正在使用android studio 3.0.1,gradle:3.0.1

I am using android studio 3.0.1, gradle: 3.0.1

推荐答案

尝试将其添加到build.gradle:

sourceSets.main.jniLibs.srcDirs = ['src/main/jniLibs']

或在android块中添加以下内容:

or add following into android block:

sourceSets {
    main {
        jniLibs.srcDirs = ['src/main/jniLibs']
    }
}

读取默认的jniLibs路径时,Gradle可能会出现问题,只需使其隐式即可.

Gradle may have problem when read default jniLibs path, just make it implicit.

sourceSets.main.jni.srcDirs不起作用,因为它定义了jni source,例如cpp源文件文件夹.

sourceSets.main.jni.srcDirs not work because it defines jni source, like cpp source files folder.

异常堆栈 nativeLibraryDirectories = [/vendor/lib,/system/lib]]] 显示系统根本没有检测到您的lib.要进行验证,请精确检查您的apk,以查看是否有/lib文件夹和您的*.so.

Exception stacks nativeLibraryDirectories=[/vendor/lib, /system/lib]]] shows that system didn't detect your lib at all. To verify it, exact your apk to see whether there is a /lib folder and your *.so.

这篇关于java.lang.UnsatisfiedLinkError:dlopen失败:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆