Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found

im getting this gradle sync error - The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found. can someone help please ? :)

im using kotlin dsl, i have libs.kt in buildSrc

buildSrc - build.gradle.kts:

plugins {
    `kotlin-dsl`
}

repositories {
    jcenter()
}

libs.kt in buildSrc

object libs {
        object hilt {
            private const val dagger_hilt_version = "2.30.1-alpha"
            private const val jetpack_hilt_version = "1.0.0-alpha02"

            const val gradlePlugin = "com.google.dagger:hilt-android-gradle-plugin:$dagger_hilt_version"
            const val android = "com.google.dagger:hilt-android:$dagger_hilt_version"
            const val android_compiler = "com.google.dagger:hilt-android-compiler:$dagger_hilt_version"

            const val jetpack_viewmodel = "androidx.hilt:hilt-lifecycle-viewmodel:$jetpack_hilt_version"
            const val jetpack_compiler = "androidx.hilt:hilt-compiler:$jetpack_hilt_version"
        }

        /* more objects + more constants */

    }

my app build.gradle.kts looks like:

plugins {
    id("com.android.application")
    id("kotlin-android")
    id("kotlin-kapt")
    id("dagger.hilt.android.plugin")
    id("androidx.navigation.safeargs.kotlin")
    id("com.google.firebase.crashlytics")
    id("com.google.gms.google-services")

    id("com.google.firebase.firebase-perf")
}

android {
    useLibrary("org.apache.http.legacy")

    compileSdkVersion = "30"

    dependenciesInfo {
        includeInApk = true
        includeInBundle = true
    }

    buildFeatures {
        dataBinding = true
        compose = true
    }

    defaultConfig {   
        vectorDrawables.useSupportLibrary = true

        applicationId = "aa.bb.cc"

        targetSdkVersion(30)
        minSdkVersion(21)

        versionCode = 1
        versionName = "1.0.0"
    }

    signingConfigs {
        register("configReleaseCZ").configure {
            /*hidden part*/
        }
    }

    bundle {
        language {
            enableSplit = false
        }
    }

    buildTypes {
        named("debug").configure {
            isDebuggable = true
            extra.set("enableCrashlytics", false)
        }
        named("release").configure {
            isShrinkResources = true
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
            isDebuggable = false
            extra.set("enableCrashlytics", true)
            signingConfig = signingConfigs.getByName("configReleaseCZ")
        }
    }

    composeOptions {
        kotlinCompilerVersion = libs.kotlin.version
        kotlinCompilerExtensionVersion = libs.compose.version
    }

    lintOptions {
        isAbortOnError = false
    }
}

kapt {
    correctErrorTypes = true
}

dependencies {
    //implementation("com.google.dagger:hilt-android:2.30.1-alpha") 
    //kapt ("com.google.dagger:hilt-android-compiler:2.30.1-alpha") //this doesnt work wither

    implementation(libs.hilt.android)
    kapt(libs.hilt.android_compiler)

    implementation(libs.hilt.jetpack_viewmodel)
    kapt(libs.hilt.jetpack_compiler)

    /* many more dependencies */

}
kapt {
    correctErrorTypes = true
}

my project build.gradle.kts:

buildscript {
    repositories {
        google()
        mavenCentral()
        maven(url = "https://jitpack.io")
        maven(url = "https://repo1.maven.org/maven2/")
        maven(url = "https://plugins.gradle.org/m2/")
        maven(url = "https://github.com/userxpro/userx/raw/maven/")
        maven(url = "https://dl.bintray.com/kotlin/kotlin-eap/")
        maven(url = "https://dl.bintray.com/kotlin/kotlinx/")
        maven(url = "https://kotlin.bintray.com/kotlinx")
        maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
        maven(url = "http://storage.googleapis.com/r8-releases/raw")
        gradlePluginPortal()
    }

    dependencies {
        classpath(libs.r8)

        classpath(libs.androidGradlePlugin)
        classpath(libs.kotlin.gradlePlugin)
        classpath(libs.hilt.gradlePlugin)

        classpath("com.google.gms:google-services:4.3.4")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.4.1")
        classpath("com.google.firebase:perf-plugin:1.3.4")
    }
}

subprojects {
    repositories {
        google()
        mavenCentral()
        maven(url = "https://jitpack.io")
        maven(url = "https://repo1.maven.org/maven2/")
        maven(url = "https://plugins.gradle.org/m2/")
        maven(url = "https://dl.bintray.com/kotlin/kotlin-eap/")
        maven(url = "https://dl.bintray.com/kotlin/kotlinx/")
        maven(url = "https://kotlin.bintray.com/kotlinx")
        maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
        maven(url = "https://github.com/userxpro/userx/raw/maven/")
        jcenter()
    }

    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        kotlinOptions {
            // Treat all Kotlin warnings as errors
            //useIR = true

            //allWarningsAsErrors = true

            freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"

            // Enable experimental coroutines APIs, including Flow
            freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
            freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.FlowPreview"
            freeCompilerArgs += "-Xopt-in=kotlin.Experimental"
            freeCompilerArgs += "-Xallow-jvm-ir-dependencies"

            // Set JVM target to 1.8
            jvmTarget = "1.8"
        }
    }
}
like image 823
Kochchy Avatar asked Dec 15 '20 09:12

Kochchy


1 Answers

remove id("dagger.hilt.android.plugin")

sync gradle

add id("dagger.hilt.android.plugin")

like image 90
Alamgir Hossain Avatar answered Dec 03 '22 06:12

Alamgir Hossain