6

Added hilt dependencies:

Build.gradle(project)

def hilt_version = "2.38.1"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"

Build.gradle(app)

plugins {
 id 'dagger.hilt.android.plugin'
 ....
 }

....

dependencies {
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-compiler:2.38.1"
 .......
 }

I also have a global application class:

MyApplication.kt

@HiltAndroidApp
class MyApplication : Application()

In my manifest:

Manifest.xml

<application
    android:allowBackup="true"
    android:name=".global.MyApplication"/>

Now, I create a module

NetworkModule.kt

@Module
@InstallIn(SingletonComponent::class)
class NetworkModule {

}

I get error when I run my code:

**Execution failed for task ':app:kaptDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.InvocationTargetException (no error message)**

When I remove these: @Module() and @InstallIn()

The error goes away...

what could be the problem? The error shown to me is not informative at all.

2
  • Did you add the kotlin-kapt plugin in the build.gradle? Commented Sep 13, 2021 at 12:54
  • Yes, its there: id 'kotlin-kapt' @LucaPizzini Commented Sep 13, 2021 at 13:18

6 Answers 6

3

Keeping latest updated dagger hilt dependencies solved my problem.

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}

 //dagger 
    implementation 'com.google.dagger:dagger:2.40.5'
    kapt 'com.google.dagger:dagger-compiler:2.40.5'
Sign up to request clarification or add additional context in comments.

Comments

1

So, it appears there is an issue integrating Hilt while targeting version 31 (Android 12).

When I had:

compileSdkVersion 31
buildToolsVersion "31.0.0"

defaultConfig {
   minSdkVersion 21
   targetSdkVersion 31
}

The error appears...

but when I changed to:

compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
   minSdkVersion 21
   targetSdkVersion 30
}

It starts working, without that error..

Something wrong with integrating Hilt while targeting android 12 (likely)

1 Comment

But it is not a solution. We need to target API levels 31 and 32
1

Follow the steps to add the hilt dependencies as stated in the below site then an error will be resolved

https://dagger.dev/hilt/gradle-setup

Comments

0

I Upgraded my project to Java 11 in the module gradle file.

android {
compileSdkVersion 31
buildToolsVersion "30.0.2"

compileOptions {
    sourceCompatibility 11
    targetCompatibility 11
}

kotlinOptions {
    jvmTarget = "11"
}

And I updated to the latest gradle plugins

enter image description here

And made sure the project points to gradle jdk11 enter image description here

Comments

0

I'm trying to update android studio to Bumblebee's Android Studio version | 2021.1.1 RC 1

android {

    compileSdkVersion 31
    buildToolsVersion "30.0.3"

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

gradle project

gradle module

Comments

0

Build for targetSdkVersion 31 works fine with version 2.42 (jvmTarget, sourceCompatibility and targetCompatibility 1.8). Versions before 2.42 failed to build successfully.

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.