問題描述
在我的 Android Studio
項(xiàng)目中有兩個(gè) build configuration
和一些 buildConfigField
:
In my Android Studio
project there are two build configuration
with some buildConfigField
:
buildTypes {
def SERVER_URL = "SERVER_URL"
def APP_VERSION = "APP_VERSION"
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'
}
}
我得到如下錯(cuò)誤:
/path/to/generated/BuildConfig.java
Error:(14, 47) error: ';' expected
Error:(15, 47) error: ';' expected
生成的BuildConfig.java
如下:
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;
}
我認(rèn)為 APP_VERSION
和 SERVER_URL
沒有正確生成,因?yàn)樗鼈兪菦]有引號的字符串類型.
I think the APP_VERSION
and SERVER_URL
are not getting generated properly as being String type they do not have quotes.
我不確定為什么會(huì)以這種方式生成它.請讓我知道如何解決此問題.
I am not sure why it is being generated in such a way. Please let me know how can I resolve this issues.
推薦答案
字符串類型的構(gòu)建配置字段應(yīng)該這樣聲明:
String type build config fields should be declared like this:
buildConfigField "String", "SERVER_URL", ""http://dev.myserver.com""
引號中的字段名稱,轉(zhuǎn)義引號中的字段值.
the field name in quotes, the field value in escaped quotes additionally.
這篇關(guān)于如何生成字符串類型的 buildConfigField的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!