我在Android Studio 3.1.1上使用Gradle 4.4和Gradle-Android插件3.1.1。
我有2种口味'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.
app 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'
}
base-feature 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"
}
到目前为止,我尝试了以下解决方案,但没有运气:
AS 3.0 test-only module Cannot choose between the following configurations of project :abcMobile:
Single flavor module based on multi flavor library in Gradle
Android Studio 3.0 Error. Migrate dependency configurations for local modules
修改:
根据评论和一个答案,我尝试给两种口味提供不同的applicationIdSuffix
,但问题仍然存在:
productFlavors{
a{
applicationIdSuffix ".a"
dimension "dim"
}
b{
applicationIdSuffix ".b"
dimension "dim"
}
}
答案 0 :(得分:1)
感谢用户TWL向我指出google samples for instant apps, with an example for flavors。
我们还需要在所有功能模块,应用程序模块和即时应用程序模块中使用flavor声明。截至今天,可以使用插件版本3.1.1跳过库模块。换句话说,将此部分包含在所有功能和已安装/即时模块中:
flavorDimensions "dim"
productFlavors{
a{
dimension "dim"
}
b{
dimension "dim"
}
}
答案 1 :(得分:1)
首先,您不必在模块中具有匹配的口味。您可以告诉它回退到默认的构建类型。
通过使用matchingFallbacks
buildTypes {
aDebug {
testCoverageEnabled true
matchingFallbacks = ['debug']
}
bDebug {
testCoverageEnabled true
matchingFallbacks = ['debug']
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// This one already looks for 'release' which is added by default, so no need for fallback
}
}
https://developer.android.com/studio/build/dependencies#resolve_matching_errors
答案 2 :(得分:0)
您似乎没有指定a
和b
包名称的差异。以下是我在 AS 2.3.3的flavor
级别com.android.tools.build:gradle:2.3.1
中针对API 25的app
功能以及build.gradle
的工作实施< /强>:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.00"
}
signingConfigs {
config {
storeFile file(STORE_PATH)
keyAlias KEY_ALIAS
keyPassword KEY_PASSWORD
storePassword KEYSTORE_PASSWORD
}
}
productFlavors {
nosync {
applicationIdSuffix ".nosync"
versionNameSuffix '-nosync'
signingConfig signingConfigs.config
}
sync {
signingConfig signingConfigs.config
}
}
buildTypes {
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
signingConfig signingConfigs.config
}
}
dependencies {
...
}
看一下差异
applicationIdSuffix ".nosync"
versionNameSuffix '-nosync'
介于nosync
和sync
之间。它会更改nosync
apk
的包名称。