我刚刚切换到Android Studio 2.1,当尝试编译之前正在运行的应用程序时出现此错误:
Run Code Online (Sandbox Code Playgroud)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.
我已经更新了主项目的gradle.build文件以强制生成Java 1.7代码:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
}
Run Code Online (Sandbox Code Playgroud)
我还更新了gradle.build模块,如下所示设置java版本:
android …Run Code Online (Sandbox Code Playgroud)