When I am running an app in android studio using Android Sv2 Preview SDK, I am getting a warning:
Build Output
We recommend using a newer Android Gradle plugin to use compileSdkPreview = "Sv2"
This Android Gradle plugin (7.2.0-alpha04) was tested up to compileSdk = 31
This warning can be suppressed by adding android.suppressUnsupportedCompileSdk=Sv2
to this project's gradle.properties
The build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdkPreview = "Sv2"
build.gradle (:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 31
compileSdkPreview 'Sv2'
...
}
...
build.gradle (Project:…)
buildscript {
ext {
compose_version = '1.1.0-beta02'
agp_version = '7.2.0-alpha04'
}
}// Top-level build file where you can add configuration options common to all sub-
projects/modules.
plugins {
id 'com.android.application' version '7.2.0-alpha04' apply false
id 'com.android.library' version '7.2.0-alpha04' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
where can I get the correct AGP(Android Gradle plugin) version?
What is apply false in
plugins {
id 'com.android.application' version '7.2.0-alpha04' apply false
id 'com.android.library' version '7.2.0-alpha04' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
5
Answers
The
apply false
syntax is used to tell Gradle not to apply the plugin to the current project and then use the plugins {} block without the version in subprojects’ build scripts.more details in the example given in official gradle doc
This is not a error, This is only a warning that you will only encounter in stable version of Android Studio,
Because Android Sdk 32 does not have a stable version release, it is currently in beta version.
Stable version of Android Studio recommends to use stable version of Android Gradle Plugin and therefore shows a warning when you use beta version of android SDK as compileSDK,
So the best solution is to ignore the warning or downgrade the version of compileSDK to current stable version which is 31 or suppress warning by adding "android.suppressUnsupportedCompileSdk=32" to gradle.properties. However if you really want to checkout features of new Android, use Android Studio Canary which is explicitly built for beta version of Android SDK, beta version Android Gradle Plugin and latest Gradle version. if above warning also shows up in android canary with latest version of Android Gradle Plugin, it means Android Gradle Plugin for new SDK has not been released, So there is no solution until or unless Android Gradle Plugin for new SDK is released.
Change
agp_version
version from7.2.0-alpha04
to7.2.2
.Inside Project level
build.gradle
:This works for me.
Try adding this 1-line code below, under Gradle Scripts > gradle.properties (Project Properties) > Syn now > Build (Clean project > Rebuild project)
Change
build.gradle
with a new version:See a list of plugin versions here, find a corresponding version and update
gradle-wrapper.properties
:Probably after sync and compile it will work, but I had to revert to old versions (some plugins and Android Studio required old versions).