Hi everyone, I'm facing this issue, but I've not f...
# multiplatform
e
Hi everyone, I'm facing this issue, but I've not found a good solution to that:
Copy code
/Users/ctrltech/StudioProjects/Tmaterials/shared/src/commonMain/kotlin/com/geekpastor/shared/ui/components/singleComponents/AppBar.kt:67:35 Unresolved reference 'painterResource'.
As you can see, it's happening in commonMain module, and I've tried to find a multiplatform library for resources, but it seems to not be stable each time I have tried to install it, it causes other issues. Doo you have ay other solutions that you could suggest me???
p
Something might be wrong with your setup or configuration? I'm using
painterResource
with no issues at all at
commonMain
, this is my import:
Copy code
import org.jetbrains.compose.resources.painterResource
e
What have you installed as a library?
p
Copy code
compose-multiplatform = "1.8.2"


composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" }
e
I've already installed it, so the only thing I've to do is to import it, isn't it???
Should I install composeMultiplatform as a plugin or a library???
p
Yeah I've also installed that plugin, and created a multiplatform project via Android Studio which also pre-installed a lot of things.
a
You also need to setup the multiplatform resources if that's not already the case, see https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-multiplatform-resources-setup.html
e
https://kotlinlang.slack.com/archives/C3PQML5NU/p1751552200137379?thread_ts=1751543801.440209&cid=C3PQML5NU My plugin, either for IntelliJ or Android Studio, looks like this. Is it the right one???
p
Yes that looks correct I think
e
okay...
thks...
So now i'm trying to install the composeResources library
That is the result I get after installing all things
Copy code
Image(
    modifier = Modifier
        .fillMaxWidth(0.4f)
        .fillMaxHeight(),
    painter = painterResource(id = Res.drawable.ic_launcher_foreground),
    contentDescription = "Logo de l'application",
    contentScale = ContentScale.Crop
)
Unresolved reference 'Res'.
a
If you cannot import Res, try adding this in your build.gradle.kts:
Copy code
compose.resources {
    publicResClass = true
    packageOfResClass = "your.package.name.resources"
    generateResClass = always
}
Then you should be able to import it with:
Copy code
import your.package.name.resources.Res
See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-multiplatform-resources-usage.html#customizing-accessor-class-generation for details. Also, you're using the wrong
painterResource
, you should import the one from compose multiplatform:
Copy code
import org.jetbrains.compose.resources.painterResource
which takes a
resource
as parameter, not an
id
.