Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error in Android Studio 2.1 with java 8

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.

like image 734
Soham Avatar asked May 04 '16 09:05

Soham


People also ask

Can I use Java 8 in Android Studio?

Java 8 language features are now supported by the Android build system in the javac/dx compilation path. Android Studio's Gradle plugin now desugars Java 8 class files to Java 7-compatible class files, so you can use lambdas, method references and other features of Java 8.

Can I use JDK 11 for Android studio?

Up to Android Studio 3.5 beta 2 one could use JDK11 for compiling project by configuring it in Project Structure -> SDK Location -> JDK Location. This way Android Studio is run under bundled JDK8 but Gradle is using selected JDK11. Starting from Android Studio 3.5 beta 3 this setup is no longer supported.

What version of Java does Android studio support?

Android Studio supports all the same programming languages of IntelliJ (and CLion) e.g. Java, C++, and more with extensions, such as Go; and Android Studio 3.0 or later supports Kotlin and "all Java 7 language features and a subset of Java 8 language features that vary by platform version." External projects backport ...

Why is Android Studio not working?

If Studio doesn't start after an upgrade, the problem may be due to an invalid Android Studio configuration imported from a previous version of Android Studio or an incompatible plugin.


3 Answers

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.

like image 129
Noah Ternullo Avatar answered Sep 23 '22 16:09

Noah Ternullo


Try to use next values:

compileSdkVersion = "android-N" buildToolsVersion = "24.0.0 rc3" 
like image 28
Alex Evtushik Avatar answered Sep 21 '22 16:09

Alex Evtushik


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

like image 39
Angel Koh Avatar answered Sep 23 '22 16:09

Angel Koh