This video shows the steps to fix the below error while using Java version greater 9 in Android Studio.
“In order to compile Java 9+ source, please set compileSdkVersion to 30 or above”
In this demo it uses Java version 11 because of which the error was observed.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@pworld1990
Code – gradle file after the fix:
plugins {
alias(libs.plugins.android.application)
}
android {
namespace = "com.programmerworld.myapplicationapi28"
compileSdk = 34
defaultConfig {
applicationId = "com.programmerworld.myapplicationapi28"
minSdk = 28
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
dependencies {
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.activity)
implementation(libs.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
}
Screenshots: