版权声明:本文为吴孔云博客原创文章,转载请注明出处并带上链接,谢谢。 https://cloud.tencent.com/developer/article/1347536
下载JDK,可到以下oracle官网下载:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
需要选择对应的版本,选择jdk-8u111-macosx-x64.dmg,然后双击安装!!!
注:这个地方一定要1.8的版本或以上,否则在 cordova build android 的时候会出现 UnsupportedClassVersionError
/usr/libexec/java_home -V
如下:
WuKongyun:~ wukongyun$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_131, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
修改$HOME目录下的.bash_profile文件,如下:
export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/wukongyun/OpensourceInstall/android-sdk-macosx
export PATH=${PATH}:/Users/wukongyun/OpensourceInstall/android-sdk-macosx/platform-tools:/Users/wukongyun/OpensourceInstall/android-sdk-macosx/tools
如果没有.bash_profile, touch新建一个
写入之后执行命令:source .bash_profile 配置生效或者重新打开terminal.然后查看java和javac命令是否执行成功,执行java -version; javac -version;如下:
WuKongyun:~ wukongyun$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
/Users/wukongyun/OpensourceInstall/android-sdk-macosx/tools/android
需安装的包有6个,如图