【问题标题】:gradle 2.5 com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)gradle 2.5 com.android.dx.cf.iface.ParseException:坏类文件魔法(cafebabe)或版本(0034.0000)
【发布时间】:2015-10-19 16:56:58
【问题描述】:

我是编程菜鸟,但我遇到了一个我找不到答案的问题。

我正在尝试在 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。

奇怪的是,当使用 gradle 2.5 编译时,我收到错误“com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)”旧版本很好。根据其他类似的问题,这是由于 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 行。除此之外,它是相同的。

提前感谢您的帮助!

【问题讨论】:

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


    【解决方案1】:

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

    model {
        android {
            compileSdkVersion = 23
            buildToolsVersion = "23.0.1"
            // ... 
    
        }
    
        compileOptions.with {
            sourceCompatibility = JavaVersion.VERSION_1_7
            targetCompatibility = JavaVersion.VERSION_1_7
        }
    
        // ...
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多