kotlinx.coroutines: VerifyError on Android since 1.3.7

java.lang.VerifyError: Verifier rejected class cz.masterapp.clones.App$onCreate$4: java.lang.Object cz.masterapp.clones.App$onCreate$4.invokeSuspend(java.lang.Object) failed to verify: java.lang.Object cz.masterapp.clones.App$onCreate$4.invokeSuspend(java.lang.Object): [0x129] cannot access instance field java.lang.Object kotlin.jvm.internal.Ref$ObjectRef.element from object of type Reference: java.io.IOException (declaration of 'cz.masterapp.clones.App$onCreate$4' appears in /data/app/cz.masterapp.annie3-BWvfpH7rb3wf9eY9Lx8gIA==/base.apk:classes2.dex)
     FATAL EXCEPTION: main
Process: cz.masterapp.annie3, PID: 12229
java.lang.VerifyError: Verifier rejected class cz.masterapp.clones.App$onCreate$4: java.lang.Object cz.masterapp.clones.App$onCreate$4.invokeSuspend(java.lang.Object) failed to verify: java.lang.Object cz.masterapp.clones.App$onCreate$4.invokeSuspend(java.lang.Object): [0x129] cannot access instance field java.lang.Object kotlin.jvm.internal.Ref$ObjectRef.element from object of type Reference: java.io.IOException (declaration of 'cz.masterapp.clones.App$onCreate$4' appears in /data/app/cz.masterapp.annie3-BWvfpH7rb3wf9eY9Lx8gIA==/base.apk:classes2.dex)
	at cz.masterapp.clones.App.onCreate(App.kt:277)
	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791)
	at android.app.ActivityThread.-wrap1(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
	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)

In App.kt:277 is just GlobalScope.launch {

Reverting to 1.3.6 fixes the crash (but it has the #2004, which has a workaround)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 20
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

It happend to me when I used coroutines- withContext in 1.3.7 to 1.3.8 on Android/Flutter, revert coroutines lib to 1.3.6 , the app does not crash anymore.

Unfortunately, this is a bug in Kotlin compiler related to function with contracts that were added in #2030.

We are working on the fix, a workaround is to extract withContext calls from try and catch blocks (I’ll try to post more specific workaround later) to separate functions. Sorry for the inconvenience!

It’s happening with Android Gradle Plugins 3.6.2, 3.6.3 and 4.0.0-rc01, so I think it’s not caused by D8/R8.

Also, it’s happening with debug builds, and I think they are not using R8 in default configuration.

Fixed in 1.3.9 with Kotlin 1.4

Changing kotlin_version to 1.4.0-rc solved the problem.

I confirm that a similar problem https://youtrack.jetbrains.com/issue/KT-39298 is not reproduced with Kotlin 1.4-M2. The bug with contracts mentioned above was fixed in 1.4-M2.