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

来源:互联网 发布:为什么淘宝助理打不开 编辑:程序博客网 时间:2024/06/06 00:07

前两天使用Dagger2写一个小Demo时,编译正常,但是在安装的时候就报错了,错误如下:

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.

当时就想WTF,编译得时候还是好好的,怎么就出错了呢?当时就引入了Dagger2一个库:

compile 'com.google.dagger:dagger:2.10-rc1'annotationProcessor 'com.google.dagger:dagger-compiler:2.10-rc1'

行吧,你说我引入的library使用的是Java8编译,要更换到Java7,我按你说的来,在gradle文件中添加:

 compileOptions {    sourceCompatibility JavaVersion.VERSION_1_7    targetCompatibility JavaVersion.VERSION_1_7 }

这下总该是好了吧,编译运行,还是一样的错误。真是百思不得其解,那就求救大神吧,在StackOverFlow上看到大神说,要添加jack编译器为true(Android N 开始google采用自己的全新的Jack & Jill编译器):

jackOptions{    enable true}

然而,结果还是一样的让人蛋疼。当时想,为什么之前使用Dagger2的时候没有出现这样的错误,试试之前的版本,把daggger的依赖版本改为2.9,编译运行,Perfect!

我猜想,可能是2.10-rc1这个版本采用JAVA8编写的,然而编译的时候采用jack编译器编译的时候,由于某些原因,只能在Java7上运行,当然这只是猜测,有时间得去研究研究编译器的编译原理。

2 0
原创粉丝点击