com.android.dx.cf.iface.ParseException:错误的类文件魔术(cafebabe)或版本(0034.0000)

时间:2015-12-09 13:59:52

标签: java android

我有一个使用Java OpenJDK7在Ubuntu上创建的JAR。我想要做的是将这个JAR包含到我的Android应用程序中。当我将JAR添加到libs文件夹并尝试运行应用程序时,我收到以下错误

com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

我读到这可以通过使用JDK 1.7来编译应用程序来解决。我这样做了,我仍然有同样的错误

Gradle console

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE :app:prepareComAndroidSupportDesign2311Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:compileDebugJavaWithJavac :app:compileDebugNdk UP-TO-DATE :app:compileDebugSources :app:transformClassesWithDexForDebug

UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.RuntimeException: Exception parsing classes   at com.android.dx.command.dexer.Main.processClass(Main.java:752)    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)    at com.android.dx.command.dexer.Main.access$1200(Main.java:85)  at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)   at com.android.dx.command.dexer.Main.processOne(Main.java:672)  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)  at com.android.dx.command.dexer.Main.run(Main.java:277)     at com.android.dx.command.dexer.Main.main(Main.java:245)    at com.android.dx.command.Main.main(Main.java:106) Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)    at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)    at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)     at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)  at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)  at com.android.dx.command.dexer.Main.parseClass(Main.java:764)  at com.android.dx.command.dexer.Main.access$1500(Main.java:85)  at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)   at com.android.dx.command.dexer.Main.processClass(Main.java:749)    ... 12 more 1 error; aborting


 FAILED

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 (x86)\Java\jdk1.7.0_79\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.

BUILD FAILED

Total time: 1 mins 5.79 secs

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.myLib"
        minSdkVersion 7
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    } }

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1' }

我正在使用Android studio 1.5

有人可以帮我修复此错误吗?

1 个答案:

答案 0 :(得分:0)

检查你的libs。

我遇到了同样的问题,因为我的一个.jar有这个导入。 " import org.apache.commons.codec.binary.Hex;" ,这是不存在的。