简体   繁体   English

如何在 Android Studio Bumblebee 中添加插件

[英]How to add plugins in the Android Studio Bumblebee

I want to add dagger-hilt plugin to project.我想将 dagger-hilt 插件添加到项目中。

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

https://developer.android.com/studio/preview/features#settings-gradle 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这是在 bumblebee 中使用类路径的正确方法

Use buildscript before plugins it will work and put your classpath there in the dependencies block在插件之前使用 buildscript 它将工作并将您的类路径放在依赖项块中

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.您应该将 resolutionStrategy 添加到 settings.gradle 如下。

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.然后,将如下所示的 hilt 插件添加到模块级别的 build.gradle 文件中,它已正确更新。

plugins{
  *****
  id 'dagger.hilt.android.plugin'
}

When creating a new project in AS BubmleBee the dependencies block is missing in top-level gradle file在 AS BubmleBee 中创建新项目时,顶级 gradle 文件中缺少依赖项块

To resolve adding classpath dependencies you should add the following block within the buildscript block.要解决添加类路径依赖项的问题,您应该在 buildscript 块中添加以下块。

 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:在顶级 gradle 文件的 plugins 部分添加以下 id:

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

Credits to this SO answer这个答案的学分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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