4

Why [Default and static interface methods] of java 8 are not supported in Android Studio 3.0?

The code always got the error hint.

the demo code

The build.gradle settings :

compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
    applicationId "com.dreamzone.mtime"
    minSdkVersion 18
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"

}

But android studio doc shows it can compatible any api level. https://developer.android.com/studio/write/java8-support.html android studio doc

2
  • On that page you screenshot, did you see how to enable Java 8 support? Commented Nov 25, 2017 at 17:22
  • Thanks. It finally works after I update the Android plugin to 3.0.1.I missed that hint. Commented Nov 26, 2017 at 8:26

2 Answers 2

7

You need to set Java 8 compatibility in your module's build.gradle file, via the compileOptions closure inside the android closure:

apply plugin: 'com.android.application'

android {

    // other good stuff here

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I tried the compile options and grade sync msg error changed to Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8. I found that I forgot to update Android Gradle plugin to 3.0.0 and higher, now it's ok,thanks.
0

// only chnage minSdkversion to more then 26

  defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 26
        targetSdkVersion 30
        versionCode 1
        versionName "1.0
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.