一、获取调试版安全码SHA1
1.进入当前用户文件夹下的~/.android目录
bash
cd ~/.android
2.查看 debug.keystore
bash
ls
3.运行 debug.keystore
bash
keytool -list -v -keystore debug.keystore
这里报错:
bash
The operation couldn't be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
java --version
查看,也报错:
bash
The operation couldn't be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
解决方法(安装java jdk):
bash
##切换到压缩包目录下
cd ~/Downloads
##将 JDK 解压到 macOS 上用于存储 Java 虚拟机的默认文件夹/Library/Java/JavaVirtualMachines
sudo tar xzf openjdk-21.0.1_macos-x64_bin.tar.gz -C /Library/Java/JavaVirtualMachines
##查看java版本
java --version
官网地址 https://www.java.com/zh-CN/
安装教程https://www.andrewhoog.com/post/3-ways-to-install-java-on-macos-2023/
报错已解决,再次运行keytool -list -v -keystore debug.keystore
,密钥库口令默认为android
。
二、获取发布版安全码SHA1
bash
##生成keystore签名文件
keytool -genkey -v -keystore mykey.keystore -alias key -keyalg RSA -keysize 2048 -validity 10000
##获取sha1
##密钥库口令默认为android
keytool -list -v -keystore mykey.keystore