With Android Studio Arctic Fox | 2020.3.1 finally you can use Java 11 in your project, here more info:
https://developer.android.com/studio/past-releases/past-agp-releases/agp-7-0-0-release-notes#java-11
You can now compile up to Java 11 source code in your app’s project,
enabling you to use newer language features like private interface
methods, the diamond operator for anonymous classes, and local
variable syntax for lambda parameters.To enable this feature, set compileOptions to the desired Java version
and setcompileSdkVersionto 30 or above
// build.gradle
android {
compileSdkVersion 30
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
// For Kotlin projects
kotlinOptions {
jvmTarget = "11"
}
}