Disabling androidAndroidTestRelease source set in gradle Kotlin DSL script

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?

7 Likes

Also getting this error and I would like to get rid of it for similar reasons :slight_smile:

1 Like

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.

2 Likes

I was helped by the setting that was added to previously created projects on KMM:
In gradle.properties file add:

kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false

Setting the gradle.properties flags does not help in our case.

I found some other workarounds in the wild: Remove unused source sets

But would appreciate if this warning could be addressed by the KMM team.

In my case there was more of them.
So, what I did was:

subprojects {
    afterEvaluate {
        project.extensions.findByType<KotlinMultiplatformExtension>()?.let { ext ->
            ext.sourceSets.removeAll { sourceSet ->
                setOf(
                    "androidAndroidTestRelease",
                    "androidTestFixtures",
                    "androidTestFixturesDebug",
                    "androidTestFixturesRelease",
                ).contains(sourceSet.name)
            }
        }
    }
}