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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With