androidbuildconfigandroid-flavors

android BuildConfig.BUILD_TYPE always in release status


I am implementing a new functionality that depending on whether the application is running, debug or release, choose between two url.

This is the code that I use insidel gradle to choose which url use ->

Code in side gradle

In the line below, is where I want to get the correct url, but when I'm debbuging with build variants in debug, the code returns me release url.

Line of code to get url -> Code get url

Url that I get -> URL Image

Check BuildConfig.BUILD_TYPE ->

BuildConfig

I'm getting release mode, why? Doing some research in BUILD_TYPE I found diferents BuildConfig which two of them have the BUILD_TYPE in release ->

Release Mode

And the only diference between them was this -> The ones that has BUILD_TYPE = "debug" have DEBUG like this ->

Build Type

The BUILD_TYPE = "release" have DEBUG like this ->

DEBUG Image

How can I change the ones that are in release to debug? Knowing that BuildConfig class is generated alone?


Solution

  • Following works for me:

    android {
    ...
        applicationVariants.all { variant ->
    
            if (variant.getName() == "release") {
                variant.buildConfigField "String", "URL_SEND_EMAIL", "\"https://www.google.com\""
            } else {
                variant.buildConfigField "String", "URL_SEND_EMAIL", "\"https://www.gmail.com\""
            }
        }
    }
    dependencies {
    ...
    }