Hi there :slightly_smiling_face: I'm hoping someon...
# android
e
Hi there šŸ™‚ I'm hoping someone can help. In KMP our project we have a
debug
and a
release
build types. The app module is a plain Android module. We have a second module that's a KMP module. Every dependency from the KMP module shows in red in the app module. I fixed it by replacing
Copy code
androidMain {
    dependsOn(commonMain)
}
with
Copy code
androidDebug {
    dependsOn(commonMain)
}

androidRelease {
    dependsOn(commonMain)
}
I'm wondering why this works. Is something wrong with my configuration, is this the expected behaviour, or...?
l
What android gradle plugin version?
e
Copy code
com.android.tools.build:gradle:7.3.1
org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10
l
I don’t see this on 7.3.1 and 1.7.10, so it’s likely not a gradle plugin issue. I believe androidRelease and androidDebug are separate source sets. I’d keep androidMain dependsOn commonMain and add android{Release,Debug} dependsOn androidMain
e
How come without adding dependencies for release and debug Android Studio isn't recognizing files from commonMain? I mean, it still compiles and runs, so it seems like a bug somewhere?
It's a good idea to have release/debug depend on one sourceset, so I'll definitely make that change.
l
Not sure. There’s often issues in AS with recognizing uncommon source set configurations.
I’d just make sure that your android configuration source sets depend on androidMain and androidMain depends os commonMain.
e
Yup. I'll do that, thanks Landy! Is debug/release considered uncommon?
Just a quick update...
Copy code
androidMain {
            dependsOn(commonMain)
        }

        androidDebug {
            dependsOn(androidMain)
        }

        androidRelease {
            dependsOn(androidMain)
        }
Does not work.
Copy code
androidDebug {
            dependsOn(commonMain)
        }

        androidRelease {
            dependsOn(commonMain)
        }
Does.
I suspect the IDE actively chooses to ignore
androidMain
for some reason, so depending on it is no good.
l
Can you send a snippet with your build.gradle.kts?
e
I can't unfortunately, client NDA šŸ˜ž But maybe I could share a relevant section, if that helps? Also, I'm using groovy, so it's build.gradle šŸ™‚
l
Makes sense. I haven’t done the android app in a separate module in a while (I tend to put the MainActivity and manifest in androidMain directly), but I’d imagine that somewhere, there’s a dependency that’s not set right. How are you doing androidDebug { dependsOn(commonMain) }? Wouldn’t commonMain be in the KMP module and androidDebug be in the android app module?
Are you using implementation(project(ā€œ:module-nameā€)) to depend on the KMP module?
e
I have one KMP library module with both commonMain and androidMain. The main app module (and some other modules) are pure Android modules. They depend on the KMP module, and compile and run fine. But in the IDE, sources aren't linked until I introduce the changes mentioned above.
Are you using implementation(project(ā€œ:module-nameā€)) to depend on the KMP module?
Yes šŸ™‚