15

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
}
Vidyesh Churi
  • 1,899
  • 1
  • 24
  • 33

5 Answers5

13

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.

Suresh Chaudhari
  • 648
  • 1
  • 8
  • 21
  • The above warning is from android studio canary. I think the android team at google has one more internal version of the android studio as they had demonstrated Figma to compose translation at keynote but it is still not available in canary. – Vidyesh Churi Jan 14 '22 at 06:01
  • 1
    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, It has nothing to do with version of Android Studio, version of android studio only matters if Gradle version or Android Gradle version do not support Android Studio, and it will say so explicitly. – Suresh Chaudhari Jan 14 '22 at 13:08
4

Change agp_version version from 7.2.0-alpha04 to 7.2.2 .

Inside Project level build.gradle :

buildscript {
    ext {
        compose_version = '1.1.0-beta02'
        agp_version = '7.2.2'
    }
}

This works for me.

Abhishek Dutt
  • 1,308
  • 7
  • 14
  • 24
  • This comment is literally months after the original post. The solutions can be rephrased to this: "Just update your Android gradle plugin to the latest possible version" – yuroyami Feb 16 '23 at 15:32
2

Try adding this 1-line code below, under Gradle Scripts > gradle.properties (Project Properties) > Syn now > Build (Clean project > Rebuild project)

android.suppressUnsupportedCompileSdk=32
LBIRD S.E.
  • 31
  • 3
1

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

George
  • 2,292
  • 2
  • 10
  • 21
0

Change build.gradle with a new version:

classpath("com.android.tools.build:gradle:7.4.2")

See a list of plugin versions here, find a corresponding version and update gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

Probably after sync and compile it will work, but I had to revert to old versions (some plugins and Android Studio required old versions).

CoolMind
  • 26,736
  • 15
  • 188
  • 224