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

查看:68
本文介绍了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.

case: 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 = []
}

case: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"
  }
   }

case: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']
    }
}

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

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]]] 表明系统根本没有检测到您的库.要验证它,请确定您的 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天全站免登陆