Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hilt Not Syncing

I know this question has been asked before but none of the solutions I've seen seems to work for me. I am new to hilt and I am trying to learn it while using java in android studio. I went to android docs and copy/pasted the dependencies, plugins, and class paths that they provide. But when I try to sync the project fails and says this:

org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to org.codehaus.groovy.ast.expr.ArgumentListExpression
org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to org.codehaus.groovy.ast.expr.ArgumentListExpression

This is my Top level build gradle:

       // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and this is my app level build gradel:

    plugins {
    id 'com.android.application'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'dagger.hilt.android.plugin'

    }

android {
    compileSdkVersion 30
    buildToolsVersion "29.0.3"

    buildFeatures {
        dataBinding = true
    }

    defaultConfig {
        applicationId "com.example.blogs"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "com.github.bumptech.glide:glide:4.12.0"
    annotationProcessor "com.github.bumptech.glide:compiler:4.12.0"
    implementation "com.google.code.gson:gson:2.8.6"
    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-gson:2.7.0"
    implementation "androidx.lifecycle:lifecycle-viewmodel:2.3.1"
    implementation "androidx.lifecycle:lifecycle-livedata:2.3.1"
    implementation "androidx.appcompat:appcompat:1.3.0"
    implementation "com.google.android.material:material:1.3.0"
    implementation "androidx.constraintlayout:constraintlayout:2.0.4"
    testImplementation "junit:junit:4.+"
    implementation "com.google.dagger:hilt-android:2.28-alpha"
    kapt "com.google.dagger:hilt-compiler:2.28-alpha"
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

I changed:

plugins {
        id 'com.android.application'
        apply plugin: 'kotlin-kapt'
        apply plugin: 'dagger.hilt.android.plugin'
    
        }

to:

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

}

but this fails and says:

A problem occurred evaluating project ':app'.
> Could not find method kapt() for arguments [com.google.dagger:hilt-compiler:2.28-alpha] on 
object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

I then saw a solution which said to use annotationProcessor instead of kapt in the dependencies for the "com.google.dagger:hilt-compiler:2.28-alpha" dependency. I get:

 A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > Configuration with name 'kapt' not found.
   > The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android-compiler dependency was found.

and when I use implementation the same thing happens.

Please help me solve this problem and thank you in advance.

like image 286
Daniel Edwards Avatar asked Feb 05 '26 11:02

Daniel Edwards


1 Answers

Ok. I figured it out.

I needed to change:

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

to:

annotationProcessor "com.google.dagger:hilt-android-compiler:2.28-alpha"

The first one is what I got from the android docs here https://developer.android.com/training/dependency-injection/hilt-android#java

I found this solution here https://github.com/google/dagger/issues/2086.

like image 61
Daniel Edwards Avatar answered Feb 07 '26 02:02

Daniel Edwards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!