我试图在启用了proguard的情况下使用协程。我收到如下错误:-
W/System.err: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/jakewharton/retrofit2/adapter/kotlin/coroutines/CoroutineCallAdapterFactory;
W/System.err: at com.example.test.utils.ApiService$a.a(SourceFile:132)
W/System.err: at com.example.test.utils.ApiService$a.a(SourceFile:95)
W/System.err: at com.example.test.registration.RegistrationActivity.a(SourceFile:166)
W/System.err: at com.example.test.registration.RegistrationActivity$a.invokeSuspend(SourceFile:91)
W/System.err: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
W/System.err: at kotlinx.coroutines.DispatchedTask$DefaultImpls.run(Dispatched.kt:235)
W/System.err: at kotlinx.coroutines.DispatchedContinuation.run(Dispatched.kt:81)
W/System.err: at android.os.Handler.handleCallback(Handler.java:815)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:104)
W/System.err: at android.os.Looper.loop(Looper.java:207)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5728)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory" on path: DexPathList[[zip file "/data/app/com.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example-1/lib/arm, /vendor/lib, /system/lib]]
W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
W/System.err: ... 14 more
W/System.err: Suppressed: java.lang.ClassNotFoundException:com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
W/System.err: at java.lang.Class.classForName(Native Method)
W/System.err: at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
W/System.err: at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
W/System.err: ... 15 more
W/System.err: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
我的proguard文件包括:-
##########
# Kotlin
##########
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
<fields>;
}
-keepclassmembers class kotlin.Metadata {
public <fields>;
public <methods>;
}
-keepclassmembers class * {
static final % *;
static final java.lang.String *;
}
#-dontwarn org.jetbrains.annotations.**
#Ignore null checks at runtime
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
}
-keep class org.jetbrains.kotlin.** { *; }
-keep class org.jetbrains.*
-keep class org.jetbrains.annotations.** { *; }
-keepclassmembers class ** {
@org.jetbrains.annotations.ReadOnly public *;
}
#############
# Google Play Services
#############
-keep class com.google.android.gms.* { *; }
-dontwarn com.google.android.gms.**
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-dontnote **ILicensingService
-dontnote com.google.android.gms.gcm.GcmListenerService
-dontnote com.google.android.gms.**
-dontwarn com.google.android.gms.ads.**
#GOOGLE_PLAY_SERVICES
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
#############
# Android Support Lib
#############
-keep class android.support.design.widget.TextInputLayout { *; }
#############
# Retrofit
#############
-dontnote okio.**
#RETROFIT2
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
# Okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
我正在对API调用使用retrofit2和jakewharton的协程适配器依赖项。如果禁用了proguard,则工作正常。但是启用proguard时会出现此问题。添加了retrofit2,okHttp,okio和kotlin所需的所有规则。仍然无法解决此问题。