https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Meika

02/24/2024, 9:38 AM
hi, I keep getting this error when building my multiplatform library.
WeakReference
is an expect class that already implemented on
jvmMain
. code in thread 🧵
Copy code
> Task :bindable-lib:compileDebugKotlinAndroid FAILED
e: file:///xxxx/bindable/bindable-lib/src/commonMain/kotlin/moe/ganen/bindable/WeakReference.kt:3:21 Expected class 'WeakReference' has no actual declaration in module <bindable-lib_debug> for JVM

> Task :bindable-lib:compileReleaseKotlinAndroid FAILED
e: file:///xxxx/bindable/bindable-lib/src/commonMain/kotlin/moe/ganen/bindable/WeakReference.kt:3:21 Expected class 'WeakReference' has no actual declaration in module <bindable-lib_release> for JVM
expect declaration
Copy code
public expect class WeakReference<T : Any>(referred: T) {
    public fun clear()

    public fun get(): T?
}
actual declaration on
jvmMain
Copy code
public actual class WeakReference<T : Any> actual constructor(referred: T) : WeakReference<T>(referred)
also to put in context, I'm targeting jvm and android sourceset only
j

Javier

02/24/2024, 9:48 AM
Both are independent source sets
You need to add the actual to android one too, or add a shared folder to both source sets
👍 1
m

Meika

02/24/2024, 9:54 AM
aha, I thought you don't need to declare the actual on Android set since the IDE only ask actual on
jvmMain
. adding the actual implementation on Android fixed it. thank you
3 Views