Retrolambda Requirement for Java 8 Causing :mobile:dexDebug' Exception

StuStirling picture StuStirling · Aug 10, 2015 · Viewed 7.5k times · Source

Having big problems trying to get retrolambda working in my project. There are plenty of sex issues and solutions out there but I haven't found any that doesn't resort to adding the multiDexEnabled flag to the grade file.

I am getting the following error.

Error:Execution failed for task ':mobile:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

To fix this I can add the multiDexEnabled true and this works however it also adds 1 minute onto my build time and this is unacceptable for development.

Is there another way or should I just not use Retrolambda?

EDIT Added build.grade code.

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.myapplication"
    multiDexEnabled true
    minSdkVersion 11
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

buildscript {
repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    classpath 'me.tatarka:gradle-retrolambda:3.2.0'
}
}
repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.google.android.gms:play-services-wearable:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'

compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'

compile 'com.android.support:support-annotations:22.2.1'

compile 'com.jakewharton:butterknife:7.0.1'
compile 'joda-time:joda-time:2.7'
/*Graphs*/
compile 'com.androidplot:androidplot-core:0.6.1'
/*Parse*/
compile project(':ParseLoginUI')

/*Images*/
compile 'com.squareup.picasso:picasso:2.3.3'
compile 'com.makeramen:roundedimageview:2.1.0' // https://github.com/vinc3m1/RoundedImageView
compile 'io.reactivex:rxandroid:0.25.0'
}

EDIT After changing my JDK Version to 1.7 Error

Error:Execution failed for task ':activity-manager:compileDebugJava'.

When running gradle with java 5, 6 or 7, you must set the path to jdk8, either with property retrolambda.jdk or environment variable JAVA8_HOME

So in my .bash_profile I set the environment variables like so:

export JAVA_HOME=$(/usr/libexec/java_home)
export JAVA8_HOME=$(/usr/libexec/java_home)
export JAVA7_HOME=$(/usr/libexec/java_home -v 1.7)

Now when I do the following in termainal echo JAVA8_HOME it comes up with the correct path however my Gradle still doesn't pick it up. I am testing it like so in my grade file.

println("***************** ---------- *******************")
    println("JAVA_HOME: " + System.getenv("JAVA_HOME"))
    println("JAVA7_HOME: " + System.getenv("JAVA7_HOME"))
    println("JAVA8_HOME: " + System.getenv("JAVA8_HOME"))
    println("***************** ---------- *******************")

The result is null for all of these outputs.

EDIT I have also overridden the retrolambda tag with the following.

retrolambda {

    jdk "/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home"
    oldJdk "/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home"
    javaVersion JavaVersion.VERSION_1_7

} 

I then go back to getting the original exception with the "finished with non-zero exit value 2" but now with the JDK version set in the project settings.

Error:Execution failed for task ':mobile:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

Answer

Anand Singh picture Anand Singh · Aug 10, 2015

In my project it is working fine, This is my build.gradle code:

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

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
        classpath "me.tatarka:gradle-retrolambda:3.2.0"
    }

}

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "xyz.com"
        minSdkVersion 22
        targetSdkVersion 22

        multiDexEnabled true


        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }

        dexOptions {
            jumboMode = true
        }

        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:appcompat-v7:21.0.3'
}

FYI: I have selected C:\Program Files\Java\jdk1.7.0_79 in File >> Project Structure >> SDK Location JDK Location.