在我们使用Android studio开始时,常常需要导入别人的项目,由于使用的JDK不统一,常常会显示如下的错误:
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.
对于这种错误,我们常用的解决办法如下:
在项目的build.gradle(注意不是工程的文件夹下)文件夹下添加如下代码,就可以轻松解决问题:
1、在defaultConfig {}中添加
jackOptions{
enabled = true
}
2、在android {}添加
compileOptions{
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
为了防止在实际添加时,位置错误,整体的 添加效果如下:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.scth.xk.targetservice"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//添加如下代码
jackOptions{
enabled = true
}
}
//添加如下代码
compileOptions{
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
至此问题便解决了