Hilt - Incremental build issue - java.lang.NoClassDefFoundError
See original GitHub issueHi,
We encountered a potential bug in Hilt which breaks the code generation in incremental builds, effectively causing a runtime crash on the start. This is the stacktrace we get:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/hiltissue/DaggerMainApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider;
at com.example.hiltissue.DaggerMainApplication_HiltComponents_SingletonC$SingletonCImpl.initialize(DaggerMainApplication_HiltComponents_SingletonC.java:469)
at com.example.hiltissue.DaggerMainApplication_HiltComponents_SingletonC$SingletonCImpl.<init>(DaggerMainApplication_HiltComponents_SingletonC.java:463)
at com.example.hiltissue.DaggerMainApplication_HiltComponents_SingletonC$SingletonCImpl.<init>(DaggerMainApplication_HiltComponents_SingletonC.java:454)
at com.example.hiltissue.DaggerMainApplication_HiltComponents_SingletonC$Builder.build(DaggerMainApplication_HiltComponents_SingletonC.java:69)
I created a sample project which presents the problem: https://github.com/henieek/hilt-incremental-build-issue
Relevant files:
MyService
in the feature module https://github.com/henieek/hilt-incremental-build-issue/blob/main/feature/src/main/java/com/example/feature/MyService.ktMyService
gets injected toMainApplication
asLazy
: https://github.com/henieek/hilt-incremental-build-issue/blob/main/app/src/main/java/com/example/hiltissue/MainApplication.kt
Steps to reproduce:
- Checkout the project
./gradlew installDebug
- In the
MyService
class, change the name of thedoStuff()
method todoStuff2()
./gradlew installDebug
again- Try to launch the app.
Some findings:
- Clean build fixes the issue.
- Injecting an instance directly, without
Lazy
, seems to fix the issue too.
I would appreciate if you could take a look - let me know if I can help with more information.
Thanks a ton!
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Hilt: java.lang.ClassNotFoundException: Didn't find class "com ...
I solved it, it turns out that I did not provide the kapt, id 'kotlin-kapt'. and used used implementation instead of kapt so...
Read more >Known issues with Android Studio and Android Gradle Plugin
lifecycle:lifecycle-runtime in your module. If you're seeing java.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.
Read more >Very annoying crash : java.lang.NoClassDefFoundError ...
I believe I have similar issue with AS 2.3.1, gradle 3.3 and Kotlin 1.1.1. The issue happens only on my windows machine. At...
Read more >Gradle Build Setup - Dagger
The Hilt Gradle plugin offers an option for performing Hilt's classpath aggregation in a dedicated Gradle task. This allows the Hilt annotation processors...
Read more >databinding errror: Error: symbol not found - Issue Tracker
KaptExecution > java.lang.reflect.InvocationTargetException (no error message) Try: Run with --info or --debug option to get more log output.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue was fixed by the Gradle team: https://github.com/gradle/gradle/issues/21203, and it seems it will be availbale in Gradle 7.6 RC1, so closing this one out.
This demo project of mine reproduces it: https://github.com/d4rken/android-starter-v4/tree/dagger-issue-3455
If I clean the project before deploying, it works. If i just deploy a second time without cleaning, I get: