Migrate your Android project to Kotlin 1.3
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
//add coroutines for Android
Also remove experimental out!!
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?”
No, again!! seem like packages of coroutine has been changed a lot. So I have to edit code like this
GlobalScope.launch(Dispatchers.Main) -> for launch coroutine on main thread
GlobalScope.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.
— end of the story —