热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

flavorDimensionsgradle错误-AndroidStudio3.0Canary1

如何解决《flavorDimensionsgradle错误-AndroidStudio3.0Canary1》经验,为你挑选了2个好方法。

我想将我的项目升级到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:

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')
}

在我的included: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中定义相同的flavorDimensions,productFlavors和buildTypes:util时,我收到以下错误消息:

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'.

包含my:util lib的正确方法是什么,而不会出现错误?



1> 小智..:

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

compile project(':util')

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

如果这对您有用,请告诉我!



2> amouly..:

我有一个类似的问题使用Canary 2,但建议的解决方案不起作用.显然有一种方法可以使用本地库或项目中的实现:

// 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文档中的参考.


推荐阅读
author-avatar
DalianLiLing_143
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有