Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android separate string values for release and debug builds

Every time i release my app i change all my url strings and some keys from testing to production. The way I do it is just comment out the testing strings before i release. Is there a better way to handle strings based on the build type ?

like image 779
spaceMonkey Avatar asked Mar 16 '16 15:03

spaceMonkey


People also ask

What is missingDimensionStrategy?

TL;DR: If a library module includes a flavor dimension that the app flavor does not, then use missingDimensionStrategy to specify default flavors from the missing dimension. More generally, you can use this any time a consumed module includes a flavor that the consumer module does not.

What is buildType in Gradle android?

Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle.

What is BuildConfigField?

BuildConfigField. Gradle allows buildConfigField lines to define constants. These constants will be accessible at runtime as static fields of the BuildConfig class. This can be used to create flavors by defining all fields within the defaultConfig block, then overriding them for individual build flavors as needed.


1 Answers

Assuming you use Android Studio, by default the system creates a basic release and debug flavor. So if you add a debug and release folder in the app/src folder of your project you can declare separate values there.

So your structure should be like this:

project   -app     -src       -debug         -java           ...         -res           -values             -strings.xml       -release         -java           ...         -res           -values             -strings.xml       -main         -java           ...         -res           -values             -strings.xml 

I should also add that if you have a string which isn't defined in either of the debug or the release folder that it will fallback to your main folder.

like image 50
Jasper van de Klundert Avatar answered Sep 22 '22 11:09

Jasper van de Klundert