【问题标题】:Android studio(2.1.1 April 28-2016) Strange Error converting bytecode to dex. Dex cannot parse version 52 byte codeAndroid studio(2.1.1 April 28-2016)将字节码转换为 dex 时出现奇怪的错误。 Dex 无法解析版本 52 字节码
【发布时间】:2016-09-11 05:36:25
【问题描述】:

我正在尝试构建我的项目并得到这个奇怪的错误(因为在以前的 AS 版本中一切正常)

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

我知道问题是(正如错误告诉我的那样)我的一些依赖项是用 java ver.8 编译的,但我怎么知道它们中的哪一个?

这是我的 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {

    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.android.app.mysuperapp"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        androidTest {
            setRoot('src/test')
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    sourceCompatibility = 1.7
    targetCompatibility = 1.7

    //<!-- TestFrameWork
    testCompile 'org.robolectric:robolectric:3.1-rc1'
    androidTestCompile 'junit:junit:4.12'
    //
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'me.dm7.barcodescanner:zxing:1.8.4'
    //----Materal design libs
    compile 'com.github.rey5137:material:1.2.2'
    compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
    compile 'com.rengwuxian.materialedittext:library:2.1.4'
    compile('com.github.ganfra:material-spinner:1.1.0') {
        exclude group: 'com.nineoldandroids', module: 'library'
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    //<--
    compile 'se.emilsjolander:stickylistheaders:2.7.0'
    compile('com.thoughtworks.xstream:xstream:1.4.8') {
        exclude group: 'xmlpull', module: 'xmlpull'
    }
    //----LogBack&SLF4J
    compile 'org.slf4j:slf4j-api:1.7.21'
    compile 'com.github.tony19:logback-android-core:1.1.1-5'
    compile('com.github.tony19:logback-android-classic:1.1.1-5') {
        // workaround issue #73
        exclude group: 'com.google.android', module: 'android'
    }
    compile 'com.jakewharton:butterknife:8.0.1'
    apt 'com.jakewharton:butterknife-compiler:8.0.1'
}

我已经在 SO 上搜索过类似的问题(例如 onethis),但添加此行来构建 gradle

dependencies {

sourceCompatibility = 1.7
targetCompatibility = 1.7
}

没有解决我的问题。我很困,我需要有人帮助。提前致谢。

【问题讨论】:

    标签: android android-studio android-gradle-plugin build.gradle


    【解决方案1】:

    您的问题是 compile('com.thoughtworks.xstream:xstream:1.4.8') 取决于 Java 8

    版本 1.4.7 不依赖于 Java8,因此如果您可以使用 1.4.7,则修复非常简单。

    【讨论】:

    • @whizzzkey - 你是怎么解决的? sebas - 你怎么知道哪个包不依赖于 JAVA 8?
    • @dazza5000 我的项目不依赖于 Java8,但是当我更新了一些库并在这个问题中遇到错误时,我不得不开始恢复更新,直到找到罪魁祸首。这里有更多信息:xstream.10960.n7.nabble.com/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 2018-04-09
    相关资源
    最近更新 更多