Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.hiltapp.Hilt_HiltApplication" on path: DexPathList

253 views Asked by At

I'm trying to set up dagger hilt in my compose project, but it seems like dagger can't find an Application class, although it does exist

@HiltAndroidApp
class HiltApplication:Application()
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            HiltAppTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {

                }
            }
        }
    }
}

android:name=".HiltApplication" inside of AndroidManifest has been written

Hilt dependecies were installed as follows:

Root build.gradle

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

Module build.gradle

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp")
id("com.google.dagger.hilt.android")
}
implementation("com.google.dagger:hilt-android:2.44")
ksp("com.google.dagger:hilt-compiler:2.44")
ksp("androidx.hilt:hilt-compiler:1.1.0")

Also, another error gets printed:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.hiltapp.Hilt_HiltApplication" on path: DexPathList

SOLUTION I just updated hilt version from 2.44 to 2.50 and now the code works

1

There are 1 answers

1
Cyd On

Have you tried to add the @HiltAndroidApp annotation in your application?

@HiltAndroidApp
class HiltApplication: Application() {)

And in your module gradle add the the plugin block.

id("com.google.dagger.hilt.android")