I am using ion, a library for Android. As shown in ion-kotlin, one can use a method called await()
like so:
fun getFiles(files: Array<String>) = async {
for (file in files) {
Ion.with(context)
.load(file)
.asString()
.await()
}
}
I copy pasted that exact function into my MainActivity
class, as a test. However, I got the error "unresolved reference: await" in Android Studio.
This was confusing because my app's build.gradle
file has the following two lines:
implementation 'com.koushikdutta.ion:ion:2.+'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5'
This brings me to my first question, how can I use the .await()
method in the ion library?
I thought that maybe I had to manually download AsyncAwait.kt, which was the only file in the source folder of ion-kotlin.
So, I downloaded that file and placed it in my project's package. I changed the package declaration at the top of the downloaded file from package com.koushikdutta.ion.kotlin
to package com.example.vroy1.recylerviewtest
.
That seemed to partially solve the problem because I no longer had the "unresolved reference: await" error in Android Studio.
But, the file AsyncAwait.kt refuses to compile. I am getting several errors.
One of the errors is occurring at an import statement at the top of the file. The error is:
This brings me to my second question. If the only way to use .await()
is to manually download AsyncAwait.kt, how can I fix this error so the file will compile?