In a classic KMP project, is there any easy way to...
# multiplatform
r
In a classic KMP project, is there any easy way to have separate debug resources for the Android target? Specifically without duplicating the
androidMain
variant since it already contains the Android-specific code. (I guess you would need to add yet another shared module for android, but I wonder if someone has done it somewhere) My usecase is just to have a separate debug variant app icon and app name string.
โž• 1
s
I'd like to know if there's way too. I always have a separate icon for debug builds and this would be super useful (but also in general, would like to know how Android build flavors and variants play with KMP)
๐Ÿ‘ 1
One idea is to just use KMP modules and make them depend on
androidMain
(e.g.
androidRelease
and
androidDebug
), but I'm not sure if and how would that work with resources, and I'm not very fond of the extra directories either.
๐Ÿ‘ 1
r
Yeah, that was my thinking also, but it seems overkill for just having an override for an icon and a string...
๐Ÿ‘ 1
j
If its just for icon, I created my own Kotlin dsl inject resources by environment. So not even need to be part of build type. Did it to avoid flavors. You can merge external resource folders with the one used by Android app. I also using same method to inject google play services json.
r
For now, I just used manifest placeholders for the app name which works fine enough.
s
@Joel Denke that's interesting, can you share more details about that?
@Rok Oblak would you mind sharing how that works? I'm not sure I understand what "placeholders" mean here
r
I set a manifest placeholder for
appName
. Then I set this custom string in my build.gradle.kts in the android { defaultConfig {
Copy code
manifestPlaceholders["appName"] = "DEBUG_NAME"
and then in buildTypes { release ... I can override it just for android release build type:
Copy code
manifestPlaceholders["appName"] = "RELEASE_NAME"
โค๏ธ 1
And you can do the same for app icon, though I haven't done it yet
๐Ÿ‘ 1
s
Didn't know about
manifestPlaceholders
, that's very neat, thanks for sharing!
๐Ÿ‘ 1
j
๐Ÿ™ 1
Also its possible create a custom Gradle task that just download and/or copy files from disk to certain place coupled into Android compile loop. I use that for copy google play services json.
๐Ÿ‘ 1