Accepted answer

cordova ionic framework error: Dex: Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code



Version 52 byte code corresponds to Java 8, you need to add below to your app/build.gradle to make your project be compatible with Java 8.

android {
    ...
    defaultConfig {
        jackOptions {
            enabled true
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ...
}

"Android: Dex cannot parse version 52 byte code"

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.

Answer:

faced same error in Android 2.3.3, after adding few JAR depencies. Problem was due to the depenecy io.netty:netty-all:4.1.16.Final. This 4.1.16 version JAR was compiled with Java 1.8 and all others was generated with Java 1.7.

This get resolved, after including older version of netty(which was generated with Java 1.7) in my build.gradle file.

compile 'io.netty:netty-all:4.1.5.Final'




If you have a module with a java library that is not Android-specific, this should work: apply plugin:'java'

Put it at the top of the build.gradle file, then rebuild.

    apply plugin: 'java'
    apply plugin: 'jacoco'

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.11'

        sourceCompatibility = 1.7
        targetCompatibility = 1.7
    }

ust use java 1.8 with Android Studio 3.0+ and set following works for me: it seems need the latest build tools

classpath 'com.android.tools.build:gradle:3.0.0'

and

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        ...        
        //jackOptions { // DEPRECATED
            //enabled true
        //}
    }
    dexOptions {
        incremental true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

solved this problem as belowed :

apply plugin: 'java'

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

"Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code"

 The problem was that this library (compile 'com.myhexaville:smart-image-picker:1.0.4') gave conflict. When I removed it everything worked finally.


Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version. You can also configure it directly in the corresponding build.gradle file:

android {
  ...
  // 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
  }
}


Add in gradle.property this line:

org.gradle.jvmargs=-Xmx1024m

After that clean and rebuild the project.

error converting bytecode to dex- ionic framework solution


Remove Android platform:

cordova platform remove android

Added latest Android platform (7.1.4):

cordova platform add android@latest

Just to note I am using Cordova 7.1.0 if that makes a difference.