在build.gradle文件中添加以下代码,以使用Java 11代替Java 8:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
...
}
然后在project的build.gradle文件中添加以下代码,以确保Gradle使用Java 11:
allprojects {
...
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.compilerArgs.addAll(["--release", "11"])
}
...
}