在Android项目中无法找到ND4J共享库

问题描述 投票:1回答:1

我正在研究这个需要OpenCV和DL4J的Android项目。但在动态链接期间,这两者之间存在冲突。

在我的app / src / main / jniLibs中:我必须包含arm64-v8a文件夹,其中包含文件libopencv_java3.so。但是,现在这会导致链接器尝试在此libdl.so文件夹中找到libjnind4jcpu.so和/或arm64-v8a,这显然不会存在,因为DL4J是从远程存储库添加的。

那么,有没有办法明确告诉Gradle从远程存储库中找到libdl.so和/或libjnind4jcpu.so?或者您可以找到解决此问题的方法?


的build.gradle

apply plugin: 'com.android.application'

android {
     compileSdkVersion 25
     buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "gov.nih.nlm.malaria_screener"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 6 // start from 1
    versionName "1.3.2" // start from 1.0
    multiDexEnabled true
    jackOptions { // for Java 1.8
        enabled true
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}

lintOptions { // for unsigned release build error on Time and Date picker
    checkReleaseBuilds false
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}



}

dependencies {
    compile files('libs/GraphView-4.0.1.jar')
    compile files('libs/AndroidSwipeLayout-v1.1.8.jar')
    compile 'com.dropbox.core:dropbox-core-sdk:2.0.1'
    compile files('libs/dropbox-android-sdk-1.6.3.jar')
    compile files('libs/json_simple-1.1.jar')
    compile files('libs/eventbus-3.0.0.jar')
    compile files('libs/glide-3.7.0.jar')
    compile files('libs/flickrj-android-2.0.0.jar')
    compile 'org.deeplearning4j:deeplearning4j-core:0.7.2'
    compile 'org.nd4j:nd4j-native:0.7.2'
    compile 'org.nd4j:nd4j-native:0.7.2:android-x86'
    compile 'org.nd4j:nd4j-native:0.7.2:android-arm'
//    implementation 'org.deeplearning4j:deeplearning4j-core:0.9.1'
//    implementation 'org.nd4j:nd4j-native:0.9.1'
//    implementation 'org.nd4j:nd4j-native:0.9.1:android-x86'
//    implementation 'org.nd4j:nd4j-native:0.9.1:android-arm'
//    implementation 'org.bytedeco.javacpp-presets:openblas:0.2.19-1.3:android-x86'
//    implementation 'org.bytedeco.javacpp-presets:openblas:0.2.19-1.3:android-arm'
    annotationProcessor 'org.projectlombok:lombok:1.16.10'
    compile project(':mysql-connector-java-5.1.43-bin')
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:design:25.4.0'
    compile 'com.android.support:cardview-v7:25.4.0'
    compile 'com.android.support:support-v13:25.4.0'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.android.support:recyclerview-v7:25.4.0'
    compile 'com.github.amlcurran.showcaseview:library:5.4.3'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation project(':openCVLibrary340')

错误:

 E/linker: library "/system/lib64/libdl.so" ("/system/lib64/libdl.so") needed or dlopened by "/system/lib64/libnativeloader.so" is not accessible for the namespace: [name="classloader-namespace", ld_library_paths="", default_library_paths="/data/app/gov.nih.nlm.malaria_screener-1/lib/arm64:/data/app/gov.nih.nlm.malaria_screener-1/base.apk!/lib/arm64-v8a", permitted_paths="/data:/mnt/expand:/data/data/gov.nih.nlm.malaria_screener"]
02-01 15:41:09.975 20294-22826/gov.nih.nlm.malaria_screener E/AndroidRuntime: FATAL EXCEPTION: Thread-5
                                                                              Process: gov.nih.nlm.malaria_screener, PID: 20294
                                                                              java.lang.ExceptionInInitializerError
                                                                                  at org.nd4j.nativeblas.NativeOpsHolder.getInstance(NativeOpsHolder.java:45)
                                                                                  at org.nd4j.linalg.cpu.nativecpu.ops.NativeOpExecutioner.<init>(NativeOpExecutioner.java:41)
                                                                                  at java.lang.Class.newInstance(Native Method)
                                                                                  at org.nd4j.linalg.factory.Nd4j.initWithBackend(Nd4j.java:5646)
                                                                                  at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5554)
                                                                                  at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:189)
                                                                                  at org.nd4j.linalg.factory.Nd4j.read(Nd4j.java:2328)
                                                                                  at org.deeplearning4j.util.ModelSerializer.restoreMultiLayerNetwork(ModelSerializer.java:216)
                                                                                  at org.deeplearning4j.util.ModelSerializer.restoreMultiLayerNetwork(ModelSerializer.java:167)
                                                                                  at gov.nih.nlm.malaria_screener.Cells.<init>(Cells.java:117)
                                                                                  at gov.nih.nlm.malaria_screener.CameraActivity.ProcessImage(CameraActivity.java:1104)
                                                                                  at gov.nih.nlm.malaria_screener.CameraActivity$8.run(CameraActivity.java:874)
                                                                                  at java.lang.Thread.run(Thread.java:762)
                                                                               Caused by: java.lang.RuntimeException: ND4J is probably missing dependencies. For more information, please refer to: http://nd4j.org/getstarted.html
                                                                                  at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:40)
                                                                                  at org.nd4j.nativeblas.NativeOpsHolder.<clinit>(NativeOpsHolder.java:16)
                                                                                  at org.nd4j.nativeblas.NativeOpsHolder.getInstance(NativeOpsHolder.java:45) 
                                                                                  at org.nd4j.linalg.cpu.nativecpu.ops.NativeOpExecutioner.<init>(NativeOpExecutioner.java:41) 
                                                                                  at java.lang.Class.newInstance(Native Method) 
                                                                                  at org.nd4j.linalg.factory.Nd4j.initWithBackend(Nd4j.java:5646) 
                                                                                  at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5554) 
                                                                                  at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:189) 
                                                                                  at org.nd4j.linalg.factory.Nd4j.read(Nd4j.java:2328) 
                                                                                  at org.deeplearning4j.util.ModelSerializer.restoreMultiLayerNetwork(ModelSerializer.java:216) 
                                                                                  at org.deeplearning4j.util.ModelSerializer.restoreMultiLayerNetwork(ModelSerializer.java:167) 
                                                                                  at gov.nih.nlm.malaria_screener.Cells.<init>(Cells.java:117) 
                                                                                  at gov.nih.nlm.malaria_screener.CameraActivity.ProcessImage(CameraActivity.java:1104) 
                                                                                  at gov.nih.nlm.malaria_screener.CameraActivity$8.run(CameraActivity.java:874) 
                                                                                  at java.lang.Thread.run(Thread.java:762) 
                                                                               Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/gov.nih.nlm.malaria_screener-1/base.apk"],nativeLibraryDirectories=[/data/app/gov.nih.nlm.malaria_screener-1/lib/arm64, /data/app/gov.nih.nlm.malaria_screener-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libjnind4jcpu.so"
                                                                                  at java.lang.Runtime.loadLibrary0(Runtime.java:972)
android opencv gradle dl4j
1个回答
2
投票

因为你只使用那些线包括android-x86android-arm

compile 'org.nd4j:nd4j-native:0.7.2:android-x86'
compile 'org.nd4j:nd4j-native:0.7.2:android-arm'

你将在你的apk中缺少arm64库。如果你解压缩并查看libs文件夹,你会看到像smth一样

 libs   
|-->x86   
|    |-->libopencv_java3.so   
|    |-->libdl.so   
|-->armeabi   
|    |-->libopencv_java3.so   
|    |-->libdl.so   
|-->arm64   
     |-->libopencv_java3.so   

因此,当您启动应用程序时,它会尝试在arm64中查找没有的libdl。

可能的解决方案:

  1. 添加arm64版本的nd4j lib。另请注意,这是首选,因为Google remove 32 bit support in 2019
  2. 使用this method从您的构建中排除arm64
© www.soinside.com 2019 - 2024. All rights reserved.