Android: Dex cannot parse 52 byte code when running androidTest (Espresso test)
<p>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: </p>

<pre><code>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
</code></pre>

<p>This is my build.gradle:</p>

<pre><code>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 -&gt;
            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'
     }

}
</code></pre>

<p>However, when I build and run the project (main source code) it runs without any problems whatsoever.</p>