JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.24k stars 1.11k forks source link

[Compose Resources] commonMainResourceAccessors is not generated in multi-module architecture using Kotlin 2.0.0 #4873

Closed sereden closed 1 month ago

sereden commented 1 month ago

The official statement says: Starting with 1.6.10, you can place resources in any module or source set, as long as you are using Kotlin 2.0.0 or newer, and Gradle 7.6 or newer.

However, when the resources are placed in another module then composeApp (I don't know whether it name or application plugin dependent) they are not generated

Affected platforms

To Reproduce Steps to reproduce the behavior:

  1. Download zip archive
  2. Click run Android app
  3. Navigate to App.kt and try to uncomment 36 line

Expected behavior The resources could be imported from another module

Screenshots

Screenshot 2024-05-25 at 22 01 59

Demo KotlinProject 2.zip

jcaiqueoliveira commented 1 month ago

I'm getting a similar problem but with fonts

Config:

compose-plugin = "1.6.10"
kotlin = "2.0.0"

jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" }

// res config:

compose.resources {
    publicResClass = true
    packageOfResClass = "sample.resources"
    generateResClass = always
}

Code to expose font:

@Composable
public fun workSans(): FontFamily {
    return FontFamily(Font(Res.font.worksans_default))
}
Caused by: java.lang.IllegalStateException: 
Unable to load font Font(assetManager, path=composeResources/sample.resources/font/worksans-default.ttf, weight=FontWeight(weight=400), style=Normal)
                                                                                                        at androidx.compose.ui.text.font.FontListFontFamilyTypefaceAdapterKt.firstImmediatelyAvailable(FontListFontFamilyTypefaceAdapter.kt:195)
                                                                                                        at androidx.compose.ui.text.font.FontListFontFamilyTypefaceAdapterKt.access$firstImmediatelyAvailable(FontListFontFamilyTypefaceAdapter.kt:1)
                                                                                                        at androidx.compose.ui.text.font.FontListFontFamilyTypefaceAdapter.resolve(FontListFontFamilyTypefaceAdapter.kt:133)
                                                                                                        at androidx.compose.ui.text.font.FontFamilyResolverImpl$resolve$result$1.invoke(FontFamilyResolver.kt:93)
                                                                                                        at androidx.compose.ui.text.font.FontFamilyResolverImpl$resolve$result$1.invoke(FontFamilyResolver.kt:92)
                                                                                                        at androidx.compose.ui.text.font.TypefaceRequestCache.runCached(FontFamilyResolver.kt:192)
                                                                                                        ... 131 more

Testproject.zip

Nek-12 commented 1 month ago

Guys, do you know is it possible to share resources between composeApp and server? I can't do it because it says my server module should be marked as multiplatform module (because resources module, that I apply to server module` should be also marked as multiplatform) - https://kotlinlang.slack.com/archives/C3PQML5NU/p1716676813612929

How is this related to the issue?

YoussefHachicha commented 1 month ago

same issue here using kotlin = "2.0.0" compose = "1.6.20-dev1646"

whenever I try to create a composeResources directory I only get suggested this which is the old impl

Screenshot 2024-05-26 at 11 08 03 AM
terrakok commented 1 month ago

@sereden you forgot about the src dir: move resources/commonMain -> resources/src/commonMain