无法在多口味应用中构建功能模块 [英] Unable to build feature modules in a multi-flavor app
问题描述
我在Android Studio 3.1.1上将Gradle 4.4与Gradle-Android插件3.1.1一起使用
I am using Gradle 4.4 with Gradle-Android plugin 3.1.1 on Android Studio 3.1.1.
我有两种口味'a'和'b',由于以下错误,我无法构建我的项目:
I have 2 flavors 'a' and 'b' and I am unable to build my project due to the following error:
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.
应用程序构建.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"
}
到目前为止,我还没有运气尝试过以下解决方案:
I have tried the following solutions thus far with no luck:
-
Android Studio 3.0错误.迁移本地模块的依赖项配置
编辑:
根据评论和一个答案,我尝试为两种口味都提供不同的
applicationIdSuffix
,但问题仍然存在:Based on the comments and one answer, I tried giving a different
applicationIdSuffix
to both flavors, but the problem persists:productFlavors{ a{ applicationIdSuffix ".a" dimension "dim" } b{ applicationIdSuffix ".b" dimension "dim" } }
推荐答案
感谢用户 TWL 向我指出了用于即时应用的Google示例,并带有示例.
Thanks to user TWL who pointed me towards google samples for instant apps, with an example for flavors.
我们还需要在所有功能模块,应用程序模块和Instant-app模块中进行味道声明.从今天起,使用插件版本3.1.1可以跳过库模块.换句话说,在所有功能模块和已安装/即时模块中都有此部分:
We need flavor declarations in all the feature modules, application module and instant-app module as well. Library modules can be skipped as of today with plugin version 3.1.1. In other words, have this section in all feature and installed/instant modules:
flavorDimensions "dim" productFlavors{ a{ dimension "dim" } b{ dimension "dim" } }
这篇关于无法在多口味应用中构建功能模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!