Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 360
Vlkam Avatar asked Feb 02 '26 01:02

Vlkam


1 Answers

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

like image 139
shadowsheep Avatar answered Feb 04 '26 13:02

shadowsheep