我想将我的项目升级到Android Studio 3.0 Canary 1和gradle:3.0.0-alpha1插件,但是我在为包含的项目定义正确的flavors方面遇到了问题。
我按照Google官方迁移指南进行操作:https://developer.android.com/studio/preview/features/new-android-plugin-migration.html 在我的主要app build.gradle中,我按照迁移指南的建议定义了“myflavor” flavorDimensions。
在我的包含的:util模块(生产者)中,我尝试在没有定义flavorDimensions、productFlavors和buildTypes的情况下进行包含。我得到了以下Gradle错误:
在util模块中定义与app主模块中相同的flavorDimensions、productFlavors和buildTypes时,会出现以下错误信息:
什么是在不出错的情况下包含我的 :util 库的正确方法?
我按照Google官方迁移指南进行操作:https://developer.android.com/studio/preview/features/new-android-plugin-migration.html 在我的主要app build.gradle中,我按照迁移指南的建议定义了“myflavor” flavorDimensions。
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'.
在util模块中定义与app主模块中相同的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 库的正确方法?