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

Kurt Renzo Acosta

03/05/2020, 1:36 AM
Has anyone encountered and resolved this error: `Class
MyClass
has several compatible actual declarations in modules module_iosX64Main, module_iosMain` , `Class
MyClass
has several compatible actual declarations in modules module_iosArm64Main, module_iosMain`? I'm trying to use the target shortcuts for iOS and my expect/actual declarations are having this error. Before I was using a switching mechanism between the device and simulator like this:
Copy code
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

iOSTarget("ios") {
    // config...
}
r

russhwolf

03/05/2020, 2:26 AM
Sounds like you have
actual class MyClass
in
iosMain
in addition to
iosArm64Main
and
iosX64Main
. Should either have separate declarations in the two different architecture sourceSets or a single definition in the shared one.
k

Kurt Renzo Acosta

03/05/2020, 2:27 AM
I just have a class in
iosMain
, not in
iosArm64Main
and
iosX64Main
since their implementation is the same
I don't have any declarations in
X64
and
Arm64
r

russhwolf

03/05/2020, 2:28 AM
Not sure then. The error seems to think otherwise.
You definitely only have a single
actual
in there?
k

Kurt Renzo Acosta

03/05/2020, 2:29 AM
Yep
r

russhwolf

03/05/2020, 2:30 AM
Maybe post your build.gradle
k

Kurt Renzo Acosta

03/05/2020, 2:31 AM
Copy code
plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.multiplatform")
}

val KOTLIN_VERSION = "1.3.70"
val COROUTINES_VERSION = "1.3.3"

val frameworkName = "MultiplatformPaging"

android {
    compileSdkVersion(29)
    defaultConfig {
        minSdkVersion(21)
        targetSdkVersion(29)

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = true
            consumerProguardFiles("<http://consumer-rules.pro|consumer-rules.pro>")
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    sourceSets {
        getByName("main") {
            manifest.srcFile("src/androidMain/AndroidManifest.xml")
            java.srcDirs("src/androidMain/kotlin")
            res.srcDirs("src/androidMain/res")
        }
        getByName("test") {
            java.srcDirs("src/androidTest/kotlin")
            res.srcDirs("src/androidTest/res")
        }
        getByName("androidTest") {
            java.srcDirs("src/androidInstrumentedTest/kotlin")
            res.srcDirs("src/androidInstrumentedTest/res")
        }
    }
}

kotlin {
    ios {
        binaries {
            framework(frameworkName) {
                baseName = frameworkName
            }
        }
    }
    android()

    sourceSets["commonMain"].dependencies {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:${COROUTINES_VERSION}")
    }

    sourceSets["iosMain"].dependencies {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:${COROUTINES_VERSION}")
    }
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$COROUTINES_VERSION")
    implementation("androidx.paging:paging-runtime:2.1.1")
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.2.0")

}
r

russhwolf

03/05/2020, 2:33 AM
Not seeing anything obvious, sorry. You should note though that coroutines 1.3.3 won’t work with 1.3.70 on native. I don’t think that’s the cause of your issue though.
k

Kurt Renzo Acosta

03/05/2020, 2:35 AM
Yeah. I just found about that now. Maybe it's just an IDE error? It builds fine but the error is just annoying. Oh well. Thanks for the help!
r

russhwolf

03/05/2020, 2:36 AM
Oh yeah if it builds fine I wouldn’t worry too much (as long as the IDE inference is still working too). Living with some warnings is a fact of life sometimes with this stuff while it’s still beta/experimental
k

Kurt Renzo Acosta

03/05/2020, 2:44 AM
Yeah. Guess I have to suppress my annoyance instead of this "warning"
If anyone comes across this, I was able to suppress it with
Copy code
kotlin.mpp.enableGranularSourceSetsMetadata=true
However, I remember that if you are using cocoapods with these, the libraries from pods won't be seen by the IDE. I haven't been able to verify if it still occurs now though
It doesn't detect the actual declarations in the
androidMain
source set though ☹️
a

Artyom Degtyarev [JB]

03/05/2020, 10:20 AM
Hello, @Kurt Renzo Acosta! Can you tell the IDE and Kotlin IDE plugin versions? We’re trying to reproduce the problem locally, but with no luck.
k

Kurt Renzo Acosta

03/05/2020, 10:23 AM
Android Studio 3.6.1 then Kotlin Plugin is 1.3.70 for AS 3.6.1
It's occurring since 1.3.60. Here's a link to an issue: https://github.com/JetBrains/kotlin-native/issues/3668
Let me know if there's anything else I can give to help this get resolved
a

Artyom Degtyarev [JB]

03/05/2020, 11:04 AM
I’m sorry but I was talking about the
several compatible actual declarations
, which was not mentioned in the GH issue.
k

Kurt Renzo Acosta

03/05/2020, 11:09 AM
Ah yeah. It was resolved by the gradle property but it can't find my android source set
a

Artyom Degtyarev [JB]

03/05/2020, 11:17 AM
Ugh, okay. So the problem you wanted to illustrate by the GH-3668 is that the Gradle property
kotlin.mpp.enableGranularSourceSetsMetadata=true
breaks the expect/actual highlighting in the AS, right? I’m feeling lost a bit as I’ve joined the discussion too late.