简体   繁体   中英

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

When you are creating new Android project with the latest version of Android Studio it will now give you a project level build.gradle that only contains plugins block

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

My question is how to specify now the version of AGP with this setup? Before it looks like this

// 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

    }
}

I also wonder how would you add classpath on some plugins that still requires it like

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

What I also do not understand is what does com.android.library plugin do and why is it in app module?

Another thing to ask is with this new setup you have two plugins block, one in app level and one in project level. Is this really necessary? What is the point of that? Thanks

This new Gradle setup is called plugins DSL , it is the new way to add Gradle plugin dependency without needing to add its classpath . While the old legacy way requires you to include the dependency's classpath inside the buildscript block.

Note that some of the plugins like com.google.gms:google-services:${version} still not support the new plugin DSL and you are required to add buildscript using the legacy approach.

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

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