1

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

StuStirling
  • 15,601
  • 23
  • 93
  • 150

2 Answers2

3

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.

Anand Singh
  • 5,672
  • 2
  • 23
  • 33
  • 1
    Thanks for sharing your grade file. Following your "FYI" I changed mine back to JDK1.7 and have added my latest problems to the original question – StuStirling Aug 10 '15 at 12:39
  • Also you still have multiDexEnabled? – StuStirling Aug 10 '15 at 12:40
  • no, im my project `multiDexEnabled true` is disabled. If you are not getting multiDex error. do not use it. – Anand Singh Aug 10 '15 at 12:49
  • 1
    I have added the retrolambda tag along with setting jdk tag but the problem is it can't find the JAVA8_HOME environment variable even though when I type `echo $JAVA8_HOME` in the terminal it comes up correctly – StuStirling Aug 10 '15 at 13:19
  • @DiscoS2 re-start android studio again and try. – Anand Singh Aug 10 '15 at 13:22
  • 1
    @DiscoS2 If you are under a mac computer it does not work, you have to hardcode like: jdk '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home' – powder366 Sep 22 '15 at 17:44
0

This is how I have configured my OSx environment,

  1. install latest java 8

  2. edit your .bash_profile (located in your home directory) and add this lines:

    export JAVA_HOME=/usr/libexec/java_home export JAVA7_HOME=/usr/libexec/java_home -v 1.7

*now "java -version" command must shows java 1.8, but retrolambda can also access to java 7 home directory.

  1. add these lines to your project build.gradle file:

    dependencies { ... classpath 'me.tatarka:gradle-retrolambda:3.2.5' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

  2. apply retrolambda plugin to your android app module build.gradle:

    apply plugin: 'me.tatarka.retrolambda'

*there is no need to add retrolambda compile dependencies to this module.

Mohsen Mirhoseini
  • 8,454
  • 5
  • 34
  • 59
  • I think you have an error here? java -version shows 1.7. Did you mean to set home to 1.8? – StarWind0 Jan 17 '17 at 03:16
  • By installing the latest version and setting javahome and path, it would become 1.8 automatically. – Mohsen Mirhoseini Jan 17 '17 at 06:31
  • Unfortunately I think you are incorrect. Least in my case this did not happen.. The reason may be that I had already set javahome in my bash profile. I fixed it be editing ~/.bash_profile to export JAVA_HOME=$"/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre" It does not "automatically" set it. Again in my case where it was already set.. – StarWind0 Jan 17 '17 at 07:00