在添加retrofit实现依赖关系时,gradle出错[无法从dataapp打开dex文件]。

问题描述 投票:0回答:1

当retrofit REST API的执行依赖得到错误时在添加retrofit实现依赖关系时,gradle出错[无法从dataapp打开dex文件]。

Process: com.alialfayed.restapitest, PID: 30680
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.alialfayed.restapitest/com.alialfayed.restapitest.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.alialfayed.restapitest.MainActivity" on path: DexPathList[[zip file "/data/app/com.alialfayed.restapitest-C1XYapOmYMAJ2JGUBBxI1w==/base.apk"],nativeLibraryDirectories=[/data/app/com.alialfayed.restapitest-C1XYapOmYMAJ2JGUBBxI1w==/lib/x86, /system/lib, /vendor/lib]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2718)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.alialfayed.restapitest.MainActivity" on path: DexPathList[[zip file "/data/app/com.alialfayed.restapitest-C1XYapOmYMAJ2JGUBBxI1w==/base.apk"],nativeLibraryDirectories=[/data/app/com.alialfayed.restapitest-C1XYapOmYMAJ2JGUBBxI1w==/lib/x86, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1173)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
    at android.app.ActivityThread.-wrap11(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
    at android.os.Handler.dispatchMessage(Handler.java:105) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6541) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
    Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.alialfayed.restapitest-C1XYapOmYMAJ2JGUBBxI1w==/base.apk because: Failure to verify dex file '/data/app/com.alialfayed.restapitest-C1XYapOmYMAJ2JGUBBxI1w==/base.apk': Bad method handle type 7
    at dalvik.system.DexFile.openDexFileNative(Native Method)

当我删除 retrofit 的依赖关系时,它可以完美地工作。

android api rest gradle retrofit2
1个回答
0
投票

添加编译选项标签到

android{}

    compileOptions {
    targetCompatibility JavaVersion.VERSION_1_8
}

和同步应用程序

© www.soinside.com 2019 - 2024. All rights reserved.