In my Kotlin Multiplatform project, I have code that is sufficiently tested via JVM based tests. The Android specific code in androidMain/ only adds a few extras, so I do not need to add Android JUnit tests. I do get this message:
The Kotlin source set androidAndroidTestRelease was configured but not added to any Kotlin compilation. You can add a source set to a target’s compilation by connecting it with the compilation’s default source set using ‘dependsOn’.
How do I disable that sourceset to avoid this warning?
We work around the warning by manually including the androidAndroidTestRelease source set in the androidTest source set using dependsOn. These are the changes you’ll need to make to your build.gradle.kts file:
// Workaround for:
//
// The Kotlin source set androidAndroidTestRelease was configured but not added to any
// Kotlin compilation. You can add a source set to a target's compilation by connecting it
// with the compilation's default source set using 'dependsOn'.
// See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
//
// This workaround includes `dependsOn(androidAndroidTestRelease)` in the `androidTest` sourceSet.
val androidAndroidTestRelease by getting
val androidTest by getting {
dependsOn(androidAndroidTestRelease)
...
}
While this doesn’t disable your android tests, it will get rid of the warning.
I tried a variation of this and it worked in gradle builds, but for some reason failed with an error like this when doing a gradle sync in Android Studio:
Key androidAndroidTestRelease is missing in the map.
Here is what I am doing instead:
subprojects {
afterEvaluate {
project.extensions.findByType<KotlinMultiplatformExtension>()?.let { ext ->
ext.sourceSets {
// Workaround for:
//
// The Kotlin source set androidXXXXX was configured but not added to any
// Kotlin compilation. You can add a source set to a target's compilation by connecting it
// with the compilation's default source set using 'dependsOn'.
// See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
sequenceOf("AndroidTest", "TestFixtures").forEach { artifact ->
sequenceOf("", "Release", "Debug").forEach { variant ->
findByName("android$artifact$variant")
?.let(::remove)
}
}
}
}
}
}