Missing module on multiplatform project

Why in a fresh created project androidMain and androidTest are not shown as modules?
I can see them if I switch to Project view, but from AndroidView are not recognized as modules.

Yeah it’s a visual issue. The module is there and works just fine, it’s just not highlighted in the IJ IDEA Project Structure!

have a look here

I know it’s just a visibility issue, but it hurts me a lot!
And I’ve read your answer before, but as I’m a newbie on android, gradle and multiplatform projects, I don’t know how to apply your workaround :sweat_smile:

1 Like

Add this to your build.gradle.kts:

android {
    sourceSets.all {

It will add src/androidMain/kotlin, src/androidMain/res, src/androidMain/resources to your project, as well for androidTest and or whatever flavor you have!

1 Like

mmm. It adds me a “java” source folder with the source code, not “androidMain” and “androidTest” as modules.

I notice another thing: If I open the project structure dialog, I cannot open the “modules” section. It displays nothing…

The problem seems that androidMain and androidTest are not recognized as modules. In fact, if I open android studio .iml files, those two projects are missing.

Trust me, they are there. Create the folders and start writing code, IJ IDEA will start working.

As I said in the other thread, all the information about where source code is and how to compile it is declared via Gradle scripts and its plugins. When syncing, IntelliJ basically tries to understand how you set up the plugins and builds a UI to let you understand that model.

Now, you applied 2 big plugins which are the Android one and the K/MP one. Both of them set up the project in different ways which are often overlapping for some folder/sources. Sometimes IJ IDEA is just unsure to what show or what not to. The icons for the modules when applying both plugins are one.

Nonetheless, Gradle may build just fine (unless yo uscrewed up the build file :stuck_out_tongue:) ! It’s not IJ IDEA that builds, it’s Gradle! So even if an icon is offset, the build will go just fine.

Why the module is not properly recognized by IJ IDEA, but the sources are correctly solved by the IDE, it’s a question that only JB itself can answer. What I always found bothering were the Android sources not aligned with the rest of the K/MP scaffolding…

1 Like

Sure, I know they are there. I’m a newbie on gradle and android development, but I can see that the project compile and run perfectly both on iOS and Android, and I understand perfectly that is just a “visualization issue”.
The problem is that it hurts me a lot and break my Zen! :sweat_smile:

Seriously, what I don’t understand is why after synching with gradle, .iml file for androidMain and androidTest are not created. Cannot I simply fix creating those file by hand?

1 Like

They will be deleted on the next sync! Try searching in the IJ iDEA issue tracker if there’s already something. Probably there is!