Abdullah Abdullah - 6 months ago 51
Android Question

How to generate buildConfigField with String type

In my

Android Studio
project there are two
build configuration
with some

buildTypes {

debug {
buildConfigField "String", SERVER_URL, "http://dev.myserver.com"
buildConfigField "String", APP_VERSION, "0.0.1"

release {
buildConfigField "String", SERVER_URL, "https://myserver.com"
buildConfigField "String", APP_VERSION, "0.0.1"

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

I am getting and error as follows:

Error:(14, 47) error: ';' expected
Error:(15, 47) error: ';' expected

the generated BuildCofig.java is as follows:

public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.mycuteoffice.mcoapp";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
// Fields from build type: debug
public static final String APP_VERSION = 0.0.1;
public static final String SERVER_URL = http://dev.mycuteoffice.com;

I think the
are not getting generated properly as being String type they do not have quotes.

I am not sure why it is being generated in such a way. Please let me know how can I resolve this issues.


String type build config fields should be declared like this:

buildConfigField "String", "SERVER_URL", "\"http://dev.myserver.com\""

the field name in quotes, the field value in mirrored quotes additionally.