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.

Dagger hilt kapt vs annotationProcessor issues

See original GitHub issue

Context

My dagger-hilt module has been coded in java, some classes (which contains @AndroidEntryPoint) I try to inject were written by java, some of them were written by kotlin. So when I use dagger hilt to do the injection, I have some erros such as

Execution failed for task ':app:transformClassesWithAndroidEntryPointTransformForDebug'.
> javassist.NotFoundException: 

BTW, I created a template project to reproduce this bug here is the link https://github.com/underwindfall/dagger_issue_project

Some potential solutions

Try to use kapt instead of annotationProcessor

I noticed that I was always use annotationProcessor as implementation dependency, at the begining of project, I thought it’s just for this "com.google.dagger:hilt-android-compiler:$hilt_version" is only for Dagger Module, since my dagger modules were coded by Java only , Classes like Activity etc we can still keep it as Kotlin. Turns out it’s not. Try to use kapt instead of annotationProcessor did solve the issue.

Try to code only by java or by kotlin

Yes the project can be compiled.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

1reaction
bcorsocommented, Jan 7, 2021

The example, seems fine as long as demoModeEnabled isn’t changed while an instance of the DashboardActivity is active.

However, if the demoModeEnabled value can change while DashboardActivity is active, it sounds like you would need to register an observer for the change and either

  1. Update all related state in DashboardActivity manually,
  2. or recreate the activity when the value changes (which would inject the new, correct value).

If you’re going with 1, you could do that by injecting Provider<DashboardContract.Interactor> and re-getting the value on each change.

Either way, it should be possible without modifying the Dagger graph at runtime.

0reactions
underwindfallcommented, Jan 8, 2021

Gotya, thanks for clarifying. Now the details of dagger-hilt looks more clear to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android project with Java and Kotlin files, kapt or ...
I have a project mixing both languages, and I just have replaced all the annotationProcessor dependencies in the build.gradle by kapt.
Read more >
KSP: Fact or kapt?. Fast and ergonomic annotation…
Firstly, KSP is faster since kapt depends on compiling Kotlin to Java ... while Dagger, Hilt, and Glide have open issues tracking support....
Read more >
The following options were not recognized by any processor...
There are two libraries using kapt for code generation: Dagger 2 (Hilt) and Room. In some cases kaptDebugKotlin fails with the following warning:...
Read more >
Use Hilt with other Jetpack libraries - Android Developers
Provide a ViewModel by annotating it with @HiltViewModel and using the @Inject annotation in the ViewModel object's constructor. Kotlin Java ...
Read more >
Using kapt | Kotlin
In a nutshell, you can use libraries such as Dagger or Data Binding ... replace usages of the annotationProcessor configuration with kapt ....
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