question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
WonderCsabocommented, Apr 13, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dagger-hilt error while compiling project - Stack Overflow
I recommend using the latest stable version of Dagger. Mine is working with these versions:
Read more >
Dependency injection with Hilt | Android Developers
Hilt is a dependency injection library for Android that reduces the boilerplate of doing manual dependency injection in your project.
Read more >
Improve error messages for exceptions thrown from Jetifier
RuntimeException: Failed to transform '/Users/username/src/projname/app/libs/skyepub.jar' using Jetifier. Reason: 0. (Run with --stacktrace for more details.)
Read more >
Micronaut Gradle plugin
Table of Contents. 1. What's new; 2. The Gradle plugins. 2.1. Individual plugins. 3. Quick Start; 4. Micronaut Library Plugin. 4.1. Kotlin Support;...
Read more >
Gradle: Version Catalogs - Styling Android
Most recently, I have been using a Dependencies.kt Kotlin file in the ... module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found