0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

HomebrewでOpenJDKをインストールしたい

Posted at

はじめに

Flutterの環境構築をしていたところ、VSCodeにJDKをインストールしろと怒られました。せっかくなのでHomebrewでインストールしたいと思い、備忘録として残します

環境

  • M2 MacBook Air
  • macOS Ventura 13.2.1
  • Flutter (Channel stable, 3.7.5, on macOS 13.2.1 22D68 darwin-arm64, locale ja-JP)
  • Visual Studio Code v1.75.1

参考

手順

インストール

brew install openjdk@17

2023年2月26日現在、普通に最新版をインストールするとv19がインストールされますが、Flutterプロジェクトで使おうとすると「gradleのバージョンと合ってない」と言われてしますのでgradle v7.5が対応しているopenjdk@17をインストールします

シンボリックリンクをつなぐ

/Library/Java/JavaVirtualMachines/openjdk.jdkを参照するようですが、Homebrewでインストールしたものは/opt/homebrew/Cellar/openjdk@17/17.0.6/libexec/openjdk.jdkにあるのでシンボリックリンクでつなぎます

sudo ln -sfn /opt/homebrew/Cellar/openjdk@17/17.0.6/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

PATHを通す

.zshrcに以下を追記します

.zshrc
export JAVA_HOME=`/usr/libexec/java_home -v 17`

flutter doctorで確認する

ここまで設定できたら、一度flutter doctorできちんと設定できているか確認します

flutter doctor -v

JAVA_HOMEを変更したからか、

✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

というエラーが出ていました。書かれている通り、

flutter doctor --android-licenses

を実行するとエラーが解消されました

おわりに

間違いなどありましたらご指摘ください

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?