Solved: The following Kotlin source sets were configured but not added to any Kotlin compilation

Problem

Solved: The following Kotlin source sets were configured but not added to any Kotlin compilation

Problem

In the KMM project, when build KMM code, it ways report the following warning:The following Kotlin source sets were configured but not added to any Kotlin compilation:
* androidAndroidTestRelease
* androidTestFixtures
* androidTestFixturesDebug
* androidTestFixturesReleaseYou 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

Although its just a warning message, but it’s annoying, I want to remove it on my project. And finally, I got the solution from this website.

Solution

Add the following code to the root project’s build.gradle.kts file.import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtensionallprojects {
   repositories {
     ...
   }
   // https://discuss.kotlinlang.org/t/disabling-androidandroidtestrelease-source-set-in-gradle-kotlin-dsl-script/21448/5
   afterEvaluate {
       // Remove log pollution until Android support in KMP improves.
       project.extensions.findByType<KotlinMultiplatformExtension>()?.let { kmpExt ->
           kmpExt.sourceSets.removeAll {
               setOf(
                   "androidAndroidTestRelease",
                   "androidTestFixtures",
                   "androidTestFixturesDebug",
                   "androidTestFixturesRelease",
               ).contains(it.name)
           }
       }
   }
}

Resources