Let's say I have one string I would like to change depending on my build type and flavor. What would be the best way to accomplish that?
I've created the following folder structure:
app/src/main/
app/src/flavor1/
app/src/flavor2/
app/src/main/res/values/my_strings.xml
app/src/flavor1/res/values/my_strings.xml
app/src/flavor2/res/values/my_strings.xml
This all works when I just want different string for each flavor. Now I would also like to separate those string by build type so I've done something like this:
app/src/main/
app/src/flavor1/
app/src/flavor2/
app/src/flavor1Release/
app/src/flavor2Release/
The problem which appears now is that if I want to create values
folder inside app/src/flavor1Release/res
, I receive the message that values
folder already exists. How can I go around this issue?
You use same core ingredients to make the base but will use different toppings for each one to have a different taste. Similarly, android apps can have the same base functionalities with changes to some of the features like styles, logo etc. This can be achieved using product flavours.
Build Type applies different build and packaging settings. An example of build types are “Debug” and “Release”. Product Flavors specify different features and device requirements, such as custom source code, resources, and minimum API levels.
BuildConfig.FLAVOR gives you combined product flavor. So if you have only one flavor dimension: productFlavors { normal { } admin { } } Then you can just check it: if (BuildConfig. FLAVOR.
Once the new project is created, by default it consists of two build types/variants - debug, release. Debug is the build type that is used when we run the application from the IDE directly onto a device. A release is the build type that requires you to sign the APK.
You must do something like this :
app/src/main/
app/src/flavor1Debug/
app/src/flavor2Debug/
app/src/flavor1Release/
app/src/flavor2Release/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With