Home > Net >  "Could not resolve all task dependencies for configuration" with two dimensions, despite h
"Could not resolve all task dependencies for configuration" with two dimensions, despite h

Time:03-01

I know this is a commonly asked question, but nothing seems to apply to this problem.

I have an Android project and a bunch of libraries it depends on. The project has a dimension, "env", which can be "mock", "debug", "release". The library has the same dimension, but only "debug" or "release". "mock" has a fallback on "debug".

Here's a simplified setup:

App's build.gradle:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        coreLibraryDesugaringEnabled true
    }
    buildTypes {
        release {
        }
        staging {
            matchingFallbacks = ['debug']
        }
        debug {
        }
    }
    flavorDimensions 'env'

    productFlavors {
        mock {
            dimension 'env'
            matchingFallbacks = ['dev']
        }
        dev {
            dimension 'env'
        }
        prod {
            dimension 'env'
        }
    }
    sourceSets {
        dev {
            java.srcDirs = ['src/main/java', 'src/live/java', 'src/dev/java']
        }
        staging {
            java.srcDirs = ['src/main/java', 'src/live/java', 'src/staging/java']
        }
        prod {
            java.srcDirs = ['src/main/java', 'src/live/java', 'src/prod/java']
        }
        androidTest {
            java.srcDirs = ['src/main/java', 'src/mock/java', 'src/androidTest/java']
        }
        androidTestMockDebug {
            java.srcDirs = ['src/main/java', 'src/mock/java', 'src/androidTest/java']
        }
    }
dependencies {
    implementation project(path: ':myLibrary:myLibrary')

The library is in the subdirectory myLibrary/myLibrary, there's also a myLibrary/sample that I don't want to include in the app.

Library's build.gradle:

android {
    buildTypes {
        debug {
        }
        release {
        }
    }

    flavorDimensions 'env'

    productFlavors {
        dev {
            dimension 'env'
        }
        prod {
            dimension 'env'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

I'm getting this error when I try to build something as mockDebug (this is an excerpt, the full error is very long):

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':myApp:hiltJavaCompileMockDebug'.
> Could not resolve all task dependencies for configuration ':myApp:hiltCompileOnlyMockDebug'.
   > Could not resolve project :myLibrary:myLibrary.
     Required by:
         project :myApp
      > No matching variant of project :myLibrary:myLibrary was found. The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'env' with value 'mock' but:
          - Variant 'devDebugApiElements' capability myApp.myLibrary:myLibrary:unspecified declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Incompatible because this component declares an API of a component, as well as attribute 'env' with value 'dev' and the consumer needed a runtime of a component, as well as attribute 'env' with value 'mock'
          - Variant 'devDebugRuntimeElements' capability myApp.myLibrary:myLibrary:unspecified declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Incompatible because this component declares a component, as well as attribute 'env' with value 'dev' and the consumer needed a component, as well as attribute 'env' with value 'mock'
          - Variant 'devReleaseApiElements' capability myApp.myLibrary:myLibrary:unspecified:
              - Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'env' with value 'dev' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'env' with value 'mock'
          - Variant 'devReleaseRuntimeElements' capability myApp.myLibrary:myLibrary:unspecified declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'env' with value 'dev' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'env' with value 'mock'
          - Variant 'prodDebugApiElements' capability myApp.myLibrary:myLibrary:unspecified declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Incompatible because this component declares an API of a component, as well as attribute 'env' with value 'prod' and the consumer needed a runtime of a component, as well as attribute 'env' with value 'mock'
          - Variant 'prodDebugRuntimeElements' capability myApp.myLibrary:myLibrary:unspecified declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Incompatible because this component declares a component, as well as attribute 'env' with value 'prod' and the consumer needed a component, as well as attribute 'env' with value 'mock'
          - Variant 'prodReleaseApiElements' capability myApp.myLibrary:myLibrary:unspecified:
              - Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'env' with value 'prod' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'env' with value 'mock'
          - Variant 'prodReleaseRuntimeElements' capability myApp.myLibrary:myLibrary:unspecified declares a runtime of a component:
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'env' with value 'prod' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'env' with value 'mock'

This all works fine if I compile in devDebug, but these errors here show up when I compile in mockDebug.

CodePudding user response:

This appears to be a bug in Gradle.

I have this problem in com.android.tools.build:gradle:7.1.2 (any 7.1.* version really) and the 7.2 beta versions. Going back to 7.0.4 fixes the problem.

  • Related