Unresolved reference: launch

前端 未结 4 523
孤独总比滥情好
孤独总比滥情好 2021-02-05 00:58

Trying to run some examples for Kotlin coroutines, but can\'t build my project. I\'m using the latest gradle release - 4.1

Any suggestions what to check/fix?

Her

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 01:43

    Try this way,

    //add this lines to gradle

     implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.kotlinx_coroutines"
     implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.kotlinx_coroutines"
    
    
      class xyz{
         private val job = Job()
            private val coroutinesScope: CoroutineScope = CoroutineScope(job + Dispatchers.IO)
    
          ....
         . ...
           coroutinesScope.launch {
                           // task to do
                            Timber.d("Delete Firebase Instance ID")
                        }
    
    
        // clear the job
          job.cancel()
    
        }
    

提交回复
热议问题