macos:安装java 17.0.6(android studio报错:Unable to locate a Java Runtime.)
一,报错信息:
android studio的报错信息:
The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java. Exception: Gradle task assembleDebug failed with exit code 1
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/03/macos-an-zhuang-java-17-6-android-studio-bao-cuo-unable-to/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,安装java,解决问题:
1,下载地址:
https://www.oracle.com/java/technologies/downloads/#jdk17-mac
如图:
点击下载:
下载完成后打开dmg包,如图:
执行:
三,安装完成后测试效果:
1,命令行:
liuhongdi@liuhongdideMBP ~ % java --version java 17.0.6 2023-01-17 LTS Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190) Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)
可见java命令已可运行
2,查看安装好后jdk
打开finder,
菜单->前往->前往文件夹
输入:
/Library/Java/JavaVirtualMachines/
可以看到已安装好的jdk
如图 :
四,配置java:
1,查看当前的shell
liuhongdi@liuhongdideMBP ~ % echo $SHELL /bin/zsh
说明:
如果输出/bin/zsh则使用vim ~/.zshrc打开文件,
如果输出/bin/bash则使用vim ~/.bashrc打开文件
2,编辑.zshrc
liuhongdi@liuhongdideMBP ~ % vim .zshrc
内容:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar PATH=$JAVA_HOME/bin:$PATH: export JAVA_HOME export CLASSPATH export PATH
3,测试配置效果:
liuhongdi@liuhongdideMBP ~ % source .zshrc liuhongdi@liuhongdideMBP ~ % echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home