Must be a very simple solution, but...
I'm using StateFlow in my android project to replace LiveData that were used as Observables in a Service. I used LiveData as observables for Room Database but the limitations regarding thread (must register observer and notify on main thread) made me switch to Flow class. Everything fitted nicely and logically, and to keep info about state, I then decided to use StateFlow.
I added
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7"
and
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { kotlinOptions.freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn"] }
in my gradle file and
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
on top of the classes that had StateFlow member types. but I get a crash when I run the project stating:
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/coroutines/flow/StateFlowKt; .... Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlinx.coroutines.flow.StateFlowKt" on path: DexPathList[[zip file "/data/app/com.xxxxx.consumer-X46raHzqXUeRRH40JT1LUg==/base.apk"],nativeLibraryDirectories=[/data/app/com.xxxxx.consumer-X46raHzqXUeRRH40JT1LUg==/lib/arm64, /data/app/com.xxxxx.consumer-X46raHzqXUeRRH40JT1LUg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]] ....
What steps are necessary to add StateFlow in an Android Project using Kotlin?
Thanks!