在我的项目中Android Studio有两个:build configuration``buildConfigField
Android Studio
build configuration``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如下:
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_VERSIONandSERVER_URL没有正确生成为 String 类型,它们没有引号。
APP_VERSION
SERVER_URL
我不确定为什么它会以这种方式生成。请让我知道如何解决此问题。
字符串类型构建配置字段应该这样声明:
buildConfigField "String", "SERVER_URL", "\"http://dev.myserver.com\""
引号中的字段名称,转义引号中的字段值。