Is it possible to provide different build variants...
# multiplatform
a
Is it possible to provide different build variants for a multiplatform app? I want to be able to run my
commonMain
with debug, regress and release modes, but I can’t find any information on how to manage this. I can add BuildKonfig and manage the necessary settings using “flavors”, but is there a simpler way to accomplish this?
h
Build types and flavors are Android thing only afaik
p
You can have an Abstract AssetsManager that will be implemented by the actual module/library that will provide specific assets. Then you decide which module implementation to use in the build.gradle scripts according to the build parameters. This approach is better, my experience with variants+flavors in big projects is that it doesn't scale well. Simple case, a project split into 20 modules and each module has 3 variants . That is a hell to maintain. And that's only 3 variants, the moment it starts fragmenting even more it gets worse.
🙌 1
f
Can you share any examples?
of such an assetManager.
p
TBH I don't have a specific example in my personal repos. Also I haven't tried this approach to multiplatform yet. My experience above is mainly working in companies and using pure Android. It sounds good to perhaps create an example in Multiplatform. Don't promise anything but if I have the time I will share it here.
In general it is easy, just declare an interface ResourceProvider/AssetsProvider/AssetsManager ... you name it. Then for instance, create 3 modules. flavor-a, flavor-b, flavor-c. Inside flavor-a the AssetsManagerImplementation will return the assets or implementations pertaining to flavor a product. Same with the other flavors. Then In your
build.gradle
Something like:
Copy code
val flavor = findProperty("build-flavor")
if(flavor == flavor-a) {
  implementation ("com.mycompany: assets-flavor-a:1.0.0")
} else if (flavor == flavor-b) {
  implementation ("com.mycompany: assets-flavor-b:1.0.0")
} else ...
I haven't tried multiplatform, perhaps there might be limitations to this approach although I don't see any. I will find out
f
And where you defined "build-flavor" property?
p
It will depend on your pipeline setup. You could provide it through command parameters. Some projects before build, download a build-config.json from the server and place in the App directory and gradle uses it from it. Pipeline vendors provide ways of providing Gradle properties too. Is many ways
132 Views