2016-10-07 57 views
1

當我嘗試運行Espresso測試時,出現以下錯誤,並且我看到了所有關於此問題的SO線程,但無濟於事:Android:運行androidTest(Espresso測試)時,Dex無法解析52字節代碼

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:[email protected]') { 
     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' 
    } 

} 

然而,當我建立和運行項目(主源代碼),它在運行時不得以任何問題。

回答

1

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

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

對我來說,它的工作原理與匕首2.8

+0

如此看來,''com.google.dagger:匕首編譯:2.8''包含Java 8(52字節碼)並且不能由dex編譯。幸運的是,你幾乎不需要編譯'dagger-compile' –

相關問題