https://kotlinlang.org logo
#android
Title
# android
m

Mahesh Kavathiya

06/28/2022, 5:32 AM
Hi Everyone, is it possible to change build flavour run time? I wanted to use common build for all environment and select flavour from menu, based on selection data will be updated which is available on each flavours like strings, drawable etc. Currently we are maintaining separate builds for DEV/SIT/UAT, but want to keep single build and QA can select flavours based on their requirement for testing. Any thought process on this? Thanks
🚫 2
g

gildor

06/28/2022, 5:34 AM
Flavours is just a way to separate different sources during compilation, so if you want to change on runtime, you should remove flavours completely and use runtime check, so you have some kind config and selecting all resources, code etc depending on this config
m

Mahesh Kavathiya

06/28/2022, 5:36 AM
Thanks Andrey for the reply, Yes I know this way we can achieve it, but do you know run time possible?
f

Francesc

06/28/2022, 5:47 AM
You can't change flavors at runtime because flavors are a compile time feature. The closest alternative I can think of would be on demand modules
m

Mahesh Kavathiya

06/28/2022, 5:52 AM
Thank you @Francesc for quick reply, will check with modules
g

gildor

06/28/2022, 6:16 AM
but do you know run time possible?
Yes, just include code/resources from all you flavors to a single flavor and select required on runtime
On Demand Modules could be very tricky, you need very good separation between parts of the app and what is worse, you need Google Play to even test it (so at least upload it to internal app sharing), so I don’t really think that it worth to look into only for testing My personal advice, do not bother with it, publish all available flavours of the app to your app distribution services, so QA can install them side by side and test. It a lot closer to what actually and less chance of mistake and many possible side effects of dynamic selection. Of course it really depends how different your different flavours, if it just let’s say, about API endpoints, it’s easy to do and you don’t really need flavours for this
m

Mahesh Kavathiya

06/28/2022, 7:16 AM
Got it, Thanks @gildor Well it's not just for API endpoints, there are many other resources to be handle based on flavour, Currently we already have published all flavour in app distribution
g

gildor

06/28/2022, 7:21 AM
if you have many resources, I wouldn’t bother with runtime selection in any way, because you will not only make your code more complex (which you don’t want to do if it’s not a product requirement, but just for testing), but also will fight with resource caching (you should never cache resources or even ids anywhere outside of activity, force recreate activity)
m

MR3Y

06/28/2022, 8:40 AM
I'm not sure if this solves your problem, but have you tried https://github.com/JakeWharton/ProcessPhoenix ? it allows for switching between different environments at runtime.
g

gildor

06/28/2022, 9:00 AM
It doesn’t allow to switch, it just allows to restart process
👍 1
m

MR3Y

06/28/2022, 9:07 AM
Oh, TIL. I thought it would help him but as I said above wasn't sure about that
45 Views