Android studio 添加jar后编译报错

添加了一个mysql-connector-java-5.1.38-bin.jar
然后编译就报错了
错误信息如下:
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
:app:transformClassesWithDexForDebug FAILED

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_66\bin\java.exe'' finished with non-zero exit value 1

从报错的英文上看,应该是项目是基于java1.8或者以上的,但是导的jar包是基于1.7的,所以会报错。可以修改项目的java版本到1.7再试一下。

targetCompatibility = '1.7'
sourceCompatibility = '1.7'

在工程根目录的build.gradle中添加:allprojects {
repositories {
jcenter()
}
tasks.withType(JavaCompile) {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
}

同样遇到这个问题,改了也无效,正在找办法

大神啊,这个问题是怎么解决的啊

jdk版本的问题,as新版本都是默认jdk1.8,调试以下jdk版本,as1.5支持jdk1.7

这个问题有解决了的么?大神求助

出现这个现象的原因是你的jar包是基于jdk 1.8的,但当前AS(2.3.1)默认使用的jdk是1.7的。添加如下两句话,使你的项目适配JDK1.8。
图片说明

英文好的朋友可以参见:
http://stackoverflow.com/questions/37020413/android-dex-cannot-parse-version-52-byte-code