本文介紹了如何生成字符串類型的 buildConfigField的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在我的 Android Studio
項目中有兩個 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'
}
}
我得到如下錯誤:
/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;
}
我認為 APP_VERSION
和 SERVER_URL
沒有正確生成,因為它們是沒有引號的字符串類型.
I think the APP_VERSION
and SERVER_URL
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 escaped quotes additionally.
這篇關于如何生成字符串類型的 buildConfigField的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!