hi-client/MACOS_BUILD_README.md
2025-10-13 18:08:02 +08:00

127 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# macOS DMG 构建指南
本指南将帮助您构建 macOS DMG 安装包,并避免用户在安装时需要在安全隐私设置中手动允许。
## 🎯 目标
构建一个经过代码签名和公证的 DMG 安装包,用户安装时无需手动允许。
## 📋 前提条件
### 1. Apple Developer 账户
- 需要有效的 Apple Developer 账户($99/年)
- 需要 **Developer ID Application** 证书
- 需要 **Developer ID Installer** 证书
### 2. 获取证书
1. 登录 [Apple Developer Portal](https://developer.apple.com)
2. 进入 "Certificates, Identifiers & Profiles"
3. 创建以下证书:
- **Developer ID Application** (用于应用签名)
- **Developer ID Installer** (用于安装包签名)
### 3. 创建 App 专用密码
1. 登录 [Apple ID 管理页面](https://appleid.apple.com)
2. 在 "App 专用密码" 部分创建新密码
3. 记录此密码,稍后需要用到
## 🚀 构建步骤
### 方法一:完整签名版本(推荐)
1. **配置签名信息**
```bash
# 编辑配置文件
nano macos_signing_config.sh
# 修改以下信息:
export APPLE_ID="your-apple-id@example.com"
export APPLE_PASSWORD="your-app-specific-password"
export TEAM_ID="YOUR_TEAM_ID"
export SIGNING_IDENTITY="Developer ID Application: Your Name (YOUR_TEAM_ID)"
```
2. **加载配置并构建**
```bash
# 加载配置
source macos_signing_config.sh
# 构建 DMG
./build_macos_dmg.sh
```
### 方法二:简化版本(需要手动允许)
如果您没有开发者证书,可以使用简化版本:
```bash
./build_macos_simple.sh
```
**注意**:此版本需要用户在安装时手动在安全隐私设置中允许。
## 📁 输出文件
构建完成后DMG 文件将位于:
```
build/macos/Build/Products/Release/kaer_with_panels.dmg
```
## 🔍 验证签名
构建完成后,您可以验证签名:
```bash
# 验证应用签名
codesign --verify --verbose build/macos/Build/Products/Release/kaer_with_panels.app
# 验证 DMG 签名
codesign --verify --verbose build/macos/Build/Products/Release/kaer_with_panels.dmg
# 检查公证状态
spctl --assess --verbose build/macos/Build/Products/Release/kaer_with_panels.dmg
```
## 🛠️ 故障排除
### 1. 证书问题
```bash
# 查看可用证书
security find-identity -v -p codesigning
# 如果看到 "0 valid identities found",说明没有安装证书
```
### 2. 公证失败
- 确保 Apple ID 和密码正确
- 确保 Team ID 正确
- 检查网络连接
### 3. 签名失败
- 确保证书已正确安装
- 检查签名身份名称是否正确
- 确保证书未过期
## 📚 相关文档
- [Apple 代码签名指南](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution)
- [Flutter macOS 部署指南](https://docs.flutter.dev/deployment/macos)
- [DMG 创建指南](https://developer.apple.com/design/human-interface-guidelines/macos/windows-and-views/dialogs/)
## ⚠️ 重要提醒
1. **安全性**:请妥善保管您的开发者证书和密码
2. **测试**:在分发前,请在干净的 macOS 系统上测试安装
3. **更新**:定期更新证书,避免过期
4. **备份**:建议备份您的签名配置
## 🎉 成功标志
如果构建成功,您应该看到:
- ✅ 应用签名成功
- ✅ DMG 签名成功
- ✅ DMG 公证成功
- ✅ 最终验证通过
用户安装时应该能够直接运行,无需手动允许。