I was trying to build an application that uses Dagger Hilt following a tutorial. I was checking whether the app is working after setting up a list of objects from API but then I kept getting a following error:
java.lang.RuntimeException: Unable to instantiate application com.example.pokedex_tutorial.PokedexApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.pokedex_tutorial.PokedexApplication" on path: DexPathList[[zip file "/data/app/~~dm2RLkrZitO-2YAba3pu3A==/com.example.pokedex_tutorial-4k4KLyudFgSUrCU--HNRXA==/base.apk"],nativeLibraryDirectories=[/data/app/~~dm2RLkrZitO-2YAba3pu3A==/com.example.pokedex_tutorial-4k4KLyudFgSUrCU--HNRXA==/lib/x86, /system/lib, /system_ext/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1244)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.pokedex_tutorial.PokedexApplication" on path: DexPathList[[zip file "/data/app/~~dm2RLkrZitO-2YAba3pu3A==/com.example.pokedex_tutorial-4k4KLyudFgSUrCU--HNRXA==/base.apk"],nativeLibraryDirectories=[/data/app/~~dm2RLkrZitO-2YAba3pu3A==/com.example.pokedex_tutorial-4k4KLyudFgSUrCU--HNRXA==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
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:51)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1236)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6683)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/pokedex_tutorial/Hilt_PokedexApplication;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 14 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.pokedex_tutorial.Hilt_PokedexApplication" on path: DexPathList[[zip file "/data/app/~~dm2RLkrZitO-2YAba3pu3A==/com.example.pokedex_tutorial-4k4KLyudFgSUrCU--HNRXA==/base.apk"],nativeLibraryDirectories=[/data/app/~~dm2RLkrZitO-2YAba3pu3A==/com.example.pokedex_tutorial-4k4KLyudFgSUrCU--HNRXA==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 17 more
I couldn't find any solution that works for me so all help is deeply appreciated. If it helps the source code is on my repository
I've seen that for some people the problem stemmed from gradle files so here they are:
// project level gradle
plugins {
id("com.android.application") version "8.1.1" apply false
id("org.jetbrains.kotlin.android") version "1.8.10" apply false
id("com.google.devtools.ksp") version "1.8.10-1.0.9" apply false
id("com.google.dagger.hilt.android") version "2.44.2" apply false
}
// build level gradle
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp")
id("com.google.dagger.hilt.android")
}
android {
namespace = "com.example.pokedex_tutorial"
compileSdk = 34
defaultConfig {
applicationId = "com.example.pokedex_tutorial"
minSdk = 30
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.7.2")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
implementation("androidx.compose.material:material:1.5.1")
implementation("androidx.compose.material:material-icons-core:1.5.1")
implementation("androidx.compose.material:material-icons-extended:1.5.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0-alpha02")
implementation("androidx.navigation:navigation-compose:2.7.2")
implementation("androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha12")
// Retrofit
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.0")
// Timber
implementation("com.jakewharton.timber:timber:4.7.1")
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1")
// Coroutine Lifecycle Scopes
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
// Coil
implementation("io.coil-kt:coil:1.1.1")
implementation("com.google.accompanist:accompanist-coil:0.7.0")
//Dagger - Hilt
implementation("com.google.dagger:dagger:2.44.2")
ksp("com.google.dagger:dagger-compiler:2.44.2")
implementation("com.google.dagger:hilt-android:2.44.2")
implementation("androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03")
implementation("androidx.hilt:hilt-navigation-compose:1.1.0-alpha01")
ksp("androidx.hilt:hilt-compiler:1.1.0-alpha01")
ksp("com.google.dagger:hilt-android-compiler:2.44.2")
implementation("androidx.palette:palette-ktx:1.0.0")
}
If anyone stumbles on a similar problem: the issue was that ksp is still not supporting hilt properly. I fixed the issue by reverting back to kapt