shadox
shadox

Reputation: 3769

Android gradle file for string constants generates wrong declaration

I'm trying to set BASE_URL for my services in my gradle script for different build types. When I'm trying to synchronize the script, it generates wrong String value.

My script

buildTypes {
    //... other build types
    debug {
        minifyEnabled false
        buildConfigField "String", "MHT_BASE_URL", "www.my-url.com"
    }
}

It generates the following BuildConfig

public final class BuildConfig {
    public static final boolean DEBUG = Boolean.parseBoolean("true");
    public static final String APPLICATION_ID = "com.myapp.app_dev";
    public static final String BUILD_TYPE = "debug";
    public static final String FLAVOR = "dev";
    public static final int VERSION_CODE = 6;
    public static final String VERSION_NAME = "0.5.1";
    // Fields from build type: debug
    public static final String BASE_URL = www.my-url.com;
}

But it should generate this string (with quotation marks!)

public static final String BASE_URL = "www.my-url.com";

I have a workaround for that but I'm searching for a right way to do it.

Upvotes: 0

Views: 243

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364516

You can use something like this:

 buildConfigField "String", "MHT_BASE_URL",  "\"www.my-url.com\""

or check the @CommonsWare answer with the single quote.

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1007359

You need to include the quotation marks in your Gradle script:

buildConfigField "String", "MHT_BASE_URL", '"www.my-url.com"'

Upvotes: 0

Related Questions