This solution works in Android Studio 3.0 or later.
Change both of Source Compatibility
and Target Compatibility
to 1.8
You can also configure it directly in the corresponding build.gradle file
android {
...
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}