dagger: Hilt Android Plugin gradle configuration fails on kotlin 1.6.10 if app has transitive dependency on non-android library module

Kotlin 1.6.10 Dagger/Hilt: 2.40.5 Gradle: 7.3.1 AGP: 7.0.4

I have an app module demo with the hilt gradle plugin applied. It has a dependency chain this: :features:mfc:demo > :base-ui > :base-utils

:base-ui applies “com.android.library” and “kotlin-kapt” plugins :base-utils applies “java-library” and “kotlin-kapt” plugins

So, demo has a transitive dependency on the base-utils module.

When compiling demo I get the following

* What went wrong:
Could not determine the dependencies of task ':features:mfc:demo:hiltJavaCompileDebug'.
> Could not resolve all task dependencies for configuration ':features:mfc:demo:hiltCompileOnlyDebug'.
   > Could not resolve project :base-utils.
     Required by:
         project :features:mfc:demo > project :base-ui
      > The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'. However we cannot choose between the following variants of project :base-utils:
          - _classStructurekaptKotlin
          - _classStructurekaptTestKotlin
        All of them match the consumer attributes:
          - Variant '_classStructurekaptKotlin' capability root-project:base-utils:unspecified declares a runtime of a component:
              - Unmatched attribute:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
          - Variant '_classStructurekaptTestKotlin' capability root-project:base-utils:unspecified declares a runtime of a component:
              - Unmatched attribute:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'apiElements' capability root-project:base-utils:unspecified:
              - Incompatible because this component declares an API of a component and the consumer needed a runtime of a component
              - Other compatible attribute:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')

When I disable incremental compilation in gradle.properties the build succeeds:

kapt.incremental.apt=false

So I’m assuming that the bug is related to kapt somehow.

I don’t understand why the hiltCompileOnlyDebug configuration would have the consumer requirement of com.android.build.api.attributes.BuildTypeAttr on java/kotlin only modules?

Assembling :base-ui directly succeeds.

I did not have this problem before upgrading to kotlin 1.6.10. (was running 1.5.30 before).

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 18 (5 by maintainers)

Most upvoted comments

We also have a similar problem (matching fallbacks being ignored), and the snapshot version fixes it!

@GuilhE it seems you are experiencing https://github.com/google/dagger/issues/3014 which should have been fixed for 7.1 based on the Google Issue: https://issuetracker.google.com/issues/205856789. Can you please report in the IssueTracker that you are still experiencing it.