flavorDimensions gradle错误 – Android Studio 3.0 Canary 1

我想将我的项目升级到Android Studio 3.0 Canary 1和gradle:3.0.0-alpha1插件,但是我对包含项目的风味的正确定义有问题。

我遵循Google提供的官方迁移指南: https : //developer.android.com/studio/preview/features/new-android-plugin-migration.html

在我的主应用程序build.gradle中,我定义了“myflavor” flavorDimensions ,正如迁移指南所build议的那样:

android { flavorDimensions "myflavor" productFlavors { dev { dimension "myflavor" minSdkVersion 21 } prod { dimension "myflavor" minSdkVersion 16 } } buildTypes { debug { signingConfig signingConfigs.debug } release { debuggable false signingConfig signingConfigs.release minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } dependencies { compile project(':util') } 

在我的包括:util模块(生产者),我试图包括它没有flavorDimensions,productFlavors和buildTypes的定义。 我得到以下gradle错误:

 Error:Could not resolve all dependencies for configuration ':app:prodDebugCompileClasspath'. Cannot choose between the following configurations on project :util: - debugApiElements - releaseApiElements All of them match the consumer attributes: - Configuration 'debugApiElements': - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required. - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided. - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but wasn't required. - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required. - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided. - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'. - Configuration 'releaseApiElements': - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required. - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided. - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=release}' but wasn't required. - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required. - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided. - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'. 

当在main:app中定义与util相同的flavorDimensions,productFlavors和buildTypes时,会出现以下错误消息:

 Error:Could not resolve all dependencies for configuration ':app:prodDebugCompileClasspath'. Cannot choose between the following configurations on project :util: - devDebugApiElements - devReleaseApiElements - prodDebugApiElements - prodReleaseApiElements All of them match the consumer attributes: - Configuration 'devDebugApiElements': - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required. - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided. - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but wasn't required. - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=devDebug}' but wasn't required. - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided. - Found myflavor 'ProductFlavorAttr{name=dev}' but wasn't required. - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'. - Configuration 'devReleaseApiElements': - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required. - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided. - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=release}' but wasn't required. - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=devRelease}' but wasn't required. - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided. - Found myflavor 'ProductFlavorAttr{name=dev}' but wasn't required. - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'. - Configuration 'prodDebugApiElements': - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required. - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided. - Found com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but wasn't required. - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=prodDebug}' but wasn't required. - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided. - Found myflavor 'ProductFlavorAttr{name=prod}' but wasn't required. - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'. - Configuration 'prodReleaseApiElements': - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but no value provided. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' but wasn't required. - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=debug}' but no value provided. - Found com.android.build.gradle.internal.dependency. 'BuildTypeAttr{name=release}' but wasn't required. - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=prodRelease}' but wasn't required. - Required myflavor 'ProductFlavorAttr{name=prod}' but no value provided. - Found myflavor 'ProductFlavorAttr{name=prod}' but wasn't required. - Required org.gradle.api.attributes.Usage 'for compile' and found compatible value 'for compile'. 

包含我的:util lib没有得到错误的正确方法是什么?

Solutions Collecting From Web of "flavorDimensions gradle错误 – Android Studio 3.0 Canary 1"

看起来像在Gradle构build过程中的错误,我不太清楚为什么它不工作。 我被困在这一段时间,但我能够通过改变来解决它

 compile project(':util') 

 compile project(path: ':util', configuration: 'default') 

让我知道这是否适合你!

我有一个类似的问题使用加那利2,但提出的解决scheme没有奏效。 显然有一种方法可以使用本地库或项目的实现:

 // This is the old method and no longer works for local // library modules: // debugCompile project(path: ':foo', configuration: 'debug') // releaseCompile project(path: ':foo', configuration: 'release') // Instead, simply use the following to take advantage of // variant-aware dependency resolution. You can learn more about // the 'implementation' configuration in the section about // new dependency configurations. implementation project(':foo') 

Studio文档的参考 。

https://issuetracker.google.com/issues/65867056

根build.gradle中应该只有一个buildScript块。 如果您使用Composite构build,由于Gradle中的限制,我们的插件目前不支持这种构build。

我通过使用gradle 4.3(与Android Studio 3.0)

要在Android Studio 3.0中使用它:

  1. 在这里下载二进制文件: https : //gradle.org/releases/
  2. 在Android Studio中configuration本地gradle二进制文件

在这里输入图像说明

  1. 然后在您的gradle文件中,取决于您的要求,使用实现APIreplace编译

参考: https : //developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

另外:确保您的外部模块(即util)具有与您的应用程序相同的风味,否则您将得到在这里概述的错误: Gradle 4.0无法find匹配的configuration