0

I'm developing an Android app using Hilt for dependency injection, but when I run the app, I get a ClassNotFoundException for my MainApp class. Here's the logcat error message:

Process: com.nat.abudawood_internal_hr, PID: 22193 java.lang.RuntimeException: Unable to instantiate application com.nat.abudawood_internal_hr.MainApp package com.nat.abudawood_internal_hr: java.lang.ClassNotFoundException: Didn't find class "com.nat.abudawood_internal_hr.MainApp" on path: DexPathList[[zip file "/data/app/~~Yzrf2RBaLzHqDKZsUwqZaA==/com.nat.abudawood_internal_hr-RtyaSVKozlG4L2qYUTxHRA==/base.apk"],nativeLibraryDirectories=[/data/app/~~Yzrf2RBaLzHqDKZsUwqZaA==/com.nat.abudawood_internal_hr-RtyaSVKozlG4L2qYUTxHRA==/lib/arm64, /system/lib64, /system/system_ext/lib64]] at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1574) at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1503) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7558) at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2400) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.nat.abudawood_internal_hr.MainApp" on path: DexPathList[[zip file "/data/app/~~Yzrf2RBaLzHqDKZsUwqZaA==/com.nat.abudawood_internal_hr-RtyaSVKozlG4L2qYUTxHRA==/base.apk"],nativeLibraryDirectories=[/data/app/~~Yzrf2RBaLzHqDKZsUwqZaA==/com.nat.abudawood_internal_hr-RtyaSVKozlG4L2qYUTxHRA==/lib/arm64, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76) at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52) at android.app.Instrumentation.newApplication(Instrumentation.java:1232) at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1566) at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1503)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7558)  at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2400)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loopOnce(Looper.java:226)  at android.os.Looper.loop(Looper.java:313)  at android.app.ActivityThread.main(ActivityThread.java:8762)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)  Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/nat/abudawood_internal_hr/Hilt_MainApp; at java.lang.VMClassLoader.findLoadedClass(Native Method) at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738) at java.lang.ClassLoader.loadClass(ClassLoader.java:363) ... 16 more Caused by: java.lang.ClassNotFoundException: Didn't find class "com.nat.abudawood_internal_hr.Hilt_MainApp" on path: DexPathList[[zip file "/data/app/~~Yzrf2RBaLzHqDKZsUwqZaA==/com.nat.abudawood_internal_hr-RtyaSVKozlG4L2qYUTxHRA==/base.apk"],nativeLibraryDirectories=[/data/app/~~Yzrf2RBaLzHqDKZsUwqZaA==/com.nat.abudawood_internal_hr-RtyaSVKozlG4L2qYUTxHRA==/lib/arm64, /system/lib64, /system/system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312)`

Code Snippet:

MainApp
@HiltAndroidApp
class MainApp : Application() {
}

Manifest
<application
    android:name=".MainApp"
    ...
</application>

Gradle Dependencies (app)
    // Hilt
    implementation("com.google.dagger:hilt-android:"2.44")
    ksp("com.google.dagger:hilt-android-compiler:"2.44")
    ksp("androidx.hilt:hilt-compiler:1.1.0")
    implementation("androidx.hilt:hilt-navigation-compose:1.1.0")

Gradle Dependencies (project)
plugins {
    id("com.android.application") version "8.1.2" apply false
    id("org.jetbrains.kotlin.android") version "1.9.10" apply false
    id("com.google.dagger.hilt.android") version "2.44" apply false
    id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false
}

I'm using Android Studio Giraffe | 2022.3.1 Patch 2

What I've tried:

  • Checked the package name in AndroidManifest.xml.
  • Cleaned and rebuilt the project in Android Studio.
  • Made sure the Hilt setup is correct.
7
  • I suggest that you edit your question and provide the complete MainApp implementation. Commented Jan 21, 2024 at 19:47
  • There are no implementations, just empty class Commented Jan 21, 2024 at 19:50
  • I feel reasonably confident that there are more lines than the two that you show. I suggest that you edit your question and provide the complete Kotlin file that contains what code you have for MainApp. Commented Jan 21, 2024 at 19:52
  • It is common to create an empty class that extends the Application class (with hilt), that's done even in the docs Commented Jan 21, 2024 at 20:50
  • Does this answer your question? MyAppHiltApp: java.lang.ClassNotFoundException: Didn't find class "HiltApp" on path: DexPathList Commented Jan 21, 2024 at 20:51

1 Answer 1

1

I found a solution to the error. I changed the Hilt version from 2.44 to 2.48

Gradle (app)
    implementation "com.google.dagger:hilt-android:2.48"
    ksp "com.google.dagger:hilt-android-compiler:2.48"
    ksp 'androidx.hilt:hilt-compiler:1.0.0'
    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'

Gradle (project)
    id("com.google.dagger.hilt.android") version "2.48" apply false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.