gradle-retrolambda icon indicating copy to clipboard operation
gradle-retrolambda copied to clipboard

Android Studio 0.9.1, OSX, JDK8 not found

Open pakoito opened this issue 9 years ago • 15 comments

This is my current configuration:

Module's build.gradle:

apply plugin: 'retrolambda'

retrolambda {
    jdk System.getenv("JAVA8_HOME")
    oldJdk System.getenv("JAVA6_HOME")
    javaVersion JavaVersion.VERSION_1_6
}

System env

dhcp-159-104-130-193:~ me$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
dhcp-159-104-130-193:~ me$ echo $JAVA8_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

AS GUI config:

JDK Location: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

And it's still not finding it due to:

Error:Execution failed for task ':mobile:patchAndroidJar'.
> Retrolambda: null/jre/lib/rt.jar does not exist, make sure that the environment variable JAVA_HOME or JAVA8_HOME, or the gradle property retrolambda.jdk points to a valid version of java8.

pakoito avatar Nov 05 '14 19:11 pakoito

I found a workaround by going to Android Studio -> Preferences -> Path Variables and adding

JAVA_8 /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

pakoito avatar Nov 06 '14 14:11 pakoito

Unfortunately this didn't fix the above error for me. Any other steps you may have done? Android Studio 0.9.2, Gradle 2.1, OSX

image image

retrolambda {
    jdk System.getenv("JAVA_8") //have tried with JAVA8_HOME
    oldJdk System.getenv("JAVA7_HOME") //have tried with JAVA6_HOME
    javaVersion JavaVersion.VERSION_1_7 //have matched the above with VERSION_1_6
    jvmArgs '-arg1', '-arg2'
}

Same error

Error:Execution failed for task ':proj:patchAndroidJar'.
> Retrolambda: null/jre/lib/rt.jar does not exist, make sure that the environment variable JAVA_HOME or JAVA8_HOME, or the gradle property retrolambda.jdk points to a valid version of java8.

MaximusMcCann avatar Nov 29 '14 12:11 MaximusMcCann

Below is my current, ugly-hardcoded, solution :(

retrolambda {
    jdk '/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home'//System.getenv("JAVA_8")
    oldJdk System.getenv("JAVA7_HOME")
    javaVersion JavaVersion.VERSION_1_7
}

MaximusMcCann avatar Nov 29 '14 13:11 MaximusMcCann

My solution for it.

String java8 = getJavaVersion(8)
String java7 = getJavaVersion(7)
retrolambda {
    jdk java8 //have tried with JAVA8_HOME
    oldJdk java7 //have tried with JAVA6_HOME
    javaVersion JavaVersion.VERSION_1_7 //have matched the above with VERSION_1_6
}

String getJavaVersion(Integer v) {
  def sout = new StringBuffer()
  def proc = "/usr/libexec/java_home -v 1.$v".execute()
  proc.consumeProcessOutput(sout, new StringBuffer())
  proc.waitForOrKill(1000)
  return sout.toString().replace("\n", "").replace("\r", "")
}

stepango avatar Dec 11 '14 07:12 stepango

Please check this if it is helpful: http://stackoverflow.com/a/27795843/1592410

mrjohannchang avatar Jan 06 '15 09:01 mrjohannchang

On OSX we had to use @stepango 's VERY CREATIVE workaround. Thanks for your snippet, it just ended an hour of nonsense for us. This is pretty crazy! Tried setting environment variables every way under the sun and couldn't get anything working. Tried the .bashrc the .bash_profile the /etc/profile the .profile , Path Variables in Android Studio etc. Seems like it shouldn't be this hard.

z-br avatar May 27 '15 23:05 z-br

Ditto: On OSX we had to use @stepango 's VERY CREATIVE workaround. THANK YOU!! This is also preferable to us as we want to have Jenkins CI automated builds, and this workaround only requires that one install JDK8 before utilizing. Very modular. :D

free5ty1e avatar Jul 15 '15 17:07 free5ty1e

Thanks @stepango, worked for us!

mtrewartha avatar Jul 23 '15 15:07 mtrewartha

I have another work around for this issue, that might be helpful. We couldn't use @stepango workaround as our projects has a variety of development machines and a CI server. Our solution uses a gradle.properties file and is outlined in this blog post:

http://andersmurphy.com/2015/09/16/setting-up-retrolambda/

Hope that helps.

andersmurphy avatar Sep 16 '15 20:09 andersmurphy

@andersmurphy The guide you provided worked great! Thank you for the hard work. Wanted to make a simple suggestion. Maybe make the following part a bit more clear as it can be confusing for some users: "Note: If you are building your project with Java 8 you only need to add oldJdk JAVA7_HOME. If you are building your project with Java 7 you only need to add jdk JAVA8_HOME."

Thanks again and keep up the wonderful work.

Mithrandir21 avatar Sep 22 '15 10:09 Mithrandir21

@Mithrandir21 Good to hear it worked for you and thanks for the feedback. I'll try and clear that confusing section up.

andersmurphy avatar Sep 22 '15 10:09 andersmurphy

@andersmurphy Thanks buddy... looks like this is the only thing that works with macosx :( Thanks again :+1:

logrish avatar Oct 08 '15 12:10 logrish

thanks so much~~!

zhangxiaofan918 avatar Oct 27 '15 10:10 zhangxiaofan918

Editing /etc/environment as follows and rebooting Ubuntu made it work for me. Otherwise Gradle wouldn't pick up the environment variables, not sure why. $ cat /etc/environment JAVA_HOME=/usr/lib/jvm/java-8-oracle JAVA7_HOME=/usr/lib/jvm/java-7-oracle JAVA8_HOME=/usr/lib/jvm/java-8-oracle

azgul avatar Dec 18 '15 21:12 azgul

@stepango worked for me thanks!

Rock610 avatar Mar 23 '16 09:03 Rock610