Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate to Kotlin coroutines in Android with Kotlin 1.3

What should I change in my build.gradle file or import in classes to use stable coroutine functions in my Android project with Kotlin 1.3 ?

Fragment about coroutines in my build.gradle

implementation "org.jetbrains.kotlin:kotlin-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlin:kotlin-coroutines-android:$coroutines_version"

Of course I use Android Studio 3.3 Preview

like image 748
Patryk Kubiak Avatar asked Oct 24 '18 20:10

Patryk Kubiak


Video Answer


1 Answers

My teammate helped me to find the solution. I had to increase the coroutines version to 1.0.0-RC1. For everyone who may don't know about the changes in using Android coroutines:

  • I had to change the UI context of coroutine to Dispatchers.Main
  • I used old experimental coroutines version (0.23 maybe) so for everyone who don't know - now launch is deprecated and you should use structured concurrency (for example coroutineScope) instead.
  • Now async function cannot be run outside the scope.

I hope I will help someone. Don't waste a time. Happy programming!

like image 190
Patryk Kubiak Avatar answered Nov 15 '22 21:11

Patryk Kubiak