https://kotlinlang.org logo
Title
o

Oluwafemi Ogundipe

04/10/2023, 10:50 AM
I’m having this error
KotlinSourceSet with name 'androidUnitTest' not found.
Here is my configuration, please what am I missing?
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
    }
}
a

atyrin

04/10/2023, 11:36 AM
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

Oluwafemi Ogundipe

04/10/2023, 11:46 AM
Yes It’s there
#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

atyrin

04/10/2023, 12:02 PM
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

Jeff Lockhart

04/10/2023, 3:12 PM
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

atyrin

05/04/2023, 1:40 PM
If you are still experiencing the problem maybe you could share the whole project/project configuration that I can import?