Hello I am trying to use `"org.jetbrains.compose.c...
# multiplatform
f
Hello I am trying to use
"org.jetbrains.compose.components:components-resources:1.3.1-rc01"
to load images images via compose in common module, but the images are not loaded. More info in the thread.
image.png
I added the file logo.jpg in resoures dir of commonMain.
So, in code I added :
Copy code
Image(
    bitmap = resource("logo.jpg").rememberImageBitmap().orEmpty(),
    contentDescription = null
)
Image(
    painter = painterResource("logo.jpg"),
    contentDescription = null
)
The first
Image()
is not load the image and the second
Image()
crash the app with the following message:
Caused by: org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: logo.jpg
The resource is missing. What is the right path to put the resources???
j
Unfortunately common resources aren't automatically added to binary compilations. I've had to use a combination of symlinking for Android and Gradle copy tasks for JVM and native targets to copy common resources to the required bundle or runtime paths.
f
you can add the following instead of: android { sourceSets["main"].resources.srcDir("src/commonMain/resources") }
j
When I tried adding the common resources directory as a resource directory for the other source sets, IntelliJ or Android Studio throws a "duplicate content roots detected" error and removes it from the other source sets. This solution might work from the terminal, but not in the IDE, which is why I resorted to symlinking instead, as this causes the directory to appear as a unique path. There are several YouTrack issues about this error, but unfortunately it's a behavior that's deeply relied on for IDE functionality.
f
hmmmmm...here worked fine, but I have been tested just in android
j
Android is your only source set?
f
no, I have android and ios, but I tested just in android
sourceSets["main"].resources.srcDir("src/commonMain/resources")
if different of:
sourceSets["main"].res.srcDirs("src/androidMain/res", "src/commonMain/resources")
resources != res
so you need add the resources directory for the library work properly
j
Maybe that one case might work because of the difference between resources and res in Android? In my case I ended up symlinking
src/commonMain/resources
to
src/androidMain/resources/assets
, as I consume the common resources as Android assets in my Android
actual
implementations.
1215 Views