Versions of constants according to BuildType

0

I have some constants which I would like to vary according to BuildType of Gradle. Among them are the URL's of the API's that I use in my app, which can be of production, homologation and development. For example:

  

link and link

I've read documentation , and now I've tried solutions from here and from here . But none worked.

What is the correct configuration of 'build.gradle' so I do not have to manually change my constants according to the environment.

    
asked by anonymous 11.02.2014 / 02:30

2 answers

1

Both the instructions on documentation when the solutions in the posts I mentioned work perfectly.

The problem is that Android Studio seems to have a bug, because it recognizes only the BuildType classes that are active giving the impression that the other packages are in error.

You need to use the Build Variant window and select the version you want to work on right now so they can recognize classes and packages.

PS: I discovered this bug thanks to link indicated by @NetoMarin, but there is no need to use Flavors for such a simple task.

    
11.02.2014 / 13:47
0

You will need to create different files for each set of values of the constants you want to use. And, there, create tasks that will select the file at the right time.

This is done through the productFlavors configuration, and there you indicate which for production and testing, for example.
Then on the Android Studio Build Variants tab to switch between settings.

In this blog post you will find a explanation even with images.

    
11.02.2014 / 03:54