在我的 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模板网!
更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 IncompIncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 Incompatible
如何在 gradle 中获取当前风味How to get current flavor in gradle(如何在 gradle 中获取当前风味)
如何修复“意外元素<查询>在“清单How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修复“意外元素lt;查询gt;在“清单中找到错误
基于 Android Gradle 中多风味库的多风味应用Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多风味库的多风味应用)
Android 依赖在编译和运行时有不同的版本Android dependency has different version for the compile and runtime(Android 依赖在编译和运行时有不同的版本)
本地 aar 库的传递依赖Transitive dependencies for local aar library(本地 aar 库的传递依赖)