Android studio(2016年4月28日,2.1.1)将字节码转换为dex时发生奇怪的错误. Dex无法解析版本52字节代码 [英] Android studio(2.1.1 April 28-2016) Strange Error converting bytecode to dex. Dex cannot parse version 52 byte code

查看:84
本文介绍了Android studio(2016年4月28日,2.1.1)将字节码转换为dex时发生奇怪的错误. Dex无法解析版本52字节代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建项目并遇到这个奇怪的错误(因为所有错误在以前的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上搜索了类似的问题(例如一个),但添加此行来建立gradle

dependencies {

sourceCompatibility = 1.7
targetCompatibility = 1.7
}

不能解决我的问题.我很困,我需要别人的帮助.预先感谢.

解决方案

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

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

I'm trying to build my project and get this strange error (cause all worked perfectly in previous AS versions)

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.

I understand that the problem is that (as the error tells me) some of my dependencies was compiled with java ver.8 but how I know which one of them?

Here is my 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'
}

I've googled alredy similar questions on SO (like this one or this) but adding this lines to build gradle

dependencies {

sourceCompatibility = 1.7
targetCompatibility = 1.7
}

didn't solve my problem. I am pretty stuck and I need someone help. Thanks in advance.

解决方案

Your problem is compile('com.thoughtworks.xstream:xstream:1.4.8') that depends on Java 8

Version 1.4.7 doesn't depend on Java8, so if you can live with 1.4.7 the fix is quite simple.

这篇关于Android studio(2016年4月28日,2.1.1)将字节码转换为dex时发生奇怪的错误. Dex无法解析版本52字节代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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