Plugin [id: 'dagger.hilt.android.plugin'] was not found in any of the following sources
Asked Answered
P

15

73

I get the following warning when I want to use @AndroidEntryPoint which is a property of hilt in my project.

 Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)

When I try to add id 'dagger.hilt.android.plugin' to the module level build.gradle file of my project, I get the following error.

org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'dagger.hilt.android.plugin'] was not found in any of the following sources:

I tried to add it to the build.gradle file at the Module level of the project as follows. They all give an error.

enter image description here

I tried to add it as a classpath to the project level build.gradle file, in this case I still get an error.

enter image description here

When I created the default project, a settings.gradle structure was created as follows. This is my first time using this build. My version of Android Studio Android Studio - Bumblebee | 2021.1.1 Canary 13

enter image description here

Preferment answered 9/10, 2021 at 23:47 Comment(1)
Unrelated, but.... what is your beautiful colour scheme?Swung
P
48

After a long struggle, I solved the problem as follows;

I added a resolutionStrategy to settings.gradle as below.

 pluginManagement {
        repositories {...}
        plugins { ...}
     resolutionStrategy {
            eachPlugin {
                if( requested.id.id == 'dagger.hilt.android.plugin') {
                    useModule("com.google.dagger:hilt-android-gradle-plugin:2.39.1")
                }
            }
        }
    }

Then, when I added the hilt plugin as below to the module level build.gradle file, it was updated correctly.

plugins{
...
id 'dagger.hilt.android.plugin'
}
Preferment answered 10/10, 2021 at 10:27 Comment(4)
But why? I have not added it and am still able to use Hilt. This error only comes (in my case) when I convert root build.gradle to build.gradle.kts. Just trying a bunch of random stuff and pasting here with one random way which coincidentally worked will not help in wrong runYolande
@AtulGupta in my case the last version of gradle was making definitions in settings.gradle. Since classpath cannot be given in settings.gradle like build.gradle at project level, I solved it with this method.Preferment
Yup agree...That this particular string sequence definitely solved your issue but it clearly doesn't explain the root causeYolande
I have added my answer as well which explains why this config is requiredYolande
B
140

I am late for the answer. I was also facing the same problem in Android Studio Bumblebee because of the new Gradle syntax for adding dependencies at the project level.

For adding Dagger Hilt in project-level you can use the following syntax:

id 'com.google.dagger.hilt.android' version '2.41' apply false

At the time of writing this, the latest version is 2.41. It is in mavenCentral repository.

Burgh answered 16/3, 2022 at 7:50 Comment(4)
Nice, it was solved my issueDecoct
This solved my issue as well. First I tried this: id("dagger.hilt.android.plugin") and it didn't work. ThanksDisclamation
The version number is important. Initially I had '2.40.5' and it did not work. Changing it to '2.41' solved it.Baton
Also, disabling offline mode in Android Studio forced the download to succeed for me.Maroney
P
48

After a long struggle, I solved the problem as follows;

I added a resolutionStrategy to settings.gradle as below.

 pluginManagement {
        repositories {...}
        plugins { ...}
     resolutionStrategy {
            eachPlugin {
                if( requested.id.id == 'dagger.hilt.android.plugin') {
                    useModule("com.google.dagger:hilt-android-gradle-plugin:2.39.1")
                }
            }
        }
    }

Then, when I added the hilt plugin as below to the module level build.gradle file, it was updated correctly.

plugins{
...
id 'dagger.hilt.android.plugin'
}
Preferment answered 10/10, 2021 at 10:27 Comment(4)
But why? I have not added it and am still able to use Hilt. This error only comes (in my case) when I convert root build.gradle to build.gradle.kts. Just trying a bunch of random stuff and pasting here with one random way which coincidentally worked will not help in wrong runYolande
@AtulGupta in my case the last version of gradle was making definitions in settings.gradle. Since classpath cannot be given in settings.gradle like build.gradle at project level, I solved it with this method.Preferment
Yup agree...That this particular string sequence definitely solved your issue but it clearly doesn't explain the root causeYolande
I have added my answer as well which explains why this config is requiredYolande
S
23

For adding dagger hilt to your project. Follow these steps

Add hilt dependencies to your module's build.gradle. I assume you are using Kotlin, otherwise you have to use annotationProcessor insted of kapt plugin.

dependencies {
  //..
  implementation 'com.google.dagger:hilt-android:2.39.1'
  kapt 'com.google.dagger:hilt-compiler:2.39.1'
  //..
   }

Add hilt gradle plugin to project's build.gradle.

dependencies {
    //..
    classpath 'com.google.dagger:hilt-android-gradle-plugin:2.39.1'
  }

