简体   繁体   中英

How to add plugins in the Android Studio Bumblebee

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'

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
}

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

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"

    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM