在 Android 项目中找不到 ND4J 共享库
ND4J Shared library can not be find in Android project
我正在处理这个需要 OpenCV 和 DL4J 的 Android 项目。但是在动态链接期间两者之间存在这种冲突。
在我的 app/src/main/jniLibs 中:我必须包含包含文件 libopencv_java3.so
的 arm64-v8a
文件夹。但是,现在这会导致链接器尝试在此 arm64-v8a
文件夹中查找 libdl.so
and/or libjnind4jcpu.so
,这显然不会存在,因为 DL4J 是从远程存储库添加的。
那么,有没有办法明确地告诉 Gradle 从远程存储库中找到 libdl.so
and/or 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.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.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-x86
和 android-arm
使用这些行
compile 'org.nd4j:nd4j-native:0.7.2:android-x86'
compile 'org.nd4j:nd4j-native:0.7.2:android-arm'
您的 apk 中将缺少 arm64 库。如果你解压缩它并查看 libs 文件夹,你会看到类似
libs
|-->x86
| |-->libopencv_java3.so
| |-->libdl.so
|-->armeabi
| |-->libopencv_java3.so
| |-->libdl.so
|-->arm64
|-->libopencv_java3.so
因此,当您启动您的应用程序时,它会尝试在 arm64 中寻找 libdl,但它没有。
可能的解决方案:
添加 arm64 版本的 nd4j 库。另请注意,这是首选,因为 Google remove 32 bit support in 2019
使用
从您的构建中排除 arm64
我正在处理这个需要 OpenCV 和 DL4J 的 Android 项目。但是在动态链接期间两者之间存在这种冲突。
在我的 app/src/main/jniLibs 中:我必须包含包含文件 libopencv_java3.so
的 arm64-v8a
文件夹。但是,现在这会导致链接器尝试在此 arm64-v8a
文件夹中查找 libdl.so
and/or libjnind4jcpu.so
,这显然不会存在,因为 DL4J 是从远程存储库添加的。
那么,有没有办法明确地告诉 Gradle 从远程存储库中找到 libdl.so
and/or 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.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.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-x86
和 android-arm
使用这些行
compile 'org.nd4j:nd4j-native:0.7.2:android-x86'
compile 'org.nd4j:nd4j-native:0.7.2:android-arm'
您的 apk 中将缺少 arm64 库。如果你解压缩它并查看 libs 文件夹,你会看到类似
libs
|-->x86
| |-->libopencv_java3.so
| |-->libdl.so
|-->armeabi
| |-->libopencv_java3.so
| |-->libdl.so
|-->arm64
|-->libopencv_java3.so
因此,当您启动您的应用程序时,它会尝试在 arm64 中寻找 libdl,但它没有。
可能的解决方案:
添加 arm64 版本的 nd4j 库。另请注意,这是首选,因为 Google remove 32 bit support in 2019
使用
从您的构建中排除 arm64