Android:Dex无法解析版本52字节的代码 [英] Android: Dex cannot parse version 52 byte code
问题描述
我刚刚切换到Android Studio 2.1,当尝试编译之前正在运行的应用程序时出现此错误:
I just switched to Android Studio 2.1 and this error showed up when trying to compile an app the was previously working:
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代码生成:
I had already updated the main project's gradle.build file to force Java 1.7 code generation:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
}
我还更新了模块gradle.build,如下所示设置java版本:
I had also updated the module gradle.build as follows to set the java version:
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.abc.def"
minSdkVersion 19
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
使用Maven构建的子模块。在pom.xml文件中,我也尝试强制生成1.7代码。
我明白我使用的是一个汇编工件,它包含了从属模块,但我没有更改任何从属模块和上次编译时,模块生成的.jar文件运行正常。
The submodule being built with Maven. In the pom.xml file I have also tried to force 1.7 code generation.
I understand that I am using an assembly artifact, which incorporates subordinate modules, but i have not changed any of the subordinate modules and the resulting .jar file for the module ran fine last time I compiled.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <!-- maven-compiler-plugin -->
<version>2.6</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我的问题:
1)这是Android Studio 2.1的问题吗?别人看到了吗?
2)假设这是我的错误,并且由于错误消息没有帮助找到坏模块,是否有任何关于查找V52代码的建议?我不能在不破坏大量代码的情况下省略库。可以检查一个.jar文件来查找代码修订版吗?
提前致谢。
-Hephaestus
My question: 1) Is this an Android Studio 2.1 problem? Have others seen it? 2) Assuming this is my error and since the error message gives no help in finding the bad module, are there any recommendations on finding the V52 code? I can't just omit the libraries without breaking large amount of code. Can one inspect a .jar file to find the code revision? Thanks in advance. -Hephaestus
推荐答案
只需使用带有Android Studio 3.0+的java 1.8并为我设置以下作品:
似乎需要最新的构建工具
just use java 1.8 with Android Studio 3.0+ and set following works for me: it seems need the latest build tools
classpath 'com.android.tools.build:gradle:3.0.0'
和
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
...
//jackOptions { // DEPRECATED
//enabled true
//}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
这篇关于Android:Dex无法解析版本52字节的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!