Migrate your Android project to Kotlin 1.3

Ta Theerasan Tonthongkam
ta tonthongkam
Published in
2 min readNov 13, 2018

Kotlin 1.3 has been released together with the stable version of the coroutine. In my current project, we are so brave to use the experimental coroutine. However, we trust our team to figure out if something unusual happened, we also trust our QA to cover our ass.

So, from Kotlin 1.26.x to Kotlin 1.3 just edit the dependency it should fine. Right? but it’s not. In the file build.gradle show error like “have to update coroutine to work with Kotlin 1.3” — Some of the experimental coroutine classes have pulled out from the core, thus we need to add those classes belong to Android platform back. So I have to update the dependency like this.

//update core version
implementation “org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1”
//add coroutines for Android
implementation “org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1”

Also remove experimental out!!

//remove this
kotlin {
experimental {
coroutines "enable"
}
}

Then I rebuilt the project, I’ve started to notice that the coroutine packages and locations are changed, therefore it makes all existing import error, Luckily, we can use Android Studio to inspect all error code.

“Just reimport it should be okay?”

Example of import changed

No, again!! seem like packages of coroutine has been changed a lot. So I have to edit code like this

Example of code changed
GlobalScope.launch(Dispatchers.Main) -> for launch coroutine on main threadGlobalScope.async(Dispatchers.IO) -> for async coroutine on Background thread.

Everything associated with the ‘main thread’ use ‘Dispatchers.Main’, and the ‘background thread’ use ‘Dispatchers.IO’.

From this point, a good code architecture helps me a lot. I don’t have to look into every class and check the code. IDE also helps me check code error as well. About the migrating from Kotlin 1.26.x to 1.3.0 with stable coroutine have some pain point, but it not that hard if you have a well code architecture.

Thank you

— end of the story —

--

--