Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for Resources accessors to be generated for custom directory structure #4718

Closed
AlexBurdu opened this issue Apr 27, 2024 · 1 comment · Fixed by #5016
Closed

Allow for Resources accessors to be generated for custom directory structure #4718

AlexBurdu opened this issue Apr 27, 2024 · 1 comment · Fixed by #5016
Assignees
Labels
enhancement New feature or request resources

Comments

@AlexBurdu
Copy link

AlexBurdu commented Apr 27, 2024

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:

  1. Create a new KMP project and customize the directory structure as above
  2. Add a resource in the composeResources directory
  3. Build the project
  4. 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.

@AlexBurdu AlexBurdu added bug Something isn't working submitted labels Apr 27, 2024
@igordmn igordmn added enhancement New feature or request and removed bug Something isn't working labels Apr 30, 2024
@amakeev
Copy link
Member

amakeev commented May 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request resources
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants