我使用以下命令在MacBook Air上安装了JAVA
:
$ brew cask install java
发现所有假定位于/bin
中的文件都存储在另一个名为/Commands
的文件夹中,其路径如下:
/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands
因此,我将JAVA_HOME
定义如下:
// Opened .bash_profile file
Hasans-Air:~ h_ajsf$ sudo code $HOME/.bash_profile
// Add the below to the .bash_profile file
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands
//Saved the file
//Updated env by:
Hasans-Air:~ h_ajsf$ source $HOME/.bash_profile
//Check for JAVA_HOME
Hasans-Air:~ h_ajsf$ echo $JAVA_HOME
/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands
然后在运行flutter doctor
来检查所有设置是否正确时,出现以下错误:
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3) ✗ Cannot execute /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/bin/java to determine the version
这意味着Flutter
正在寻找$JAVA_HOME/bin
我没有空的!如何使Flutter
忽略/bin
或如何使brew cask
考虑添加/bin
一个朋友建议删除openJDK:
Hasans-Air:~ h_ajsf$ brew cask uninstall java --force
然后将其替换为java8,并按照here的说明将JAVA_HOME设置为:
Hasans-Air:~ h_ajsf$ brew tap caskroom/versions
Hasans-Air:~ h_ajsf$ brew search "java*"
Hasans-Air:~ h_ajsf$ brew cask info java8
Hasans-Air:~ h_ajsf$ brew cask install java8
// Opened .bash_profile file
Hasans-Air:~ h_ajsf$ sudo code $HOME/.bash_profile
// Add the below to the .bash_profile file
export JAVA_HOME=$(/usr/libexec/java_home)
// Save the file
// Refresh the environment variables
Hasans-Air:~ h_ajsf$ source $HOME/.bash_profile
//Check for JAVA_HOME
Hasans-Air:~ h_ajsf$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
但是我想真正使用openJDK
。