簡體   English   中英

Android Gradle 插件版本在新的 Android Studio (大黃蜂及以上)Z7B5CC4FB56E171DC75Z0FBB361

[英]Where to put Android Gradle Plugin version in the new Android Studio (Bumblebee and above) Gradle setup?

當您使用最新版本的 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 'com.google.gms:google-services:4.3.10'

我也不明白com.android.library插件是做什么的,為什么它在應用程序模塊中?

要問的另一件事是,通過這個新設置,您有兩個插件塊,一個在應用程序級別,一個在項目級別。 這真的有必要嗎? 那有什么意義呢? 謝謝

這個新的 Gradle 設置稱為plugins DSL ,它是添加 Gradle 插件依賴項而無需添加其classpath的新方法。 雖然舊的遺留方式要求您在buildscript塊中包含依賴項的類路徑。

請注意, com.google.gms:google-services:${version}等一些插件仍然不支持新插件 DSL,您需要使用舊方法添加buildscript

buildscript {
dependencies {
    classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"
}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM