compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

"Duplicate content roots detected" for Compose Multiplatform projects in Android Studio

Open SebastianAigner opened this issue 1 year ago • 2 comments

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]
Screenshot 2023-03-23 at 13 01 23

SebastianAigner avatar Mar 23 '23 12:03 SebastianAigner

Same with Idea (Ultimate)

ThraaxSession avatar Mar 24 '23 06:03 ThraaxSession

We discussed this issue with @sellmair:

  1. The root cause of the warning is the following line in shared/build.gradle.kts
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
  1. If we remove the line then the warning disappears but at the same time accessing resources in commonMain/resources via compose.components.resources library causes MissingResourceException for Android target. That is because AGP does not automatically propagate commonMain/resources to Android distribution (because Android has its own resource management that we cannot use for Multiplatform).

  2. 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.

  3. 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.

  4. 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.

  5. 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.

pjBooms avatar Mar 24 '23 08:03 pjBooms

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

23-12-07-Cupio.zip

Morons avatar Dec 07 '23 09:12 Morons

Hi is there any update on this bug? It's pending for a long time. @sellmair @SebastianAigner @pjBooms

swarupbc avatar Mar 18 '24 10:03 swarupbc

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.

chikega avatar May 25 '24 20:05 chikega

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.

terrakok avatar Jun 27 '24 09:06 terrakok