Skip to content

Main dispatcher missing on version 1.2.1 (android gradle plugin 3.5.0-beta02) #1213

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

Closed
sellmair opened this issue May 21, 2019 · 9 comments
Closed

Comments

@sellmair
Copy link
Member

sellmair commented May 21, 2019

When upgrading our project to coroutines version 1.2.1 (from 1.2.0), we get a

    java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'

Here are the relevant parts of our build.gradle:


root:

    ext.coroutines_version = '1.2.1'

one of many library modules in our project module:
(all looking basically the same, there is no import of another version somewhere)


dependencies {
    /* Test */
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    /* Kotlin */
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    /* Coroutines */
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"


Gradle version: 5.4.1
Android gradle plugin: 3.5.0-beta02


The same configuration works using the older agp version 3.4.0 or the older coroutines version 1.2.0

@sellmair
Copy link
Member Author

Seems to work with agp version 3.5.0-beta01 as well.

@elizarov
Copy link
Contributor

May I ask to report the bug to AGP then?

@LouisCAD
Copy link
Contributor

I just reported it myself to bring awareness early to the Android Gradle plugin team: https://issuetracker.google.com/issues/133495912
@sellmair if you have additional details that could help them, please, share them into that linked issue.

@qwwdfsad
Copy link
Collaborator

Thanks, @LouisCAD!
I'll close this one then

@hungvietnguyen
Copy link

Could you provide a more detailed stacktrace to help us debug this issue, or even better, a sample project?

Please post it at https://issuetracker.google.com/issues/133495912.

@sellmair
Copy link
Member Author

Sure, will do a sample project and post it 👍

@rabidaudio
Copy link

If anyone else stumbles across this, it seems to be that AGP 3.5.0 isn't including the META-INF/services/* files (similar to #983 ). There may be some proguard rules way to fix this but we just rolled back to AGP 3.4.0. I have a feeling more people are going to hit this now that 3.5.0 is recommended by Android Studio. I'm going to post this on the AGP issue as well.

@sgjesse
Copy link

sgjesse commented Sep 4, 2019

@rabidaudio Are you seeing issues with coroutines and R8 after upgrading to AGP 3.5.0? Or are you just concerned that META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory is not present?

It is not necessarily an issue that META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory is not included. R8 can optimize/desugar the ServiceLoader calls when performing whole program optimization by rewriting the use of ServiceLoader to a direct instantiation of the class implementing the service. The coroutines library has code to ensure that this R8 optimization can kick in, and there is a test in the repo to test that the ServiceLoader class is not mentioned in the generated dex when using R8.

@wojtek-kalicinski and @JakeWharton have been working on getting the coroutines library and R8 to work seamlessly together, and they might have more precise information in which versions work well together.

(copied this to http://issuetracker.google.com/133495912 as well)

@wojtek-kalicinski
Copy link
Contributor

FYI this doesn't seem to be related to any work I've been doing as my changes landed in AGP 3.6 canary 7 and coroutines 1.3.0.

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

No branches or pull requests

8 participants