无法修复“ParseException: bad class file magic (cafebabe) or version (0034.0000)"; [英] Unable to fix "ParseException: bad class file magic (cafebabe) or version (0034.0000)"

查看:38
本文介绍了无法修复“ParseException: bad class file magic (cafebabe) or version (0034.0000)";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从我的 AWS 应用程序中导入了一个 jar,其中包含我将在我的 Android 应用程序上引用的所有对象.一旦它在我的 Android Studio 项目中并通过 Gradle 连接,错误就会出现并且不会消失,直到我清除我导入的 jar 并重建所有内容.

I recently imported a jar from my AWS application that contains all the objects I am going to be referencing on my Android application. As soon as that is in my Android Studio project and hooked up via Gradle, the error shows up and doesn't go away until I clear out my imported jar and rebuild everything.

我读到了什么:

这个错误可能是合法的.当 Android 应用程序的方法名称超过 65k 时,就会发生这种情况.我的应用程序可能很大,但如果我导入的所有库都超过了这个,我会感到惊讶......我不会排除它,但这是很多方法.据我所知,十分之九,这是一个配置错误.我读的前几篇文章说让 Proguard 可以删除所有未使用的方法,但这并没有帮助.

This error can be legitimate. This can happen when an Android application surpasses 65k method names. My application may be big, but I would be amazed if all the libraries I imported totaled over that.... I won't rule it out, but that is a lot of methods. From what I saw, nine times out of ten, this was a configuration bug. The first couple articles I read said to enable Proguard to remove all unused methods, but that didn't help.

我的配置:

我已将 Android Studio 环境中的所有内容设置为运行 Java 7:

I have everything on my Android Studio environment set to run Java 7:

  • 项目字节码版本:1.7
  • JDK 位置:C:\Program Files\Java\jdk1.7.0_45

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.maveric.helloworld"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:4.2.42'
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'org.apache.commons:commons-io:1.3.2'
    compile 'com.cedarsoftware:json-io:4.3.0'
}

在过去的 5 个小时里,我在 SO 上尝试了每一个解决方案,但对其中任何一个都没有一点运气.

I have spent the last 5 hours trying every single solution on SO, and haven't had a single bit of luck with any of them.

推荐答案

经过 6 个多小时的尝试解决方案,Oleg 在评论中链接我的人终于让我找到了问题的真正原因.

After over 6 hours of trying solutions, the one Oleg linked me in the comments finally led me to the real cause of the problem.

问题的简要说明可以在这里找到,但我将尝试解释我系统上的所有内容:

The brief explanation of the issue can be found HERE, but I will try to explain how everything looked on my system:

当我导入作为主 Java 项目一部分的 jar 文件时,这个错误首先出现在我身上,该项目托管在 Eclipse 中.

This error first showed up for me when I imported a jar file that was part of my main Java project, which was hosted in Eclipse.

此错误首先向用户提示的方式是通过消息选项卡,Gradle 会在该选项卡中遍历其每个任务.它崩溃的任务是

The way this error first pokes up to the user is through the Messages tab where Gradle walks through each of its tasks. The task that it crashes on is

:app:transformClassesWithDexForDebug

问题是 Gradle Messages 窗口只是说任务失败,然后给出了一个非描述性的错误消息说

The problem is the Gradle Messages window just says the task failed and then gives a non-descriptive error message saying

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 1

为了获得更好的视图,您需要查看 Gradle 控制台视图.终端视图中的文本告诉您:

In order to get a better view, you need to go look at the Gradle Console view. The text in the terminal view tells you this:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

向上滚动一点表明堆栈跟踪通过得很好,即使这个初始消息暗示应该添加额外的标志用于调试.堆栈跟踪的顶部是这样说的:

Scrolling up a little bit shows that the stacktrace came through just fine, even though this initial message hints that there should be additional flags added for debugging. The top of the stacktrace says this:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

但即便如此也无济于事.它试图告诉您(我不得不补充说的非常糟糕)它正在查看的类是用不受支持的 Java 版本编译的.就我而言,版本 (0034) 是 52 的十六进制表示,这意味着 Java 8.Android 不支持 Java 8,因此它终止了构建.

But even that doesn't help very much. What it is trying to tell you (very poorly I have to add) is that the class it is looking at was compiled with a Java version that is not supported. In my case, version (0034) was the hex representation of 52 which means Java 8. Android doesn't support Java 8, so it terminates the build.

解决方案是返回到我的 Eclipse 项目并导出 jar 文件,并将编译器设置为 1.7 版,现在一切都已启动并再次运行.我希望这会有所帮助!

The solution was to go back to my Eclipse project and export the jar file with the compiler set to version 1.7 and now everything is up and running again. I hope this helps!

这篇关于无法修复“ParseException: bad class file magic (cafebabe) or version (0034.0000)";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