I’ve recently had a problem with importing a dependency in commonMain in CMP. More specifically I was trying out the new navigation3 component. Since I first tried out Nav3 in Android - I blindly copied over the dependency to my CMP project.
My Android CMP build was working fine - and I was happy. However, I decided to give my other target a run - specifically the iOS one. I was very surprised when I couldn’t make the project compile.
I quadruple-checked everything, cleaned gradle cache, and restarted the project around 5 times - but it just wouldn’t compile. So I went checking everything line by line.
And then I saw it:
I was importing an Android dependency in commonMain.
This seemingly minor mistake - can create a lot of pain if you’re not careful. An Android dependency that is put into commonMain.dependencies{} will resolve without issues… on Android. But the same project won’t compile when you try to launch iOS.
Sooo… if you’re working with CMP / KMP - make sure you’re not putting platform-specific libraries into commonMain!
Member discussion: