androidandroid-studiogradlegradle-kotlin-dsldagger-hilt

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


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


Solution

  • 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'
    }