I’m having this error `KotlinSourceSet with name ...
# multiplatform
o
I’m having this error
KotlinSourceSet with name 'androidUnitTest' not found.
Here is my configuration, please what am I missing?
Copy code
plugins {
    kotlin(Plugins.multiplatform)
    kotlin(Plugins.nativeCocoapods)
    id(Plugins.androidLibrary) version Versions.androidGradlePlugin
    id(Plugins.ktlint) version Versions.ktlintVersion
    id(Plugins.kotlinx_serialization)
    id("io.kotest.multiplatform") version "5.0.2"
}

kotlin {
    android {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
    targets {
        jvm {
            compilations.all {
                kotlinOptions {
                    jvmTarget = "1.8"
                }
            }
        }
        android {
            compilations.all {
                kotlinOptions {
                    jvmTarget = "1.8"
                }
            }
        }
        iosX64()
    }
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0"
        ios.deploymentTarget = "14.1"
        framework {
            baseName = "magicsdk"
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(Google.gson)
                // ktor
                implementation(Ktor.clientSerialization)
                implementation(Ktor.serialization_kotlinx)
                implementation(Ktor.ktor_json_serialization)
                implementation(Ktor.content_negotiation)
                implementation(Ktor.core)
                implementation(Ktor.kmmLogging)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation("io.kotest:kotest-framework-engine:5.0.2")
//                implementation("io.kotest:kotest-assertions-core:5.0.2")
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(Ktor.android)
                implementation(Ktor.ktor_client_android_okhttp)
                implementation(SQLDelight.androidDriver)
                implementation(Ktor.logging)
            }
        }
        val androidUnitTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
            dependencies {
                implementation(Ktor.ktor_darwin)
                implementation(Ktor.ios)
                implementation(SQLDelight.nativeDriver)
            }
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

android {
    namespace = "com.tilbury.magic"
    compileSdk = Application.compileSdk
    defaultConfig {
        minSdk = Application.minSdk
        targetSdk = Application.targetSdk
    }
}
🧵 2
a
Did you add
kotlin.mpp.androidSourceSetLayoutVersion=2
to your
gradle.properties
?
androidUnitTest
is available only in the new layout. https://kotlinlang.org/docs/whatsnew18.html#kotlin-multiplatform-a-new-android-source-set-layout
o
Yes It’s there
Copy code
#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"

#Kotlin
kotlin.code.style=official

#Android
android.useAndroidX=true
android.nonTransitiveRClass=true

#MPP
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2
@atyrin
a
Then I don’t see any problems with the configuration in the build script regarding missed ‘androidUnitTest’. Is the Kotlin version 1.8.0 or higher?
j
You're declaring Android targets twice with both
android { ... }
and
android()
.
Also
iosX64()
is called twice.
Try replacing everything between
kotlin {
and
android()
with
jvmToolchain(8)
, as that seems to be your goal with those lines.
a
If you are still experiencing the problem maybe you could share the whole project/project configuration that I can import?
1393 Views