添加外部库时,Android Studio错误

时间:2018-12-09 02:40:17

标签: android android-studio

我正在尝试在Android Studio中实现Solver SDK。我成功添加了它,并且能够从.jar文件中调用函数并实例化类,但是在运行时出现以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.company.vince.physicswhiledriving, PID: 23012
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.company.vince.physicswhiledriving-2/base.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.company.vince.physicswhiledriving-2/lib/arm64, /data/app/com.company.vince.physicswhiledriving-2/base.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.company.vince.physicswhiledriving-2/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libSolverSDK.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:972)
        at java.lang.System.loadLibrary(System.java:1567)
        at SolverPlatform.Problem.<clinit>(Unknown Source)
        at com.company.vince.physicswhiledriving.MainActivity.Evaluate(MainActivity.java:472)
        at com.company.vince.physicswhiledriving.MainActivity.lambda$onCreate$3(MainActivity.java:202)
        at com.company.vince.physicswhiledriving.-$$Lambda$MainActivity$_ZIHQnNzIub2iCs97DsuIwkLxLQ.onClick(lambda)
        at android.view.View.performClick(View.java:6205)
        at android.widget.TextView.performClick(TextView.java:11103)
        at android.view.View$PerformClick.run(View.java:23653)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1424)

该错误是Android Studio独有的,因为我能够导入.jar文件并执行代码,而在Eclipse中没有错误。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

.jar文件和.so文件放在正确的文件夹中,如下所示:

project/
├──libs/
|  └── *.jar       <-- if your library has jar files, they go here
├──src/
   └── main/
       ├── AndroidManifest.xml
       ├── java/
       └── jniLibs/ 
           ├── arm64-v8a/                       <-- ARM 64bit
           │   └── yourlib.so
           ├── armeabi-v7a/                     <-- ARM 32bit
           │   └── yourlib.so
           └── x86/                             <-- Intel 32bit
               └── yourlib.so

并在模块Gradle文件中添加以下行:

implementation files('libs/your jar file.jar')

答案 1 :(得分:0)

您忘记将“ libSolverSDK.so”添加到“ jniLibs”文件夹中了;)