Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In order to compile Java 9+ source, please set compileSdkVersion to 30 or above

Tags:

android

I am trying to build a project in Android Studio and getting this error

In order to compile Java 9+ source, please set compileSdkVersion to 30 or above

In my android/build.gradle file I have set

 compileSdkVersion = 33

How do I fix this?

like image 787
Matt Avatar asked Dec 01 '25 13:12

Matt


1 Answers

You can fix ths by adding this code to the buildscript section in your build.gradle file:

subprojects { subproject ->
    afterEvaluate{
        if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}

So afterwards it should look something like:

buildscript {
    ext {
        compileSdkVersion = 33
        buildToolsVersion = "33.0.0"
    }
    subprojects { subproject ->
        afterEvaluate{
            if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
                android {
                    compileSdkVersion rootProject.ext.compileSdkVersion
                    buildToolsVersion rootProject.ext.buildToolsVersion
                }
            }
        }
    }
}

This will apply compileSdkVersion and buildToolsVersion to any android modules you have.
Source: https://stackoverflow.com/a/25736483

like image 154
ut9081 Avatar answered Dec 04 '25 15:12

ut9081