Hi Everyone, is it possible to change build flavou...
# android
m
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
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
Thanks Andrey for the reply, Yes I know this way we can achieve it, but do you know run time possible?
f
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
Thank you @Francesc for quick reply, will check with modules
g
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
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
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
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
It doesn’t allow to switch, it just allows to restart process
đź‘Ť 1
m
Oh, TIL. I thought it would help him but as I said above wasn't sure about that