Home > Software design >  Unable to instantiate application dagger android
Unable to instantiate application dagger android

Time:11-24

I am integrating dagger in my application And facing this issue when I run the app

java.lang.RuntimeException: Unable to instantiate application com.mine.parsexml.ParseApplication: java.lang.ClassNotFoundException: Didn't find class "com.mine.parsexml.ParseApplication" on path: DexPathList[[zip file "/data/app/com.mine.parsexml-4NxKMOI9esXH_ar6UHYk5w==/base.apk"],nativeLibraryDirectories=[/data/app/com.mine.parsexml-4NxKMOI9esXH_ar6UHYk5w==/lib/x86, /system/lib, /system/product/lib]]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:1226)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
    at android.app.ActivityThread.access$1300(ActivityThread.java:219)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)

This is the application class - already declared in manifest as well

@HiltAndroidApp
class ParseApplication: Application()

App level gradle

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'

} apply plugin: 'kotlin-android'

android {
compileSdk 31

defaultConfig {
    applicationId "com.mine.parsexml"
    minSdk 23
    targetSdk 31
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
    viewBinding true
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
kotlinOptions {
    jvmTarget = '1.8'
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/AL2.0'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/gradle/incremental.annotation.processors'
    exclude("META-INF/*.kotlin_module")
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4. '
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "com.google.android.exoplayer:exoplayer:2.16.0"
implementation "com.google.dagger:hilt-android:2.39.1"
implementation "com.google.dagger:hilt-android-compiler:2.39.1"
implementation "androidx.core:core-ktx: "
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

}
repositories {
mavenCentral()
}

CodePudding user response:

My issue was with the wrong keyword for dagger dependency for the compiler had to use kapt rather than implementation

changed

implementation "com.google.dagger:hilt-android-compiler:2.39.1"

to

kapt "com.google.dagger:hilt-android-compiler:2.39.1"
  • Related