Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different string resources for different flavor build types

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?

like image 980
user4386126 Avatar asked Jan 22 '16 19:01

user4386126


People also ask

When would you use product flavor in your build setup?

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.

What is a build type and a product flavor in android?

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.

What is BuildConfig flavor?

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.

What are build types in android?

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.


1 Answers

You must do something like this :

app/src/main/
app/src/flavor1Debug/
app/src/flavor2Debug/
app/src/flavor1Release/
app/src/flavor2Release/
like image 135
ben75 Avatar answered Oct 26 '22 19:10

ben75