Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 2.1 Error converting bytecode to dex

I am getting the following error since I updated the android studio from 2.0 to 2.1.

Error:Error converting bytecode to dex:

Cause: Dex cannot parse version 52 byte code. This is caused by library dependencies that have been compiled using Java 8 or above. If you are using the 'java' gradle plugin in a library submodule add targetCompatibility = '1.7' sourceCompatibility = '1.7' to that submodule's build.gradle file.

I tried adding the following snippet in build.gradle, but still the issue persists

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

I saw some of the questions similar to this, but neither of the questions answered. Can anyone help me to solve this? Thanks in advance.

like image 499
Suresh Kumar Avatar asked May 07 '16 05:05

Suresh Kumar


3 Answers

Possibile duplicate of Android: Dex cannot parse version 52 byte code. The most quoted answer solved the problem for me.
I added compileOptions and jackOptions as shown below to my build.gradle to use JDK 1.8.

android {
    ...
    defaultConfig {
        ...        
        jackOptions {
            enabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
like image 107
Matteo Milesi Avatar answered Oct 20 '22 17:10

Matteo Milesi


Try

allprojects {
    tasks.withType(JavaCompile) {
        sourceCompatibility = "1.7"
        targetCompatibility = "1.7"
    }
}

in the main build.gradle file

like image 33
sbeliakov Avatar answered Oct 20 '22 18:10

sbeliakov


Remove the dependencies from build.gradle, comment relevant code and then compile and clean your project.

After a successful clean add the dependencies again and uncomment what you commented after removing the dependencies earlier.

like image 2
AndroidMechanic - Viral Patel Avatar answered Oct 20 '22 17:10

AndroidMechanic - Viral Patel