skip to Main Content

I want to add dagger-hilt plugin to project.

 classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'

https://developer.android.com/studio/preview/features#settings-gradle

plugins {
    id 'com.android.application' version '7.1.0-beta02' apply false
    id 'com.android.library' version '7.1.0-beta02' apply false
    id 'org.jetbrains.kotlin.android' version '1.5.30' apply false
}

task clean(type: Delete) {
  delete rootProject.buildDir
}
pluginManagement {
  repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
  }
}

dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositories {
    google()
    mavenCentral()
  }
}
rootProject.name = 'GradleManagedDeviceTestingNew'
include ':app'

4

Answers


  1. You should add a resolutionStrategy to settings.gradle as below.

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

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

    plugins{
      *****
      id 'dagger.hilt.android.plugin'
    }
    
    Login or Signup to reply.
  2. When creating a new project in AS BubmleBee the dependencies block is missing in top-level gradle file

    To resolve adding classpath dependencies you should add the following block within the buildscript block.

     dependencies {
            classpath "com.google.dagger:hilt-android-gradle-plugin:2.40.5"
    
        }
    
    Login or Signup to reply.
  3. This is the correct to using the classpath in bumblebee

    Use buildscript before plugins it will work and put your classpath there in the dependencies block

    buildscript {
        dependencies {
            classpath("com.google.dagger:hilt-android-gradle-plugin:2.40.5")
        }
    }
    
    
    plugins {
        id 'com.android.application' version '7.1.0-rc01' apply false
        id 'com.android.library' version '7.1.0-rc01' apply false
        id 'org.jetbrains.kotlin.android' version '1.5.30' apply false
    }
    
    
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    Login or Signup to reply.
  4. Add the following id in the plugins section of the top level gradle file:

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

    Credits to this SO answer

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search