Help us understand the problem. What is going on with this article?

gradle-retrolambdaを使ってビルドした時に `you must set the path to jdk8` エラーが出た時の対処法

More than 3 years have passed since last update.

retrolambdaの導入でgradle-retrolambdaを使った時に、以下のエラーが出た時の対処法です。

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> 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

※ コマンドはMacの場合だけしか書いてません。すみません。。。

1. java8がインストールされているか

Macの場合、 /usr/libexec/java_home -V で確認できるはずです。
Java8がなかったらOracleのページからインストールしましょう。

% /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    1.7.0_71, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
    1.6.0_65-b14-462, x86_64:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

2. JAVA8_HOMEが設定されているか

echo $JAVA8_HOME で確認しましょう。

% echo $JAVA8_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/

もしセットされていなければセットしましょう。

export JAVA8_HOME=`/usr/libexec/java_home -v 1.8`

3. gradleで JAVA8_HOME が読み取れているか

println で、 System.getenv("JAVA8_HOME") の値がちゃんと読めているか確認します。

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

android {
    ...
}

retrolambda {
    println("***************** ---------- *******************")
    println("JAVA8_HOME: " + System.getenv("JAVA8_HOME"))
    println("***************** ---------- *******************")
    jdk System.getenv("JAVA8_HOME")
    defaultMethods true
}

dependencies {
    ...
}

もしnullだとしたら、AndroidStudioに環境変数を渡せていないです。

***************** ---------- *******************
JAVA8_HOME: null
***************** ---------- *******************

launchctl で、環境変数を渡してやります。AndroidStudioに環境変数を渡す を参考に。

launchctl setenv JAVA8_HOME $JAVA8_HOME
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした