如何生成字符串类型的 buildConfigField
- 作者: 久伴我者必永驻我34693861
- 来源: 51数据库
- 2022-10-26
问题描述
在我的 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.
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
