简体   繁体   English

Android:运行 androidTest(Espresso 测试)时,Dex 无法解析 52 字节代码

[英]Android: Dex cannot parse 52 byte code when running androidTest (Espresso test)

I get the following error when I try to run an Espresso test and I have looked at all the SO threads on this issue but with no avail:当我尝试运行 Espresso 测试时出现以下错误,我查看了有关此问题的所有 SO 线程,但无济于事:

Dex: 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.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
    at com.android.dx.command.dexer.Main.processClass(Main.java:775)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:741)
    at com.android.dx.command.dexer.Main.access$1200(Main.java:88)
    at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683)
    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:695)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:560)
    at com.android.dx.command.dexer.Main.runMultiDex(Main.java:376)
    at com.android.dx.command.dexer.Main.run(Main.java:290)
    at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)
    at com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:173)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
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:476)
    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:787)
    at com.android.dx.command.dexer.Main.access$1600(Main.java:88)
    at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722)
    at com.android.dx.command.dexer.Main.processClass(Main.java:773)
    ... 16 more

This is my build.gradle:这是我的 build.gradle:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'

repositories {
     maven { url 'https://maven.fabric.io/public' }
}

apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        applicationId "xxx.xxxxxx.xxxx"
        minSdkVersion 19
        targetSdkVersion 23
        versionName versionName(versionMajor, versionMinor, versionPatch)
        versionCode versionCode(versionMajor, versionMinor, versionPatch)
        buildConfigField "boolean", "ENABLE_CACHE", "true"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    signingConfigs {
        // my release and debug signing configs
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            debuggable true
            signingConfig signingConfigs.debug
            buildConfigField "boolean", "DEBUG_ENABLED", 'true'
        }

        applicationVariants.all { variant ->
            def flavor = variant.mergedFlavor
            if (variant.buildType.isDebuggable()) {
                flavor.versionName = "${getVersionName()}";
            }
        }
    }

    productFlavours {
        // my product flavours here
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
    }
}


repositories {
    maven {
        url "https://urbanairship.bintray.com/android"
    }
}

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     apt 'com.google.dagger:dagger-compiler:2.0.2'
     provided 'javax.annotation:jsr250-api:1.0'
     //    compile 'joda-time:joda-time:2.3'
     compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
     }

     compile(name: 'common', ext: 'aar')
     compile(name: 'base', ext: 'aar')
     compile(name: 'jwplayer-vr-sdk-1.0.0+12', ext: 'aar')
     compile ('com.longtailvideo.jwplayer:jwplayer-android-sdk:2.4.3+160'){
         exclude group: 'com.android.support'
        exclude group: 'com.google.android.gms'
     }

     compile 'uk.co.chrisjenx:calligraphy:2.1.0'
     compile 'com.google.dagger:dagger:2.0.2'
     compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
     compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
     compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
     compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
     compile 'com.facebook.fresco:fresco:0.10.0'
     compile 'com.facebook.fresco:animated-gif:0.12.0'

     compile 'me.relex:photodraweeview:1.0.0'

     compile ('com.urbanairship.android:urbanairship-sdk:7.2.0') {
         exclude group: 'com.google.android.gms'
     }
     compile 'com.github.castorflex.verticalviewpager:library:19.0.1'
     compile 'com.android.support:appcompat-v7:23.4.0'
     compile 'com.android.support:design:23.4.0'
     compile 'com.jakewharton:butterknife:8.2.1'
     apt 'com.jakewharton:butterknife-compiler:8.2.1'
     compile 'net.danlew:android.joda:2.9.3'
     compile 'com.android.support:recyclerview-v7:23.4.0'
     compile 'com.android.support:cardview-v7:23.4.0'
     compile 'com.android.support:support-v4:23.4.0'
     compile 'com.android.support:percent:23.3.0'


     compile 'com.google.firebase:firebase-core:9.4.0'
     compile 'com.google.android.gms:play-services-auth:9.4.0'
     compile 'com.google.android.gms:play-services-ads:9.4.0'
     compile 'com.google.android.gms:play-services-gcm:9.4.0'

     compile 'com.google.android.gms:play-services-tagmanager:9.4.0'

     compile 'com.facebook.android:facebook-android-sdk:4.14.0'

     compile 'io.reactivex:rxandroid:1.1.0'
     compile 'io.reactivex:rxjava:1.1.0'
     compile 'com.android.support:multidex:1.0.1'
     compile 'com.wefika:flowlayout:0.4.1'

     //Automatic Getters and Setters, hash, etc
     provided "org.projectlombok:lombok:1.16.10"

     testCompile 'junit:junit:4.12'
     // Android instrumentation unit testing dependencies
     androidTestCompile('com.android.support.test:runner:0.4.1') {
         exclude module: 'support-annotations'
     }
     androidTestCompile('com.android.support.test:rules:0.4.1') {
         exclude module: 'support-annotations'
     }
     androidTestCompile 'junit:junit:4.12'
     androidTestCompile 'org.mockito:mockito-core:1.10.19'
     androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
     androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
     androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
          exclude group: 'com.android.support', module: 'support-annotations'
     }

}

However, when I build and run the project (main source code) it runs without any problems whatsoever.但是,当我构建并运行项目(主要源代码)时,它运行起来没有任何问题。

You need to setup dagger properly, otherwise you get exactly your error message.您需要正确设置 Dagger,否则您会得到准确的错误消息。 Replace your dagger setup as follows:更换你的匕首设置如下:

dependencies {
    compile 'com.google.dagger:dagger:2.8'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.8'
}

For me it works with dagger 2.8对我来说它适用于匕首 2.8

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:Dex无法解析版本52字节的代码 - Android: Dex cannot parse version 52 byte code Android Studio:Dex无法解析版本52字节代码 - Android studio: Dex cannot parse version 52 byte code Android错误将字节码转换为dex:原因:Dex无法解析版本52字节代码 - Android Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code 构建Cordovo Android应用程序失败-Dex无法解析版本52字节代码的错误消息 - Building Cordovo Android app fails - Dex cannot parse version 52 byte code error message cordova错误:Dex:将字节码转换为dex时出错:原因:Dex无法解析版本52字节代码 - cordova error: Dex: Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code Dex:将字节码转换为dex时出错:原因:Dex无法在统一andorid构建中解析版本52字节代码 - Dex: Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code in unity andorid build 将字节码转换为dex时出错:原因:Dex无法解析版本52字节码 - Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code 错误:将字节码转换为 dex 时出错:原因:Dex 无法解析 52 版字节码 - Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code Cordova build:将字节码转换为dex时出错:Dex无法解析版本52字节的代码 - Cordova build: Error converting bytecode to dex: Dex cannot parse version 52 byte code Android Espresso测试无法通过Dex进行调试Android测试 - Android Espresso Test Failed With Dex For Debug Android Test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM