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
2
Answers
This new Gradle setup is called
plugins DSL
, it is the new way to add Gradle plugin dependency without needing to add itsclasspath
. While the old legacy way requires you to include the dependency's classpath inside thebuildscript
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 addbuildscript
using the legacy approach.You hould put it in project level
build.gradle
file like this