我正在努力使一个大型项目模块化。我已经分离了代码和布局文件,除了一个问题,一切正常。
我需要在模块中创建3种构建类型,即beta,stage和live(由于后面提到的原因)。现在有一件事我无法理解。
必须有一些
我在库模块中创建构建变体的原因是我在模块中使用Content Provider,并且在同一设备中同时安装多个构建类型时出现CONTENT_PROVIDER_AUTHORITY_CONFLICT错误。
因此,为了同时安装beta版,阶段版和实时版,我将内容机构添加为build.gradle中的字符串资源
apply plugin: 'com.android.library'
android {
compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION)
buildToolsVersion project.BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.TARGET_SDK_VERSION)
vectorDrawables.useSupportLibrary true
}
buildTypes {
beta {
minifyEnabled false
resValue("string", "account_type", "com.****.****.dev")
resValue("string", "_authority", "com.****.****.dev.syncadapter.finance")
buildConfigField "String", "FinanceContentProvider", "\"com.****.****.dev.syncadapter.finance\""
}
staging {
minifyEnabled false
resValue("string", "account_type", "com.****.****.stage")
resValue("string", "_authority", "com.****.****.stage.syncadapter.finance")
buildConfigField "String", "FinanceContentProvider", "\"com.****.****.stage.syncadapter.finance\""
}
live {
minifyEnabled false
resValue("string", "account_type", "com.****.****.live")
resValue("string", "_authority", "com.****.****.live.syncadapter.finance")
buildConfigField "String", "FinanceContentProvider", "\"com.****.****.syncadapter.finance\""
答案 0 :(得分:0)
您需要使用以下构建类型:
flavorDimensions 'tier'
productFlavors {
beta {
buildConfigField("Your_field", "Data", "Data")
}
staging {
buildConfigField("Your_field", "Data", "Data")
}
live {
buildConfigField("Your_field", "Data", "Data")
}
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "AppName_${variant.productFlavors[0].name}-${buildType.name}-${defaultConfig.versionCode}.apk"
}
}
}
希望这有帮助。