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

时间:2015-10-19 16:56:59

标签: android gradle android-ndk java-native-interface native

我是编程中的菜鸟,我遇到了一个我无法找到答案的问题。

我正在尝试在Android Stuido 1.3.2中编译Superpowered SDK(superpowered.com)的修改示例。 原始示例使用gradle 2.2.1编译,并且对于我当前的NDK版本它可以正常工作。但是,我希望调试器适用于本机代码,并且根据http://tools.android.com/tech-docs/new-build-system/gradle-experimental我需要gradle 2.5。

奇怪的是我收到错误" com.android.dx.cf.iface.ParseException:错误的类文件魔术(cafebabe)或版本(0034.0000)"当使用gradle 2.5进行编译时,它与旧版本一起工作正常。根据其他类似的问题,由于JAVA中存在一些链接错误,如果有多个Java版本可用(v 1.8。而不是v1.7。),但是,我只有Java 8,这适用于较旧的gradle版本

任何人都可以帮我解决这个问题吗?

我的gradle 2.2.1 build.gradle代码:

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.superpowered.frequencydomain"
    minSdkVersion 11
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = []
    }
}

task ndkBuild(type: Exec) {
    commandLine '/android/ndk/ndk-build', '-B', '-C', file('src/main/jni').absolutePath
    // Windows users:
    // commandLine 'C:\\Android\\ndk\\ndk-build.cmd', '-B', '-C', file('src/main/jni').absolutePath
}
tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

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

我的Gradle 2.5。代码是:

apply plugin: 'com.android.model.application'


model {
android {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.1"


    defaultConfig.with {
        applicationId = "com.superpowered.frequencydomain"
        minSdkVersion.apiLevel = 10
        targetSdkVersion.apiLevel = 23
    }



}

android.buildTypes {
    release {
        minifyEnabled = false
        proguardFiles += file('proguard-rules.pro')
        proguardFiles += file('proguard-android.txt')
    }
}

}



task ndkBuild(type: Exec) {
commandLine  'C:\\Users\\Dave\\AppData\\Local\\Android\\Sdk\\ndk-bundle\\ndk-build.cmd', '-B', '-C', file('src/main/jni').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}


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

另一个build.gradle文件说明了2.2.1:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

2.5。它写着:

classpath 'com.android.tools.build:gradle-experimental:0.2.0'

在第6行。除此之外它是相同的。

提前感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。在模块 build.gradle中添加compileOptions设置可以解决我的问题:

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.1"
        // ... 

    }

    compileOptions.with {
        sourceCompatibility = JavaVersion.VERSION_1_7
        targetCompatibility = JavaVersion.VERSION_1_7
    }

    // ...
}

答案 1 :(得分:0)

我也遇到过同样的问题。使用版本0.4.0的gradle-experimental插件并将Gradle更新为2.8修复了Java 8构建错误。

相关问题