86 lines
1.9 KiB
Markdown
86 lines
1.9 KiB
Markdown
# Android 构建说明
|
||
|
||
## 本地开发构建
|
||
|
||
### 1. 环境准备
|
||
确保已安装:
|
||
- Node.js 18+
|
||
- Rust 1.70+
|
||
- Android SDK
|
||
- pnpm
|
||
|
||
### 2. 安装依赖
|
||
```bash
|
||
pnpm install
|
||
```
|
||
|
||
### 3. 配置签名(可选)
|
||
如果需要生产签名(发布到应用商店),需要配置签名密钥:
|
||
|
||
1. 复制配置模板:
|
||
```bash
|
||
cp keystore.properties.example keystore.properties
|
||
```
|
||
|
||
2. 编辑 `keystore.properties`,填入你的密钥信息:
|
||
```properties
|
||
storeFile=your-keystore.jks
|
||
storePassword=your_keystore_password
|
||
keyPassword=your_key_password
|
||
keyAlias=your_key_alias
|
||
```
|
||
|
||
3. 确保密钥文件在项目根目录
|
||
|
||
### 4. 构建应用
|
||
```bash
|
||
# 构建Android APK
|
||
./build_android.sh
|
||
|
||
# 或使用 Tauri 命令
|
||
pnpm tauri android build --apk
|
||
```
|
||
|
||
## CI/CD 环境构建
|
||
|
||
### 自动处理签名
|
||
构建系统会自动检测签名配置:
|
||
|
||
- **有 `keystore.properties`**: 使用自定义签名密钥
|
||
- **无 `keystore.properties`**: 自动使用debug签名
|
||
|
||
这确保了CI/CD环境可以正常构建,无需额外配置。
|
||
|
||
### GitHub Actions 示例
|
||
```yaml
|
||
- name: Build Android APK
|
||
run: |
|
||
pnpm install
|
||
pnpm tauri android build --apk
|
||
# 无需配置密钥,会自动使用debug签名
|
||
```
|
||
|
||
### 生产环境签名
|
||
如果需要在CI/CD中使用生产签名:
|
||
|
||
1. 将密钥文件和配置作为secrets添加到CI/CD系统
|
||
2. 在构建前创建 `keystore.properties` 文件
|
||
3. 构建系统会自动使用生产签名
|
||
|
||
## 输出文件
|
||
构建完成后,APK文件位于:
|
||
```
|
||
src-tauri/gen/android/app/build/outputs/apk/universal/release/
|
||
```
|
||
|
||
## 故障排除
|
||
|
||
### 签名相关错误
|
||
- 检查 `keystore.properties` 文件路径和内容
|
||
- 确保密钥文件存在且密码正确
|
||
- 如果不需要生产签名,删除 `keystore.properties` 文件
|
||
|
||
### 构建环境问题
|
||
- 确保Android SDK正确安装
|
||
- 检查环境变量 `ANDROID_HOME`
|
||
- 更新Android构建工具到最新版本 |