如何使用String类型生成buildConfigField [英] How to generate buildConfigField with String type
本文介绍了如何使用String类型生成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
不能正确生成,因为它们是String类型,没有引号.
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.
这篇关于如何使用String类型生成buildConfigField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文