Getting error in Android Studio 2.1 with java 8

2020-03-08 08:01发布

Currently I am using java 8 with latest android studio 2.1

Here is my build.gradle file

android {
    compileSdkVersion 22
    buildToolsVersion "24rc3"

    defaultConfig {
        applicationId "com.name"
        minSdkVersion 10
        targetSdkVersion 19
        jackOptions {
            enabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
.......
}

I am getting the below compile time error that I have no clue

Error:com.android.jack.frontend.FrontendCompilationException: Failed to compile at com.android.jack.Jack.buildSession(Jack.java:892) at com.android.jack.Jack.run(Jack.java:472) at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:102) ... 8 more Warning:Exception while processing task java.io.IOException: com.android.jack.api.v01.CompilationException: Failed to compile :oTT:compileDebugJavaWithJack FAILED Error:Execution failed for task ':oTT:compileDebugJavaWithJack'.

java.io.IOException: com.android.jack.api.v01.CompilationException: Failed to compile Information:BUILD FAILED

Please feel to ask if you need some details.

5条回答
家丑人穷心不美
2楼-- · 2020-03-08 08:18

you can try

compileSdkVersion 23
buildToolsVersion '24.0.0-rc3'

note the dash before rc3. This is according to http://developer.android.com/preview/setup-sdk.html under the section "Update an existing project"

I am using 23 just for the lambda.

the following link shows the Supported Java 8 Language Features and APIs https://developer.android.com/preview/j8-jack.html

查看更多
We Are One
3楼-- · 2020-03-08 08:31

Some java 8 features only support Android N. read android docs http://developer.android.com/preview/j8-jack.html#configuration

When I use Default Methods on sdk23, I got this error too. so update your sdk version to Android N.

查看更多
不美不萌又怎样
4楼-- · 2020-03-08 08:38

I think we are all looking mostly at the same answer. To be precise I'd say "make sure the buildToolsVersion = "[version]" is the same as the [version] in the error".
For some this will be 24.0.0

查看更多
女痞
5楼-- · 2020-03-08 08:43

I had this error too, and what I found was that the error itself was masking another compilation issue. Look at your Console Messages carefully and see if there is something else not compiling. Once I solved the underlying issue with my own code, this error magically disappeared. Hope this helps.

查看更多
疯言疯语
6楼-- · 2020-03-08 08:43

Try to use next values:

compileSdkVersion = "android-N"
buildToolsVersion = "24.0.0 rc3"
查看更多
登录 后发表回答