icerockdev / moko-resources

Resources access for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.03k stars 117 forks source link

Handle different build flavors resources #742

Open ahmedsalemelzeiny opened 5 days ago

ahmedsalemelzeiny commented 5 days ago

Hi, I'm developing a new Compose app with multiple flavors, and each flavor may require different values for strings, images, or assets.

How can I manage this using Moko-Resources?

Alex009 commented 5 days ago

hello. different flavors exist only on android, so you cant use this feature in multiplatform module. but i think you can reimplement it with different gradle modules.

android-app
ios-app
shared
shared-flavor-1
shared-flavor-2

shared-flavor-1, shared-flavor-2 declare api dependency to shared

android-app can be configured with android build-flavors and declare dependency like: flavor1Implementation(shared-flavor-1) flavor2Implementation(shared-flavor-2) implementation(shared)

in ios-app you can use separated targets - flavor1App, flavor2App. that will use two different frameworks - from shared-flavor-1 and shared-flavor-2.

in code you should use dependency inversion to provide flavor-specific resources from shared-flavor-1/shared-flavor-2 to shared

it's not so simple as with android flavors, but in this case you have quarantee that used resources really exist in specific build variant