Apply kotlin-kapt and hilt plugins to module build.gradle

plugins {
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}
Spiffy answered 10/10, 2021 at 8:39 Comment(4)
In gradle latest version I can't do this like classical method.Preferment
What version are you using?Spiffy
Are you sure 2.39.1 version of dagger hilt is really available? at the time of writing this comment 2.31-alpha is available.Hearne
@GopalSinghSirvi Currently, the latest version of the hilt is 2.40.5 which was released on Dec 7th, 2021. github.com/google/dagger/releases/tag/dagger-2.40.5Spiffy
Y
15

plugin{} block in the root build.gradle is used to define the Gradle plugins that can be applied to root build.gradle and all(or some) the Gradle sub-projects.

The one caveat of using plugin block is that it only resolves plugin that is present in the Gradle plugin portal(see doc) or custom Maven and Ivy plugin repositories must contain plugin marker artefacts in addition to the artefacts which actually implement the plugin(see doc). In the case of the Android Gradle plugin and Hilt plugin, they have not published those plugins to Gradle plugin portal and they have also not published their Plugin Marker Artifacts

Due to the above missing Plugin Marker Artifacts you need to manually resolve the plugin using Plugin Resolution Rules at settings.gradle by adding the below code(this is specific to Hilt Gradle plugin for other you have to check different against requested.id.id)

pluginManagement {
    repositories {
        // Your repo from where Gradle will search for Gradle plugins
    }
    plugins {
        // ...
    }
    resolutionStrategy {
        eachPlugin {
            if(requested.id.id == 'dagger.hilt.android.plugin') {
                    useModule("com.google.dagger:hilt-android-gradle-plugin:${requested.version}")
            }
        }
    }
}

Yolande answered 2/1, 2022 at 13:15 Comment(1)
Much appreciated for the {requested.version}Equitable
W
11

I faced the same problem, I solved the problem as follows:

First, add the com.google.dagger.hilt.android plugin to your project's root build.gradle file:

plugins {
    id 'com.android.application' version '7.2.0' apply false
    id 'com.android.library' version '7.2.0' apply false
    id 'com.google.dagger.hilt.android' version '2.42' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.0' apply false
}

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

Then, apply the Gradle plugin and add these dependencies in your app/build.gradle file:

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

android {
    ....................
    // Enable java 8
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    
    implementation 'com.google.dagger:hilt-android:2.38.1'
    kapt 'com.google.dagger:hilt-android-compiler:2.38.1'
  
}
Worn answered 14/6, 2022 at 17:33 Comment(0)
H
7

Just you need to add this to project's root build.gradle file.

buildscript {
  repositories {
    // other repositories...
    mavenCentral()
  }
  dependencies {
    // other plugins...
    classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40'
  }
}
Halla answered 11/11, 2021 at 11:40 Comment(2)
This is the correct solution no need for all the stuff you are told by AndroidEngineX the docs are here dagger.dev/hilt/gradle-setup.htmlArreola
@Arreola This is an older way to do it. In the latest Android studio, you have to do it using the way AndroidEngineX and other have suggested.Equitable
S
4

use this configration in gradle root

         plugins {
         id 'com.android.application' version '7.2.0' apply false
         id 'com.android.library' version '7.2.0' apply false
        id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
        id 'com.google.dagger.hilt.android' version '2.42' apply false
         }

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

