Search code examples
androidkotlin-multiplatform

I create a new KMM project in Android studio and don't see the androidMain module in Android View


I've spent an entire day trying to solve it, tried to open few projects from github, tried Android studio 4.0, 4.2 canary, IntellyJ Idea but still don't see the androidMain in modules

What should I try?

Screenshot from Android studio


Solution

  • Try adding additional source sets for your android project by setting in your shared:build.gradle.kts file under the android node this

    sourceSets {
        getByName("main") {
            java.srcDirs("src/androidMain/kotlin")
            res.srcDirs("src/androidMain/res")
        }
        getByName("test") {
            java.srcDirs("src/androidTest/kotlin")
            res.srcDirs("src/androidTest/res")
        }
    }
    

    so you could have something like this:

    android {
        compileSdkVersion(29)
        sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
        defaultConfig {
            minSdkVersion(24)
            targetSdkVersion(29)
            versionCode = 1
            versionName = "1.0"
        }
        buildTypes {
            getByName("release") {
                isMinifyEnabled = false
            }
        }
    
        sourceSets {
            getByName("main") {
                java.srcDirs("src/androidMain/kotlin")
                res.srcDirs("src/androidMain/res")
            }
            getByName("test") {
                java.srcDirs("src/androidTest/kotlin")
                res.srcDirs("src/androidTest/res")
            }
        }
    }
    

    This way you could see the androidMain and androidTest kotlin files under your MyApplication11 node

    enter image description here