compose-multiplatform
compose-multiplatform copied to clipboard
Allow for Resources accessors to be generated for custom directory structure
Describe the bug
In the project I'm working on we try to reduce the nesting of the directories and customized the directory structure:
sourceSets {
val commonMain by getting {
kotlin.apply {
srcDir("commonMain")
resources.srcDir("commonMain/composeResources")
}
// missing code
}
// missing code
What happens is that the Resources accessors (extensions) are not generated, hence we can't do Res.drawable.cupcake and still need to rely on DrawableResource("drawable/copcake.xml").
It would appear that the new compose resources feature relies on the standard structure and does not generate the accessors when that is customized.
Changing the above to the following fixes the issue:
sourceSets {
val commonMain by getting {
kotlin.apply {
srcDir("src/commonMain")
resources.srcDir("src/commonMain/composeResources")
}
// missing code
}
// missing code
Notice the src addition.
Affected platforms
- Tested Desktop (Linux) and Android, but I expect it to happen on all
Versions
- Kotlin version*: 1.9.23
- Compose Multiplatform version*: 1.6.2
- OS version(s)* (required for Desktop and iOS issues): Ubuntu 22.04.4 LTS
- OS architecture (x86 or arm64): x64
- JDK (for desktop issues): Temurin 17.0.6
To Reproduce Steps and/or the code snippet to reproduce the behavior:
- Create a new KMP project and customize the directory structure as above
- Add a resource in the composeResources directory
- Build the project
- Observe
Unresolved reference: cupcake
Expected behavior Resources should be accessible for custom directory structure, as the path to them is provided in the gradle configuration.
One of the use-cases for this is Compose Resources support in Amper. The current limitation in the Compose Gradle Plugin doesn't allow configuring it for the Amper-native project layout, which uses the flat folders structure. Example:
project/
src/
src@android/
composeRresources/
...
module.yaml
settings.gradle.kts
In this example layout, the composeResources folder is located on the module/project level, without additional nesting.
Currently, there is a workaround for Amper to use Gradle-compatible project layout. But this leads to additional setup burden on the user.
In order to support Amper-native project layout, Compose Gradle plugin should allow customizable location of the composeResources folder
See: AMPER-555 Support Compose resources in native Amper layout
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.