Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin + hilt error. [Hilt] and java.lang.reflect.InvocationTargetException (no error message)

I have a problem with my hilt injection. Recently I started learning Kotlin and Hilt for my project. I watched some tutorials and afterwhile tried to write my own code

My build.gradle

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.28.3-alpha"
        classpath 'com.google.gms:google-services:4.3.8'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

    }
}

allprojects {
    repositories {
        google()
        mavenCentral()

    }
}

And this one build.gradle

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            debuggable true
            signingConfig signingConfigs.config
        }
        debug {
            signingConfig signingConfigs.config
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'com.google.firebase:firebase-firestore:23.0.0'
    implementation 'com.google.firebase:firebase-storage:20.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
    implementation 'com.google.firebase:firebase-analytics'

    implementation 'com.google.android.exoplayer:exoplayer:2.14.0'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.14.0'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.14.0'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.0'

    // Material Design
    implementation 'com.google.android.material:material:1.3.0-alpha02'

    // Architectural Components
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"

    // Lifecycle
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

    // Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

    // Coroutine Lifecycle Scopes
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

    // Navigation Component
    implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.0"

    // Glide
    implementation 'com.github.bumptech.glide:glide:4.11.0'

    // Activity KTX for viewModels()
    implementation "androidx.activity:activity-ktx:1.1.0"

    //Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha'
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02"
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'


}

I have a java.lang.reflect.InvocationTargetException (no error message) error And just one message in console This one message

Whats wrong? I read a lot of suggestions but none of them helped

Injection code

like image 366
FeedokTV Avatar asked Sep 13 '25 14:09

FeedokTV


2 Answers

Did you add hilt-android-gradle-plugin to your project's root build.gradle file? This is how my gradle looks like:

plugins {
   id 'com.android.application'
   id 'kotlin-android'
   id 'kotlin-kapt'
   id 'dagger.hilt.android.plugin'
   id 'kotlin-parcelize'
}
like image 134
Berkay Kireçci Avatar answered Sep 16 '25 06:09

Berkay Kireçci


Your classpath version should be the same as these two

implementation "com.google.dagger:hilt-android:2.28-alpha"
kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha'

If it still doesn't work. Try to update all your hilt related to the lastest version, and make sure change your kotlin_version to 1.4.32. If you want to see the changes on hilt check out this: https://github.com/google/dagger/releases

like image 24
adwardwo1f Avatar answered Sep 16 '25 06:09

adwardwo1f