You should use Java 8 to solve this, based on the Android documentation you can do this by
clicking File > Project Structure
and change Source Compatibility
and Target Compatibility
.
and you can also configure it directly in the app-level 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
}
}