How do I get the icon to resolve? - I've confirmed...
# getting-started
s
How do I get the icon to resolve? - I've confirmed
ic_launcher_foreground.xml
exists. Specifically it's found at
composeApp/src/androidMain/res/drawable/ic_launcher_foreground.xml
s
You probably want to be using
R.drawable
, not
Res.drawable
. Make sure that the R file you're importing matches the module containing the resource.
s
I don't have
R
in Kotlin Multiplatform;
Res
is what I have.
p
There is 2 things mixed here. There is Android resources API and the CMP resources API. In commonMain you use
Res.drawable.mypng
. In androidMain I believe you can use both,
R.drawable.my_only_android_png
as traditionally, but you can also resolve
Res.drawable.cmp_png
although not advisable
To use the code you posted you have to place the resources under
commonMain/composeResources/drawable
directory. The directory in your screenshot is only accessible from androidMain and you should use
R
instead of
Res
if that is what you want.
s
Wait so how do I add an icon to my desktopMain? I target Android, iOS, web and desktop.
composeApp/src/desktopMain/kotlin/dev/myname/main.kt
what do I use here? - For
icon =
of
Window
?
Oh I see, so it's in
Copy code
composeApp/src/androidMain/res/drawable
composeApp/src/androidMain/res/drawable-v24
but it needs to be elsewhere. In Android Studio there are no
res
directories apart from the
androidMain
one; that aren't generated.
p
I quite don’t get what you want. If you want an icon for your desktop App or Android App. Each platform has a specific API to set the App icon. That is separate from compose and you should follow the proper API per platform. What I describe above was the API to access a drawable or any resource from composecode, lets say to display it on a screen. But is not related to the App icon.
s
Yes I already have `iconFile.set(rootProject.file("assets/icon.icns"))`for macOS,
iconFile.set(rootProject.file("assets/icon.ico"))
for Windows,
iconFile.set(rootProject.file("assets/icon.png"))
for Linux. My question is about how to access resources from
composeApp/src/desktopMain/kotlin/dev/myappname/main.kt
; what to put in
icon=
for my
org.jetbrains.compose.ui/ui-desktop/1.8.0-dev1890/c830ee7608c7e0c5d80489c58f3bdc74fe50f079/ui-desktop-1.8.0-dev1890-sources.jar!/desktopMain/androidx/compose/ui/window/Window.desktop.kt
. I don't seem to be able to access assets that I've imported. Elsewhere in my multiplatform code I use
Res.drawable
and it works.
p
Ok, perhaps is worth filing a bug. You will need a minimum reproducer public repo.
s
How do I get
Res.drawable.logo
to work? - I've been hacking around a bunch and now it looks like:
Copy code
% fd -Iexml logo
composeApp/src/debug/res/drawable/logo.xml
composeApp/src/androidMain/res/drawable/logo.xml
composeApp/src/release/res/drawable/logo.xml
composeApp/src/main/res/drawable/logo.xml
composeApp/build/intermediates/packaged_res/debug/packageDebugResources/drawable/logo.xml
composeApp/build/intermediates/packaged_res/release/packageReleaseResources/drawable/logo.xml
But I still can't
icon = painterResource(Res.drawable.logo)
p
You have to place the logo.png or logo.xml icon under:
commonMain/composeResources/drawable
s
Even after a direct
cp composeApp/src/debug/res/drawable/logo.xml composeApp/src/commonMain/composeResources/drawable
it doesn't resolve. Trying a bunch of
gradle
tasks now to see if any force generation
Oh weirdly specific errors about upgrading from Kotlin
2.0.20
to
2.0.21
and now it works. No errors, but also no non-default icon
Can this icon not be changed [macOS]?
p
Humm 🤔 I believe you can. WRT the other issues , like I said, if it persists worth opening an issue in GitHub or YuoTrack
s
Got a duplication error so removed all logo.xml files except the one in
composeApp/src/commonMain/composeResources/drawable
. Android logos all work now. iOS icon is default [at least in Simulator]. Web has no favicon but that's probably a different setting.
🎉 1
p
Yes the fav icon is platform specific
s
gratitude thank you 1
& thx for fixing my Android build
😸 1
👍 1