compose-multiplatform
compose-multiplatform copied to clipboard
"Duplicate content roots detected" for Compose Multiplatform projects in Android Studio
Opening a CMP project (like the template) in Android Studio, I regularly get this message:
Path [/Users/Sebastian.Aigner/Desktop/github/compose-multiplatform-template2/shared/src/commonMain/resources] of module [My_application.shared.commonMain] was removed from modules [My_application.shared.main]

Same with Idea (Ultimate)
We discussed this issue with @sellmair:
- The root cause of the warning is the following line in
shared/build.gradle.kts
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
-
If we remove the line then the warning disappears but at the same time accessing resources in
commonMain/resources
viacompose.components.resources
library causesMissingResourceException
for Android target. That is because AGP does not automatically propagatecommonMain/resources
to Android distribution (because Android has its own resource management that we cannot use for Multiplatform). -
However declaring propagation explicitly via
sourceSets["main"].resources.
really creates a duplicate (logical) root: one comes from commonMain source set on which Android source set depends and another we declare explicitly. -
It seems that removing the logical root does not bring any harm so the warning is just superfluous for now. However the warning comes from a quite deep base so suppressing it properly just for this case can be not trivial task.
-
We agreed with @sellmair that he will try to find a nice harmless way to suppress it. If he fails then users will live with the warning for a while.
-
It the future It seems AGP team should be involved to this process so
commonMain/resources
would be automatically propagated without explicit declaration in our case.
For me, the problem is actually simple / easy solvable, For me, it looks like Android R works with res and desktop with resources, While I attempt to re-use resources to mimic Android Material3 inside Desktop, I have implemented it different that seem to work.
The problem stems from the multiple assignments of the directory "src/commonMain/res" as source sets, The distinction is not made between the various modules in which it is defined. We, however, need a Single source of "src/commonMain/res" to be able to be shared among all builds of the composeApp, iosApp, etc. to get the resource as a single source of truth.
Similar
Maybe the same could be said for the resource folder in packaged WAR files that changes from "src/main/resources/" to "/opt/tomcat/webapps/{jar deployment folder name}/WEB-INF/classes/" as an example. These need to re-map automatically in the process of making a WAR file.
Find attached project
I have tried to solve the resource fonts for Material3 FontFamily this way and it seem to work. I might miss other cenarios that I have not yet encountered Please download google tff files for Ubuntu and Quicksand into the resource folder (:shared/src/commonMain/res/font) as they were to large for this forum, thus I removed them
Hi is there any update on this bug? It's pending for a long time. @sellmair @SebastianAigner @pjBooms
Fresh install of Android Studio, Kotlin, KMM, KDoctor, etc.. and I ran into this very same problem following the 'Get Started Kotlin Multiplatform Development' tutorial.
As was said before, it is the problem on the IDE/import side. We don't have a plan to do anything on the compose side. @pjBooms gave a perfect explanation above.