我正在 Android Studio 中制作一个使用两个库的应用程序。带有 Android 包装器和 jar 库的本机库。
由于某种原因,如果将其他 jar 库编译到项目中,则本机库将不会加载。因此,如果我仅使用本机库运行应用程序,则一切正常。我将另一个 jar 库添加到我的 gradle 文件中,然后出现 UnsatisfiedLinkError:
java.lang.UnsatisfiedLinkError: Couldn't load MobileOcrEngine from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.app-1, /vendor/lib, /system/lib]]]: findLibrary returned null
当我使用这个时,我的应用程序运行良好:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
compile 'com.android.support:support-v13:21.0.2'
compile project(':wheel')
}
当我尝试时出现错误:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
compile 'com.android.support:support-v13:21.0.2'
compile project(':wheel')
compile files('libs/realm-0.78.0.jar')
}
或者当我尝试使用相同的库但使用 Maven 存储库时:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
compile 'com.android.support:support-v13:21.0.2'
compile project(':wheel')
compile 'io.realm:realm-android:0.78.0'
}
或者如果我尝试将 jar 放在 jniLibs 文件夹中:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
compile 'com.android.support:support-v13:21.0.2'
compile project(':wheel')
}
我不知道问题的根源在哪里。使用两个库之一,Android Studio 还是我做错了什么?
Note:我知道 StackOverflow 上有很多关于 UnsatisfiedLinkErrors 的问题,但这些问题都没有为我的问题提供解决方案。如果它是我使用的唯一库,那么加载本机库没有问题......