gradle-retrolambda
gradle-retrolambda copied to clipboard
Android Studio 0.9.1, OSX, JDK8 not found
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.
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
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
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.
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
}
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", "")
}
Please check this if it is helpful: http://stackoverflow.com/a/27795843/1592410
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.
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
Thanks @stepango, worked for us!
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 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 Good to hear it worked for you and thanks for the feedback. I'll try and clear that confusing section up.
@andersmurphy Thanks buddy... looks like this is the only thing that works with macosx :( Thanks again :+1:
thanks so much~~!
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
@stepango worked for me thanks!