kotlin 升级1.30出现的bug

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>;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容