5

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?

Liru
  • 311
  • 1
  • 4
  • 10

2 Answers2

2

You need to select your build variant in the window normally found at the bottom-left of android studio: enter image description here

leonardkraemer
  • 6,573
  • 1
  • 31
  • 54
1

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 {
...
}
Sagar
  • 23,903
  • 4
  • 62
  • 62