How to specify source and target compatibility in Java module?

后端 未结 3 947
说谎
说谎 2020-12-11 01:20

I have a Gradle project consisting of an Android module (the com.android.library plugin is applied in the build.gradle file) and a Java module (the

3条回答
  •  失恋的感觉
    2020-12-11 01:42

    (As pointed out by the OP, this answer doesn't really fit the question. I'd like to keep it here at the bottom though, just in case somebody else lands on this page searching for the same problem as me)

    For android, the compileJava block that Jeroen Wijdemans suggested, does not work. What does work is specifying in the app build.gradle

    // https://developer.android.com/studio/write/java8-support.html
    // 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
    }
    

    Currently, intellij 2017.2.6 tells me then that you need to enable Jack. So let's do that as well, by adding the following inside the android block:

        // https://stackoverflow.com/questions/37004069/errorjack-is-required-to-support-java-8-language-features
        jackOptions {
            enabled true
        }
    

    If building now results in errors or warnings, simply rebuilding the whole project might get rid of them. (It did work for me)

提交回复
热议问题