Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a keep rule for AndroidDispatcherFactory for R8 version > 1.6.0 #2154

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

OscarSpruit
Copy link
Contributor

In commit #3a8a0ea this keep rule was removed from kotlinx-coroutines-core (which is good), but this caused AndroidDispatcherFactory to be minimized in newer R8 versions. Adding a rule explicitly fixes the problem.

I didn't succeed in making a sample project to reproduce the issue, as the project that faces this issue has a complex multi module setup (which might be the cause). I verified this change is working by including the local kotlinx-coroutines-android jar in the project and not getting the following error:

Fatal Exception: java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
       at kotlinx.coroutines.internal.MainDispatchersKt.throwMissingMainDispatcherException(MainDispatchersKt.java:76)
       at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing(MissingMainCoroutineDispatcher.java:110)
       at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MissingMainCoroutineDispatcher.java:91)
       at kotlinx.coroutines.DispatchedContinuation.resumeCancellableWith(DispatchedContinuation.java:199)
       at kotlinx.coroutines.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuationKt.java:285)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(CancellableKt.java:26)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:109)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.java:158)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_commonKt.java:56)
       at kotlinx.coroutines.BuildersKt.launch(BuildersKt.java:1)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(BuildersKt__Builders_commonKt.java:49)
       at kotlinx.coroutines.BuildersKt.launch$default(BuildersKt.java:1)

In commit #3a8a0ea this keep rule was removed from kotlinx-coroutines-core (which is good), but
this caused AndroidDispatcherFactory to be minimized in newer R8 versions. Adding a rule explicitly
fixes the problem.
@elizarov
Copy link
Contributor

elizarov commented Jul 21, 2020

This is really strange and seems to be some kind of R8 bug that reproduces only in your rare circumstances since kotlinx.coroutines.android.AndroidDispatcherFactory is mentioned in the services file. Anyway, this is not really relevant as I see no harm in adding a rule here. Thanks for your contribution.

@elizarov elizarov merged commit 3cc9b94 into Kotlin:develop Jul 21, 2020
@OscarSpruit
Copy link
Contributor Author

Thanks! Agreed, it's probably some R8 bug. My wild guess would be that R8 gets confused from the multiple modules and transitive dependencies on older versions of kotlinx-coroutines-android.

recheej pushed a commit to recheej/kotlinx.coroutines that referenced this pull request Dec 28, 2020
…otlin#2154)

In commit #3a8a0ea this keep rule was removed from kotlinx-coroutines-core (which is good), but
this caused AndroidDispatcherFactory to be minimized in newer R8 versions. Adding a rule explicitly
fixes the problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants