Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I replace java 8 with java 7 android studio error?

why I replace JAVA 8 with JAVA 7,Android studio error?

> 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.
Error:...while parsing android/support/v7/recyclerview/R$attr.class
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.
Error:...while parsing android/support/v7/recyclerview/R$dimen.class
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.
Error:...while parsing android/support/v7/recyclerview/R$id.class
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.
Error:...while parsing android/support/v7/recyclerview/R$styleable.class 
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.
Error:...while parsing android/support/v7/recyclerview/R.class
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.
Error:...while parsing com/example/administrator/comjarlib/R$anim.class
Error:Error converting bytecode to dex:
............

I think to use retroLambda in Android Studio.

Anyone facing similar issue / resolved can give some pointer to resolve it.

I am using Android Studio 2.1 Preview 3 with grade 2.10

like image 780
allen218 Avatar asked Dec 01 '22 13:12

allen218


2 Answers

This one helped me. In your project's main build.gradle file add these lines of code into allprojects section (or add this section if it isn't there).

allprojects {

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

}
like image 107
Victor Nidens Avatar answered Dec 15 '22 16:12

Victor Nidens


If I don't get wrong gradle android plugin extends 'java' plugin, so you can just add these two lines in your "android" block in your build.gradle :

apply plugin: 'com.android.application'

android {

    targetCompatibility = '1.7'
    sourceCompatibility = '1.7'

    ...
}

Worked fine for me.

like image 29
Nicolas Bossard Avatar answered Dec 15 '22 17:12

Nicolas Bossard