and in 2nd gradle file

   plugins {    id 'com.android.application'    id 
   'org.jetbrains.kotlin.android'    id 'kotlin-kapt'    id 
   'com.google.dagger.hilt.android' }
   android {    compileSdk 32
   defaultConfig {
   applicationId "com.example.hilttest"
   minSdk 21
   targetSdk 32
   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    }    kotlinOptions {
   jvmTarget = '1.8'    } }
   dependencies {
   implementation 'androidx.core:core-ktx:1.7.0'    implementation 
   'androidx.appcompat:appcompat:1.4.1'    implementation 
     `enter code here`'com.google.android.material:material:1.6.0'    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'    testImplementation 'junit:junit:4.13.2'    androidTestImplementation 'androidx.test.ext:junit:1.1.3'    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'    implementation 'com.google.dagger:hilt-android:2.42'    kapt 'com.google.dagger:hilt-compiler:2.42'
   // For instrumentation tests    androidTestImplementation  'com.google.dagger:hilt-android-testing:2.42'    kaptAndroidTest 'com.google.dagger:hilt-compiler:2.42'
   // For local unit tests    testImplementation 'com.google.dagger:hilt-android-testing:2.42'    kaptTest 'com.google.dagger:hilt-compiler:2.42' } kapt {    correctErrorTypes = true }
Snowslide answered 1/6, 2022 at 5:8 Comment(0)
A
2

I found this: Gradle Build Setup

plugins {
  // other plugins...
  id 'com.google.dagger.hilt.android' version '2.48.1' apply false
}

That works for me (although I didn’t use the apply false; I think that’s only if you have a parent project with sub projects). Note that the plugin name is different (‘com.google.dagger.hilt.android’ vs ‘dagger.hilt.android.plugin’), and that a version is specified; it didn’t work until I specified a version.enter code here

Amphitheater answered 19/2, 2024 at 14:39 Comment(0)
H
1

First, add the hilt-android-gradle-plugin plugin to your project's root build.gradle  file:

buildscript {
    ...
    dependencies {
        def hilt_version = "2.39.1"
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
    }
}

Then, apply the Gradle plugin and add these dependencies in your app/build.gradle file:

plugins {
  id 'kotlin-kapt' // for annotation processing
  id 'dagger.hilt.android.plugin'
}

android {
    ...
}

dependencies {
    def hilt_version = "2.39.1"
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-compiler:$hilt_version"
}

 
kapt {
    correctErrorTypes true
}

enable Java 8 in your project, add the following to the app/build.gradle

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8.toSttring()
}
Hearse answered 22/3, 2022 at 16:46 Comment(1)
You forgot to mention that this solution is almost copy-paste from the official documentation: developer.android.com/training/dependency-injection/…Bloom
N
1

if u use gradle kotlin DSL

you must change kapt to ksp https://developer.android.com/build/migrate-to-ksp

Nutation answered 2/6, 2023 at 0:13 Comment(0)
D
0

All I need to add was this class path:

classpath 'com.google.dagger:hilt-android-gradle-plugin:2.39.1'
Durning answered 4/5, 2022 at 17:25 Comment(0)
M
0

I also faced the same issue, I solved it by adding com.google.dagger.hilt.android to my root build.gradle()

plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
    id 'com.google.dagger.hilt.android' version '2.46.1' apply false
} 

Then I applied this plug and added hilt dependencies in my app/build.gradle(Module:app)

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


 dependencies{
    ----------------------------------------
      // dagger -hilt
        implementation "com.google.dagger:hilt-android:2.46.1"
        kapt "com.google.dagger:hilt-compiler:2.46.1"
        implementation "androidx.activity:activity-ktx:1.7.2"
    }
Mesocratic answered 27/6, 2023 at 15:22 Comment(0)
S
0

in build.gradle project level, add this line id 'com.google.dagger.hilt.android' version '2.46.1' apply false

plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
    id 'com.google.dagger.hilt.android' version '2.46.1' apply false
}

Then in build.gradle app level, add this line id 'com.google.dagger.hilt.android'

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'com.google.dagger.hilt.android'
}
Saffron answered 8/7, 2023 at 5:38 Comment(0)
C
0

If you are using Kotlin and Android Studio Bumblebee 2023.1 or letter version then add the hilt-android-gradle-plugin plugin to your project's root build.gradle file:

plugins {
  ...
  id("com.google.dagger.hilt.android") version "2.44" apply false
}
Castano answered 7/8, 2023 at 9:42 Comment(0)
T
0

If you, like me, came across this because you were trying to add the dagger plugin into a precompiled convention plugin, none of the other answers will solve the problem. The solution is easy to gloss over, but note the part of gradle's documentation on convention plugins stating:

external plugins need to be added as implementation dependencies before they can be applied in a precompiled script plugin

So, assuming a directory structure of:

├─build-conventions
│ ├─build.gradle.kts
│ ├─settings.gradle.kts
│ ├─src
│ │ ├─main
│ │ │ └─kotlin
│ │ │   ├─myproject.hilt-conventions.gradle.kts
│ │ │   └─[...]
├─app
│ └─[...]
├─build.gradle
├─settings.gradle

Rather than adding the hilt plugin as a versioned plugin in the root build.gradle.kts as you would do to get hilt to function in the :app module, you will instead need to add the following to build-conventions/build.gradle.kts:

// build-conventions/build.gradle.kts

dependencies {
    implementation("com.google.dagger:hilt-android-gradle-plugin:2.47")
}

Then you will be free to apply the hilt plugin as usual to your convention plugin:

// build-conventions/src/main/kotlin/myproject.hilt-conventions.gradle.kts

plugins {
    id("kotlin-kapt")
    id("dagger.hilt.android.plugin")
}
Testate answered 16/8, 2023 at 15:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.