square / dagger

A fast dependency injector for Android and Java.
https://square.github.io/dagger/
Apache License 2.0
7.3k stars 3.07k forks source link

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

Closed Drjacky closed 3 years ago

Drjacky commented 3 years ago

Hilt Version: 2.36 Compose Project Android Studio Bumblebee | 2021.1.1 Canary 1 Build #AI-203.7717.56.2111.7361063, built on May 14, 2021 Runtime version: 11.0.10+0-b96-7281165 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 11.4

Depends:

        const val gradleVersion = "7.1.0-alpha01"
        const val hiltVersion = "2.36"
        const val hiltCompilerVersion = "1.0.0"
        const val hilt_android = "com.google.dagger:hilt-android:${Versions.hiltVersion}"
        const val hilt_android_compiler = "com.google.dagger:hilt-android-compiler:${Versions.hiltVersion}"
        const val hilt_compiler = "androidx.hilt:hilt-compiler:${Versions.hiltCompilerVersion}"

Root's build.gradle:

buildscript {
...
    dependencies {
        ...
        classpath(app.web.drjackycv.buildsrc.Depends.ClassPaths.hilt_android_gradle_plugin)

App's build.gradle:

plugins {
    id("com.android.application")
    kotlin("android")
    id("kotlin-parcelize")
    kotlin("kapt")
    id("dagger.hilt.android.plugin")
}
...
dependencies {
...
    //dependency injection
    implementation(Depends.Libraries.hilt_android)
    kapt(Depends.Libraries.hilt_android_compiler)
    kapt(Depends.Libraries.hilt_compiler)
    implementation(Depends.Libraries.java_inject)
...

Domain's build.gradle:

plugins {
    id("com.android.library")
    kotlin("android")
    id("kotlin-parcelize")
    kotlin("kapt")
    id("dagger.hilt.android.plugin")
}
...
dependencies {
    //dependency injection
    implementation(Depends.Libraries.hilt_android)
    kapt(Depends.Libraries.hilt_android_compiler)
    kapt(Depends.Libraries.hilt_compiler)

Data's build.gradle:

plugins {
    id("com.android.library")
    kotlin("android")
    id("kotlin-parcelize")
    kotlin("kapt")
    id("dagger.hilt.android.plugin")
}
...
dependencies {
    //dependency injection
    implementation(Depends.Libraries.hilt_android)
    kapt(Depends.Libraries.hilt_android_compiler)
    kapt(Depends.Libraries.hilt_compiler)
    implementation(Depends.Libraries.java_inject)

Presentation's build.gradle:

plugins {
    id("com.android.library")
    kotlin("android")
    id("kotlin-parcelize")
    kotlin("kapt")
    id("androidx.navigation.safeargs.kotlin")
    id("dagger.hilt.android.plugin")
}
...
dependencies {
    //dependency injection
    implementation(Depends.Libraries.hilt_android)
    kapt(Depends.Libraries.hilt_android_compiler)
    kapt(Depends.Libraries.hilt_compiler)
    implementation(Depends.Libraries.java_inject)

And it doesn't matter if I only use hilt_android_compiler or only hilt_compiler.

Sample project: https://github.com/Drjacky/MVVMTemplate/tree/feature/compose

swankjesse commented 3 years ago

Consider reporting this to another project; Dagger 1 is obsolete.