Error:Could not resolve all dependencies for configuration ':app:prodDebugCompileClasspath'. Cannot

Join Stack Overflow to learn, share knowledge, and build your career.

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.

I followed the official migration guide from Google: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html

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

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

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

What is the correct way to include my :util lib without getting the error?

share improve this question
 
 
Same problem here –  Santacrab  May 25 at 10:28

4 Answers

up vote 55 down vote accepted

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

to

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

Let me know if this works for you!

share improve this answer
 
 
Perfect! Thank you @Moez for your help. Works like a charm :-) Best regards –  Devdroid  May 26 at 21:32
 
thx for your answer –  vlasevich  Jul 13 at 13:41
 
This bug is not fixed yet as of gradle-4.1-rc-1-all and gradle plugin 3.0.0-beta2. Took more than an hour figuring this out.. Thanks!! –  CoderSpinoza  Aug 31 at 9:12
 
while this works, it somehow prevents the transitive dependencies of utils to be exported so my build fails a bit further –  mbonnin  Sep 18 at 16:13
 
I filed a comment there: issuetracker.google.com/issues/65867056 –  mbonnin  Sep 19 at 8:29

I had a similar issue using Canary 2, but the proposed solution didn't work. Apparently there is a way to use the implementation from a Local library or project:

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

Reference from Studio Documentation.

share improve this answer
 
 
what about flavors here? –  Stefan Sprenger  Nov 5 at 20:27

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

You should have only one buildScript block in the root build.gradle. If you are using Composite builds, this is not currently supported by our plugin due to limitations in Gradle.

share improve this answer
 

I got around this by using gradle 4.3 (with Android Studio 3.0)

To use it with Android Studio 3.0:

  1. Download the binary here: https://gradle.org/releases/
  2. Configure local gradle binary in Android Studio, under preferences...

enter image description here

  1. Then in your gradle file replace compile with either implementation or api depending on your requirements.

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

ALSO: make sure that your external modules (i.e util) have the same flavors as your App or you will get the error outlined in here: Gradle 4.0 Unable to find a matching configuration

share improve this answer
 

Your Answer

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值