簡體   English   中英

Android:運行 androidTest(Espresso 測試)時,Dex 無法解析 52 字節代碼

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

當我嘗試運行 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

這是我的 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'
     }

}

但是,當我構建並運行項目(主要源代碼)時,它運行起來沒有任何問題。

您需要正確設置 Dagger,否則您會得到准確的錯誤消息。 更換你的匕首設置如下:

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

對我來說它適用於匕首 2.8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM