简体   繁体   English

Android-运行应用程序时加载JNI库时出错

[英]Android - Error loading JNI library when running an app

I downloaded the Affdex sdk, and I'm trying to get CameraDetectorDemo to run on my nexus 5. 下载了Affdex sdk,并且试图让CameraDetectorDemo在我的nexus 5上运行。

I encountered an the following exception trying to run the application. 我在尝试运行应用程序时遇到以下异常。

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)

This is most likely caused by an error in the way the project is configured and is importing the library files. 这很可能是由项目配置和导入库文件的方式错误引起的。

If you are building your project in Gradle, you need to follow a similar structure as shown here: 如果要在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

The location of the libs and jniLibs folders do not really matter as long as your project is configured properly to reference them. 只要您的项目已正确配置为引用libs和jniLibs文件夹的位置,它们的位置并不重要。

And here is the snippet of the build.gradle that references the locations of the libs and jniLibs above for comparison: 这是build.gradle的代码段,该代码段引用了上面的lib和jniLib的位置进行比较:

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')
}


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM