无法修复"ParseException:错误的类文件魔术(cafebabe)或版本(0034.0000)" [英] Unable to fix "ParseException: bad class file magic (cafebabe) or version (0034.0000)"

查看:755
本文介绍了无法修复"ParseException:错误的类文件魔术(cafebabe)或版本(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.

有关此问题的简要说明,请参见 HERE ,但我将尝试解释系统上的所有内容:

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 Console视图.终端视图中的文本告诉您:

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.

向上滚动一点,表明stacktrace顺利通过,即使此初始消息暗示应添加其他用于调试的标志. stacktrace的顶部表示:

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的十六进制表示形式,表示Java8.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项目,并在编译器设置为1.7版本的情况下导出jar文件,现在一切正常并再次运行.我希望这会有所帮助!

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:错误的类文件魔术(cafebabe)或版本(0034.0000)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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