google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

Adding enableAggregatingTask breaks build #2704

Closed dzolnai closed 3 years ago

dzolnai commented 3 years ago

Versions:

We have a Kotlin Multiplatform Module called common, which is then referenced from Android and iOS. In the Android app we include this common module. The app builds fine without the following code in build.gradle:

hilt { enableAggregatingTask = true }

As soon as I add it, the next build after the Gradle sync fails with the following error:

Could not determine the dependencies of task ':android:app:hiltJavaCompileRtvNoordDebug'.
> Could not resolve all task dependencies for configuration ':android:app:hiltCompileOnlyRtvNoordDebug'.
   > Could not resolve project :common.
     Required by:
         project :android:app
      > The consumer was configured to find attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'omroep' with value 'rtvNoord'. However we cannot choose between the following variants of project :common:
          - debugApiElements
          - debugRuntimeElements
          - iosApiElements
          - iosDefault
          - iosRuntimeOnly
          - metadataApiElements
          - metadataDefault
        All of them match the consumer attributes:
          - Variant 'debugApiElements' capability nl.stichtingrpo.news.common:common:1.0 declares attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Unmatched attributes:
                  - Provides com.android.build.api.attributes.VariantAttr 'debug' but the consumer didn't ask for it
                  - Doesn't say anything about omroep (required 'rtvNoord')
                  - Provides org.gradle.usage 'java-api' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'androidJvm' but the consumer didn't ask for it
          - Variant 'debugRuntimeElements' capability nl.stichtingrpo.news.common:common:1.0 declares attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Unmatched attributes:
                  - Provides com.android.build.api.attributes.VariantAttr 'debug' but the consumer didn't ask for it
                  - Doesn't say anything about omroep (required 'rtvNoord')
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'androidJvm' but the consumer didn't ask for it
          - Variant 'iosApiElements' capability nl.stichtingrpo.news.common:common:1.0:
              - Unmatched attributes:
                  - Provides artifactType 'org.jetbrains.kotlin.klib' but the consumer didn't ask for it
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about omroep (required 'rtvNoord')
                  - Provides org.gradle.usage 'kotlin-api' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.localToProject 'public' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.native.target 'ios_x64' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'native' but the consumer didn't ask for it
          - Variant 'iosDefault' capability nl.stichtingrpo.news.common:common:1.0:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about omroep (required 'rtvNoord')
                  - Provides org.jetbrains.kotlin.localToProject 'local to :common' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.native.target 'ios_x64' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'native' but the consumer didn't ask for it
          - Variant 'iosRuntimeOnly' capability nl.stichtingrpo.news.common:common:1.0:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about omroep (required 'rtvNoord')
                  - Provides org.jetbrains.kotlin.native.target 'ios_x64' but the consumer didn't ask for it
          - Variant 'metadataApiElements' capability nl.stichtingrpo.news.common:common:1.0:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about omroep (required 'rtvNoord')
                  - Provides org.gradle.usage 'kotlin-api' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.localToProject 'public' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'common' but the consumer didn't ask for it
          - Variant 'metadataDefault' capability nl.stichtingrpo.news.common:common:1.0:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about omroep (required 'rtvNoord')
                  - Provides org.jetbrains.kotlin.localToProject 'local to :common' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'common' but the consumer didn't ask for it
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'prereleaseApiElements' capability nl.stichtingrpo.news.common:common:1.0:
              - Incompatible because this component declares attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'prerelease' and the consumer needed attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
              - Other compatible attribute:
                  - Doesn't say anything about omroep (required 'rtvNoord')
          - Variant 'prereleaseRuntimeElements' capability nl.stichtingrpo.news.common:common:1.0:
              - Incompatible because this component declares attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'prerelease' and the consumer needed attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
              - Other compatible attribute:
                  - Doesn't say anything about omroep (required 'rtvNoord')
          - Variant 'releaseApiElements' capability nl.stichtingrpo.news.common:common:1.0:
              - Incompatible because this component declares attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
              - Other compatible attribute:
                  - Doesn't say anything about omroep (required 'rtvNoord')
          - Variant 'releaseRuntimeElements' capability nl.stichtingrpo.news.common:common:1.0:
              - Incompatible because this component declares attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
              - Other compatible attribute:
                  - Doesn't say anything about omroep (required 'rtvNoord')

omroep is a flavor, which is set to rtvNoord in the current build variant. nl.stichtingrpo.news.common:common is the package of the common module. Is this new setting not compatible with the 4.x versions of AGP or Kotlin Multiplatform? Let me know if you need any more info for resolving this.

aftabahmadTW commented 3 years ago

Running into the same problem as this. Couldn't resolve our multi-platform module when applying the new flag

danysantiago commented 3 years ago

We made a fix for this (https://github.com/google/dagger/commit/396be80ee3870628cc4cf6296aaadd588bec33e8), but sadly didn't make it into the release, can you try using a snapshot of the plugin to confirm it works?

Snapshots are available in https://oss.sonatype.org/content/repositories/snapshots/com/google/dagger/, you add a maven repo in the repositories closure for plugins and depend on com.google.dagger:hilt-android-gradle-plugin:HEAD-SNAPSHOT.

dzolnai commented 3 years ago

I can confirm it working with the HEAD-SNAPSHOT version. One minor correction on the comment above, this is the correct repository URL: maven { url "https://oss.sonatype.org/content/repositories/snapshots/"}

eric-labelle commented 3 years ago

Not sure why, but it does not seem to work for our project (not a KMP project) with the HEAD_SNAPSHOT or it was broken in newest snapshots? Using dependencyInsight I can see it's using

I still have the error:

Execution failed for task ':app:getDependencies'.
> Cannot change dependencies of dependency configuration ':app:DebugAndroidTestRuntimeClasspath' after it has been included in dependency resolution. Use 'defaultDependencies' instead of 'beforeResolve' to specify default dependencies for a configuration.
danysantiago commented 3 years ago

@eric-labelle you seem to be having a different issue, can you file a new bug and share more information about your setup? Like your build.gradle and a trace running Gradle with --stacktrace.

eric-labelle commented 3 years ago

Thank you @danysantiago I just created a new issue with the most informations I was able to find after further investigation. https://github.com/google/dagger/issues/2744

Micpol commented 3 years ago

I have the same problem on a casual android project with hilt and multiple modules. We've tried migrating back to enableExperimentalClasspathAggregation, but it breaks lint as for another issue I've seen.

Snapshot however works fine, but using it as production dependency doesn't feel right, @danysantiago is there a release date already?

Also upgrading to AGP 7 didn't help, had same issues, though lint went a bit further but broke on some local .aars.

Edit. Also the enableAggregatingTask seems to work fine on Macs, but not on Windows.

danysantiago commented 3 years ago

Closing as the fix for this was released in 2.38