bug如下:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.itcast.itcast, PID: 926
java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
at kotlinx.coroutines.cr.d(Dispatchers.kt:123)
at kotlinx.coroutines.cr.a(Dispatchers.kt:116)
at kotlinx.coroutines.be.a(Dispatched.kt:279)
at kotlinx.coroutines.c.a.a(Cancellable.kt:23)
at kotlinx.coroutines.ar.invoke(CoroutineStart.kt:109)
at kotlinx.coroutines.c.a(AbstractCoroutine.kt:160)
at kotlinx.coroutines.k.a(Builders.common.kt:54)
at kotlinx.coroutines.i.b(Unknown Source:1)
at org.jetbrains.anko.h.a.a$g.onClick(ListenersWithCoroutines.kt:299)
at android.view.View.performClick(View.java:6311)
at android.view.View$PerformClick.run(View.java:24791)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6602)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:453)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:821)
具体解决方案,参考了kotlin携程的issue,在你的主工程混淆文件下添加:
# ServiceLoader support
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}
# Most of volatile fields are updated with AFU and should not be mangled
-keepclassmembernames class kotlinx.** {
volatile <fields>;
}