我正在使用Android Studio 3.1.1,Gradle版本为4.4,Gradle-Android插件版本为3.1.1。
我的项目中有两个渠道,分别为'a'和'b',但是由于以下错误,我无法构建项目:
Cannot choose between the following configurations of project :app:
- aDebugMetadataElements
- bDebugMetadataElements
All of them match the consumer attributes:
- Configuration 'aDebugMetadataElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'aDebug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Metadata' and found compatible value 'Metadata'.
- Found dim 'a' but wasn't required.
- Configuration 'bDebugMetadataElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'bDebug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Metadata' and found compatible value 'Metadata'.
- Found dim 'b' but wasn't required.
应用构建文件build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "me.xyz.flavors"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug{
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "dim"
productFlavors{
a{
dimension "dim"
}
b{
dimension "dim"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':base')
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
基础特性 build.gradle:
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
baseFeature true
defaultConfig {
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
aDebug {
testCoverageEnabled true
}
bDebug {
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
application project(':app')
api 'com.android.support:appcompat-v7:27.1.1'
api 'com.android.support.constraint:constraint-layout:1.0.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
api "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
到目前为止,我已经尝试了以下解决方案,但都没有成功:
编辑:
根据评论和一个答案,我尝试为两个味道提供不同的applicationIdSuffix
,但问题仍然存在:
productFlavors{
a{
applicationIdSuffix ".a"
dimension "dim"
}
b{
applicationIdSuffix ".b"
dimension "dim"
}
}