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 - Incremental build issue - java.lang.NoClassDefFoundError

See original GitHub issue

Hi,

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:

  1. MyService in the feature module https://github.com/henieek/hilt-incremental-build-issue/blob/main/feature/src/main/java/com/example/feature/MyService.kt
  2. MyService gets injected to MainApplication as Lazy: https://github.com/henieek/hilt-incremental-build-issue/blob/main/app/src/main/java/com/example/hiltissue/MainApplication.kt

Steps to reproduce:

  1. Checkout the project
  2. ./gradlew installDebug
  3. In the MyService class, change the name of the doStuff() method to doStuff2()
  4. ./gradlew installDebug again
  5. Try to launch the app.

Some findings:

  1. Clean build fixes the issue.
  2. 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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
danysantiagocommented, Jul 19, 2022

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.

0reactions
d4rkencommented, Jul 13, 2022

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:

2022-07-13 14:43:42.504 13746-13746/eu.darken.androidstarter E/AndroidRuntime: FATAL EXCEPTION: main
    Process: eu.darken.androidstarter, PID: 13746
    java.lang.NoClassDefFoundError: Failed resolution of: Leu/darken/androidstarter/DaggerApp_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider;
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$SingletonCImpl.initialize(DaggerApp_HiltComponents_SingletonC.java:800)
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$SingletonCImpl.<init>(DaggerApp_HiltComponents_SingletonC.java:793)
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$SingletonCImpl.<init>(DaggerApp_HiltComponents_SingletonC.java:754)
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$Builder.build(DaggerApp_HiltComponents_SingletonC.java:139)
        at eu.darken.androidstarter.Hilt_App$1.get(Hilt_App.java:23)
        at dagger.hilt.android.internal.managers.ApplicationComponentManager.generatedComponent(ApplicationComponentManager.java:40)
        at eu.darken.androidstarter.Hilt_App.generatedComponent(Hilt_App.java:34)
        at eu.darken.androidstarter.Hilt_App.hiltInternalInject(Hilt_App.java:49)
        at eu.darken.androidstarter.Hilt_App.onCreate(Hilt_App.java:40)
        at eu.darken.androidstarter.App.onCreate(App.kt:16)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1223)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6762)
        at android.app.ActivityThread.access$1500(ActivityThread.java:256)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7870)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider" on path: DexPathList[[zip file "/data/app/~~L4t94MtqIyG5HRbwOIlGHQ==/eu.darken.androidstarter-D6HPNnNoWZFtYpI16jMIHA==/base.apk"],nativeLibraryDirectories=[/data/app/~~L4t94MtqIyG5HRbwOIlGHQ==/eu.darken.androidstarter-D6HPNnNoWZFtYpI16jMIHA==/lib/arm64, /data/app/~~L4t94MtqIyG5HRbwOIlGHQ==/eu.darken.androidstarter-D6HPNnNoWZFtYpI16jMIHA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$SingletonCImpl.initialize(DaggerApp_HiltComponents_SingletonC.java:800) 
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$SingletonCImpl.<init>(DaggerApp_HiltComponents_SingletonC.java:793) 
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$SingletonCImpl.<init>(DaggerApp_HiltComponents_SingletonC.java:754) 
        at eu.darken.androidstarter.DaggerApp_HiltComponents_SingletonC$Builder.build(DaggerApp_HiltComponents_SingletonC.java:139) 
        at eu.darken.androidstarter.Hilt_App$1.get(Hilt_App.java:23) 
        at dagger.hilt.android.internal.managers.ApplicationComponentManager.generatedComponent(ApplicationComponentManager.java:40) 
        at eu.darken.androidstarter.Hilt_App.generatedComponent(Hilt_App.java:34) 
        at eu.darken.androidstarter.Hilt_App.hiltInternalInject(Hilt_App.java:49) 
        at eu.darken.androidstarter.Hilt_App.onCreate(Hilt_App.java:40) 
        at eu.darken.androidstarter.App.onCreate(App.kt:16) 
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1223) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6762) 
        at android.app.ActivityThread.access$1500(ActivityThread.java:256) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7870) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
Read more comments on GitHub >

github_iconTop 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 >

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