问题描述
我想将项目升级到Android Studio 3.0 Canary 1和gradle:3.0.0-alpha1插件,但是对于包含的项目,正确定义口味存在问题.
I would like to upgrade my project to Android Studio 3.0 Canary 1 and the gradle:3.0.0-alpha1 plugin, however I have a problem with the correct definition of flavors for included projects.
我遵循了Google的官方迁移指南: https ://developer.android.com/studio/preview/features/new-android-plugin-migration.html
I followed the official migration guide from Google: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html
在主应用程序build.gradle中,按照迁移指南的建议定义了"myflavor" flavorDimensions :
In my main app build.gradle I defined the "myflavor" flavorDimensions, as recommended by the migration guide:
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错误:
In my included :util module (producer), I tried to include it withouth a definition of flavorDimensions, productFlavors and buildTypes. I get the following gradle error:
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'.
在:util中定义与主:app中相同的flavourDimensions,productFlavors和buildTypes时,出现以下错误消息:
When defining the same flavorDimensions, productFlavors and buildTypes in :util as in the main :app, I get the following error message:
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的正确方法是什么?
What is the correct way to include my :util lib without getting the error?
推荐答案
似乎就像Gradle构建过程中的错误一样,我不太确定为什么它确实无法正常工作.我坚持了一段时间,但可以通过更改来解决
Seems like a bug in the Gradle build process, I'm not quite sure why exactly it's not working. I was stuck on this for a while but I was able to fix it by changing
compile project(':util')
到
compile project(path: ':util', configuration: 'default')
让我知道这是否对您有用!
Let me know if this works for you!
这篇关于flavourDimensions gradle错误-Android Studio 3.0 Canary 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!