Android - 运行 一个应用程序加载 JNI 库时出错
Android - Error loading JNI library when running an app
我在 Nexus 5 上 downloaded the Affdex sdk, and I'm trying to get CameraDetectorDemo 到 运行。
我在尝试 运行 应用程序时遇到以下异常。
07-23 11:16:19.020: D/dalvikvm(830): Not late-enabling CheckJNI (already on)
07-23 11:16:23.280: D/AndroidRuntime(830): Shutting down VM
07-23 11:16:23.280: W/dalvikvm(830): threadid=1: thread exiting with uncaught exception (group=0xada4aba8)
07-23 11:16:23.390: E/AndroidRuntime(830): FATAL EXCEPTION: main
07-23 11:16:23.390: E/AndroidRuntime(830): Process: com.affectiva.android.affdex.measureup, PID: 830
07-23 11:16:23.390: E/AndroidRuntime(830): java.lang.UnsatisfiedLinkError: Couldn't load affdexface_jni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.affectiva.android.affdex.measureup-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.affectiva.android.affdex.measureup-1, /system/lib]]]: findLibrary returned null
07-23 11:16:23.390: E/AndroidRuntime(830): at java.lang.Runtime.loadLibrary(Runtime.java:358)
07-23 11:16:23.390: E/AndroidRuntime(830): at java.lang.System.loadLibrary(System.java:526)
07-23 11:16:23.390: E/AndroidRuntime(830): at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI.<clinit>(AffdexFaceJNI.java:21)
07-23 11:16:23.390: E/AndroidRuntime(830): at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI$$InjectAdapter.get(AffdexFaceJNI$$InjectAdapter.java:27)
07-23 11:16:23.390: E/AndroidRuntime(830): at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI$$InjectAdapter.get(AffdexFaceJNI$$InjectAdapter.java:14)
这很可能是由于项目配置和导入库文件的方式出错造成的。
如果您在 Gradle 中构建项目,则需要遵循类似的结构,如下所示:
AffdexGradleProject
`-- app
|-- jniLibs
| `-- armeabi-v7a
| `-- libaffdexface_jni.so
|-- libs
| |-- Affdex-sdk.jar
| `-- Affdex-sdk-javadoc.jar
`-- src
|-- main
| |-- assets
| | `-- Affdex
| | |-- Classifiers.v_9
| | | `-- ...
| | `-- Affectiva.licence
| |-- java
| | `-- ...
| |-- res
| | `-- ...
| `-- AndroidManifest.xml
|-- app.iml
`-- build.gradle
libs 和 jniLibs 文件夹的位置并不重要,只要您的项目配置正确以引用它们即可。
这里是 build.gradle 的片段,它引用了上面的 libs 和 jniLibs 的位置以进行比较:
android {
...
sourceSets {
main {
jniLibs.srcDirs = ['jniLibs']
jni.srcDirs = [] //disable automatic ndk-build
}
}
ndk {
abiFilters “armeabi-v7a”, ... (what ever other architecture types additional libraries are using)
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'javax.inject:javax.inject:1'
compile files('libs/Affdex-sdk.jar')
compile files('libs/Affdex-sdk-javadoc.jar')
}
我在 Nexus 5 上 downloaded the Affdex sdk, and I'm trying to get CameraDetectorDemo 到 运行。
我在尝试 运行 应用程序时遇到以下异常。
07-23 11:16:19.020: D/dalvikvm(830): Not late-enabling CheckJNI (already on)
07-23 11:16:23.280: D/AndroidRuntime(830): Shutting down VM
07-23 11:16:23.280: W/dalvikvm(830): threadid=1: thread exiting with uncaught exception (group=0xada4aba8)
07-23 11:16:23.390: E/AndroidRuntime(830): FATAL EXCEPTION: main
07-23 11:16:23.390: E/AndroidRuntime(830): Process: com.affectiva.android.affdex.measureup, PID: 830
07-23 11:16:23.390: E/AndroidRuntime(830): java.lang.UnsatisfiedLinkError: Couldn't load affdexface_jni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.affectiva.android.affdex.measureup-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.affectiva.android.affdex.measureup-1, /system/lib]]]: findLibrary returned null
07-23 11:16:23.390: E/AndroidRuntime(830): at java.lang.Runtime.loadLibrary(Runtime.java:358)
07-23 11:16:23.390: E/AndroidRuntime(830): at java.lang.System.loadLibrary(System.java:526)
07-23 11:16:23.390: E/AndroidRuntime(830): at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI.<clinit>(AffdexFaceJNI.java:21)
07-23 11:16:23.390: E/AndroidRuntime(830): at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI$$InjectAdapter.get(AffdexFaceJNI$$InjectAdapter.java:27)
07-23 11:16:23.390: E/AndroidRuntime(830): at com.affectiva.android.affdex.sdk.detector.AffdexFaceJNI$$InjectAdapter.get(AffdexFaceJNI$$InjectAdapter.java:14)
这很可能是由于项目配置和导入库文件的方式出错造成的。
如果您在 Gradle 中构建项目,则需要遵循类似的结构,如下所示:
AffdexGradleProject
`-- app
|-- jniLibs
| `-- armeabi-v7a
| `-- libaffdexface_jni.so
|-- libs
| |-- Affdex-sdk.jar
| `-- Affdex-sdk-javadoc.jar
`-- src
|-- main
| |-- assets
| | `-- Affdex
| | |-- Classifiers.v_9
| | | `-- ...
| | `-- Affectiva.licence
| |-- java
| | `-- ...
| |-- res
| | `-- ...
| `-- AndroidManifest.xml
|-- app.iml
`-- build.gradle
libs 和 jniLibs 文件夹的位置并不重要,只要您的项目配置正确以引用它们即可。
这里是 build.gradle 的片段,它引用了上面的 libs 和 jniLibs 的位置以进行比较:
android {
...
sourceSets {
main {
jniLibs.srcDirs = ['jniLibs']
jni.srcDirs = [] //disable automatic ndk-build
}
}
ndk {
abiFilters “armeabi-v7a”, ... (what ever other architecture types additional libraries are using)
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'javax.inject:javax.inject:1'
compile files('libs/Affdex-sdk.jar')
compile files('libs/Affdex-sdk-javadoc.jar')
}