https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
u

uli

03/15/2024, 11:50 AM
Hi multi platform enthusiast, today I ran into an issue with Android Studio, where gradle sync failed in
compileCommonMainKotlinMetadata
due to an error in one of my actual app source files. (just a typo in the imports). I don’t think I have ever seen that on pure android projects so it was quite surprising to me to see that the actual app sources are relevant for the sync process. And it is a real pain to make the app sources compile again without your IDE working. Am I doing something wrong here? Is this just a plain (known?) bug that needs to be fixed in the gradle plugin? Or does it work as designed due to some multi platform requirements? I’d be thankful if anyone could shed some light on that issue.
👀 1
One more data point. I am using ksp and followed this page to set it up: https://kotlinlang.org/docs/ksp-multiplatform.html There it mentions to put a dependency on commonMainMetadata so maybe that’s related to my issue? Why we need a dependency on commonMainMetadata is unclear and has also been questioned here: https://kotlinlang.slack.com/archives/C3PQML5NU/p1710447465610489
g

Gleb

03/15/2024, 5:48 PM
Hi, I encountered the same issue in the past. I never managed to find a way to solve it. Just letting you know, you’re not alone here
gratitude thank you 1
u

uli

03/15/2024, 8:40 PM
Did you have ksp set up when that happened?
g

Gleb

03/16/2024, 10:27 PM
Yes, as soon as I added KSP I started having similar problems
u

uli

03/18/2024, 7:44 AM
Let me try crossposting to #ksp
t

Ting-Yuan Huang

03/18/2024, 6:07 PM
that sounds not right. Can you share more details like logs / tasks / errors or a project for reproducing the issue?
Also, can you try to remove the
kspCommonMainMetadata
to see if the problems remains?
u

uli

03/20/2024, 4:17 PM
completely removing ksp does not help. Guess I have to look into other directions. Btw. I am using include builds. Maybe that’s a hint.
Ok, I did some more investigation and removed all plugins from main build and includeBuild except kotlin multiplatform • Introducing a syntax error in any of the includeBuilds commonMain kotlin source files will still break ide sync • Introducing a syntax error in any of the includeBuilds platform specific xxxxMain kotlin source files will not break ide sync • Introducing a syntax error in any of the main app’s commonMain kotlin source files will not break ide sync • Introducing a syntax error in any of the main app’s platform specific xxxxMain kotlin source files will not break ide sync So this is either a kotlin multi platform + includeBuild issue or just an includeBuild issue
I found the cause: Having a main kotlin multi platform project with an includeBuild kotlin multi platform library. Then setting
kotlin.mpp.enableCInteropCommonization=true
on the main project will cause the task
compileCommonMainKotlinMetadata
to run on the includeBuild during IDE gradle project sync and thereby causes the sync to fail on all errors in the kotlin code
Is this the wrong channel? Is Jetbrains reading here? Could some one comment if this is a known issue? A new bug to report? Or works as designed?
I found the cause:
Having a main kotlin multi platform project with an includeBuild kotlin multi platform library. Then setting
kotlin.mpp.enableCInteropCommonization=true
on the main project will cause the task
compileCommonMainKotlinMetadata
to run on the includeBuild during IDE gradle project sync and thereby causes the sync to fail on all errors in the kotlin code (edited)
Here is a reproducer:
https://github.com/uluckas/SyncIssueDemo