Hilt Android Plugin gradle configuration fails on kotlin 1.6.10 if app has transitive dependency on non-android library module
See original GitHub issueKotlin 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).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:18 (5 by maintainers)
Top GitHub Comments
We also have a similar problem (matching fallbacks being ignored), and the snapshot version fixes it!
See https://dagger.dev/dev-guide/versions#head-snapshot-setup