【发布时间】:2016-08-29 11:01:54
【问题描述】:
我刚切换到 Android Studio 2.1,在尝试编译以前可以运行的应用程序时出现此错误:
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
}
}
我还更新了模块 gradle.build 如下设置 java 版本:
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 文件运行良好。
<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 文件以找到代码修订版吗? 提前致谢。 -赫菲斯托斯
【问题讨论】:
-
我现在正面临这个错误。有解决办法吗?
-
我也将 Android Studio 更新到 2.1。从那时起,我就面临着这个问题。你有什么解决办法吗?
-
较早的错误消息(此后已消失)表明 pubnub jar 文件是问题的一部分。所以我们注释掉了对 pubnub 的所有引用,它现在可以编译并运行。我相信当我们添加编译器指令(如上所示)以强制代码为“1.7”时错误消息消失了,但似乎一些 1.8 代码仍在泄漏。
-
这是另一个相关的 SO 讨论:stackoverflow.com/questions/36968728/…。但是除了说“从一个更简单的测试项目开始”之外,这并不能回答这个问题。
-
我们唯一做的就是拉出 PubNub 库并替换为旧版本。这似乎解决了它。但是在这种情况下,我们通过注释掉库导入及其方法调用并确定它有问题来进行测试。但是 PubNub 库是松散集成的,我们可以很容易地注释掉它。如果我们有许多紧密集成的库,那会很痛苦。
标签: java android maven android-studio