Unresolved reference async in Kotlin

后端 未结 3 2021
情歌与酒
情歌与酒 2021-01-04 03:22

I am trying to perform network operation async in Kotlin. I read it you can do async using async function. I am getting below error, can anyone gue

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-04 04:10

    I see async function is available in anko library not Kotlin library itself. https://github.com/Kotlin/anko

    I resolved by adding this dependency in build.gradle compile "org.jetbrains.anko:anko-commons:0.10.1" as this is not available in Kotlin itself.

    I see that async is deprecated now, library suggests to use doAsync instead.

    doAsync {
        val forecastWeather = ForecastRequest("302015").execute()
        uiThread {
            Log.d("Test", forecastWeather.toString())
        }
    }
    

提交回复
热议问题