在新版的Android Studio(Bumblebee及以上版本)Gradle设置中,应该在哪里放置Android Gradle插件的版本?

3
当你使用最新版本的Android Studio创建新的Android项目时,它将提供一个仅包含插件块的项目级别build.gradle文件。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

我的问题是如何在这个设置中指定 AGP 的版本?以前它看起来像这样:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    // This block encapsulates custom properties and makes them available to all modules in the project.
    ext {
        kotlin_version = '1.6.20-M1'
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.0-alpha03'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

    }
}

我也想知道如何在一些仍然需要它的插件中添加classpath,比如

classpath 'com.google.gms:google-services:4.3.10'

我不理解的另一件事是,com.android.library插件的作用是什么,为什么它在应用模块中?

另一个问题是,在这个新设置中,你有两个插件块,一个在应用级别上,一个在项目级别上。这真的必要吗?这是什么意思?谢谢。


我认为这可能会有所帮助 https://dev59.com/5XQOtIcB2Jgan1zno995 - einschneidend
2个回答

3
这个新的Gradle 设置被称为plugins DSL,它是添加Gradle插件依赖项的新方法,无需添加其classpath。而旧的遗留方式需要您在buildscript块中包含依赖项的classpath。
请注意,一些插件如com.google.gms:google-services:$ {version}仍不支持新的插件DSL,您需要使用传统方法添加buildscript

1
你需要将它放在项目级别的build.gradle文件中,像这样。
buildscript {
dependencies {
    classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"
}}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接