Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation error: "-Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond"

When I try to compile my Android app written in Kotlin, I get the following compilation error, and my build fails:

w: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond

How can I fix this?

like image 263
grooveplex Avatar asked Oct 30 '18 09:10

grooveplex


2 Answers

It turns out it is actually very easy to solve this problem, and I thought I'd document my solution for people who will undoubtedly stumble upon the same problem in the future.

Simply remove the following block from your app-level build.gradle, hit "Sync Now" in Android Studio and rebuild:

kotlin {
    experimental {
        coroutines "enable"
    }
}
like image 94
grooveplex Avatar answered Sep 23 '22 03:09

grooveplex


You don't need this anymore when using Kotlin 1.3 as it removed the "experimental" nature of Coroutines. See here:

Coroutines are now stable

Coroutines are a modern way to write non-blocking asynchronous code that’s easy to understand and evolve. It’s a powerful tool for anything from offloading work onto background workers to implementing complicated network protocols. The kotlinx.coroutines library hits 1.0 release and provides a solid foundation for managing asynchronous jobs at any scale including composition, cancelation, exception handling and UI-specific use cases.

You probably have a missing reference in your build script, e.g.:

kotlin {
    experimental {
        coroutines "enable"
    }
}
like image 37
s1m0nw1 Avatar answered Sep 26 '22 03:09

s1m0nw1