How can I connect the Android sourcesets (androidD...
# gradle
h
How can I connect the Android sourcesets (androidDebug/androidInstrumentationTest) to the android source set with a KMP library having a jvm target too, and using kotlin.mpp.androidSourceSetLayoutVersion=2?
Copy code
import org.jetbrains.kotlin.gradle.plugin.*

plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
    id("com.android.library")
    kotlin("plugin.parcelize")
}

kotlin {
    jvm()
    js(IR) {
        browser()
        nodejs()
    }

    // tier 1
    linuxX64()
    macosX64()
    macosArm64()
    iosSimulatorArm64()
    iosX64()

    // tier 2
    linuxArm64()
    watchosSimulatorArm64()
    watchosX64()
    watchosArm32()
    watchosArm64()
    tvosSimulatorArm64()
    tvosX64()
    tvosArm64()
    iosArm64()

    // tier 3
    androidNativeArm32()
    androidNativeArm64()
    androidNativeX86()
    androidNativeX64()
    mingwX64()
    watchosDeviceArm64()

    jvmToolchain(8)
    applyDefaultHierarchyTemplate {
        common {
            group("linuxDerivat") {
                group("androidNative")
                group("linux")
            }
        }
    }
}

android {
    compileSdk = 34
}

kotlin {
    androidTarget {
        instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
    }
}

tasks.register("printDependsOns") {
    doFirst {
        kotlin.sourceSets.map { from ->
            "${from.name} -> ${from.dependsOn.map { it.name }}"
        }.sorted().forEach { println(it) }
    }
}
This results into this sourceset tree:
Copy code
androidDebug -> [commonMain]
androidInstrumentedTest -> [commonTest]
androidInstrumentedTestDebug -> [commonTest]
androidMain -> [commonMain]
androidRelease -> [commonMain]
androidUnitTest -> [commonTest]
androidUnitTestDebug -> [commonTest]
androidUnitTestRelease -> [commonTest]
But I miss the intermediate source sets:
androidDebug -> androidMain -> commonMain
or
androidUnitTest -> androidTest -> commonTest
Okay, I am able to fix it by adding the androidTarget to the source set group
android
but I am surprised I need to add the group manually:
Copy code
kotlin {
  applyDefaultHierarchyTemplate {
    common {
      group("android") {
        withAndroidTarget()
       }
    }
  }
}