DiyCode icon indicating copy to clipboard operation
DiyCode copied to clipboard

Dex cannot parse version 52 byte code

Open gongzelong0718 opened this issue 8 years ago • 7 comments

Information:Gradle tasks [:app:assembleDebug]
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:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process

AS: 2.3.2 Gradle Plugin version: 2.2.3 Gradle version: 3.3 or 2.14.1

gongzelong0718 avatar Aug 23 '17 09:08 gongzelong0718

image 你的 JDK 版本是 1.7 么?如果是的话,换成 1.8 试试 我这里的版本是 Android Studio 自带的

openjdk version "1.8.0_112-release"
OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
OpenJDK 64-Bit Server VM (build 25.112-b06, mixed mode)

plusend avatar Aug 23 '17 11:08 plusend

screen shot 2017-08-23 at 8 21 49 pm

我用jdk7和jdk8都试过,都会报错

➜ DiyCode git:(master) ✗ java -version java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode) ➜ DiyCode git:(master) ✗ setjdk 1.8 ➜ DiyCode git:(master) ✗ java -version java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

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:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process

https://stackoverflow.com/questions/37020413/android-dex-cannot-parse-version-52-byte-code

这种方法也试过,也不行(sourceCompatibility JavaVersion.VERSION_1_8)

just use java 1.8 and set following works for me: it seems need the latest build tools and using jack

android { compileSdkVersion 23 buildToolsVersion 24rc3

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

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

按报错提示修改为sourceCompatibility = '1.7',也不行

tasks.withType(JavaCompile) { sourceCompatibility = "1.7" targetCompatibility = "1.7" } or add this in dependencies

sourceCompatibility = 1.7
targetCompatibility = 1.7

in all modules manually

gongzelong0718 avatar Aug 23 '17 12:08 gongzelong0718

您的是Mac系统是什么版本呢?其他的版本和我的也是一样的么?

AS: 2.3.2 Gradle Plugin version: 2.2.3 Gradle version: 3.3 or 2.14.1

gongzelong0718 avatar Aug 23 '17 12:08 gongzelong0718

版本信息在工程里的 build.gradle 里都有啊,master 分支和 dev 分支里都有,如果 master 分支里的编译不了,你可以试试 dev 里的,dev 分支里的版本比较新。

// gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
classpath 'com.android.tools.build:gradle:2.3.3'

// android studio & java version
Android Studio 2.3.3
Build #AI-162.4069837, built on June 6, 2017
JRE: 1.8.0_112-release-b06 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

plusend avatar Aug 24 '17 01:08 plusend

Information:Gradle tasks [:app:assembleDebug]
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:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/Users/gongzelong/.android/build-cache/955ac80aaf93fdf0864980a6cd3d1375a86516bc/output/jars/classes.jar' to '/Users/gongzelong/Android/mature/DiyCode/app/build/intermediates/pre-dexed/debug/classes_9c88e795cbd10f8d6cb06b03f21dca48a671c22e.jar'
Information:BUILD FAILED
Information:Total time: 10.688 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console

It failed on dev branch too. Thanks for your update, I will check later.

➜  DiyCode git:(dev) java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

After I change to jdk 1.7

➜  DiyCode git:(dev) setjdk 1.7
➜  DiyCode git:(dev) java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
➜  DiyCode git:(dev) 
Information:Gradle tasks [:app:assembleDebug]
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:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/Users/gongzelong/.android/build-cache/955ac80aaf93fdf0864980a6cd3d1375a86516bc/output/jars/classes.jar' to '/Users/gongzelong/Android/mature/DiyCode/app/build/intermediates/pre-dexed/debug/classes_9c88e795cbd10f8d6cb06b03f21dca48a671c22e.jar'

gongzelong0718 avatar Aug 24 '17 12:08 gongzelong0718

What is your OS version? Ubuntu?

gongzelong0718 avatar Aug 24 '17 12:08 gongzelong0718

MacOS 10.12.6

plusend avatar Aug 31 '17 07:08 plusend