ci(android): 修复 Rust 缓存命中后 cargo 报 no default toolchain
Android Build & Publish / build-android (push) Successful in 16m27s

This commit is contained in:
Cheney
2026-11-02 10:11:11 +08:00
parent f2c7dae4a8
commit 6d560583ae
+17 -9
View File
@@ -60,8 +60,10 @@ jobs:
with:
path: |
~/.cargo
~/.rustup/toolchains
~/.rustup
# 工具链升级时 bump 版本号使缓存失效重装 (含 cargo-ndk)
# 注意: 必须缓存整个 ~/.rustup。只缓存 ~/.rustup/toolchains 会丢掉
# settings.toml (默认 toolchain 记录), 缓存命中时 cargo 无法选择版本。
key: rust-android-v1-${{ runner.os }}
- name: Cache Tauri cargo target
@@ -72,16 +74,22 @@ jobs:
key: tauri-target-android-${{ hashFiles('src-tauri/Cargo.lock') }}
restore-keys: tauri-target-android-
# ---------- 安装工具链 (仅缓存未命中时) ----------
- name: Install Rust + Android targets
if: steps.cache-rust.outputs.cache-hit != 'true'
# ---------- 安装/修复工具链 (缓存命中时也要执行) ----------
# 缓存命中时不能只是跳过安装: 缓存里可能缺少 ~/.rustup/settings.toml,
# rustup 代理会报 "no default is configured", 导致 cargo / tauri 全部失败。
# 因此这一步无条件运行, 但都是幂等操作 (已安装时不会重新下载)。
- name: Setup Rust toolchain
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
if [ ! -x "$HOME/.cargo/bin/rustup" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
fi
. "$HOME/.cargo/env"
# 幂等: stable 已在 ~/.rustup/toolchains 时只补写 settings.toml
rustup default stable
# 只构建 aarch64 (现代 Android 手机); 需要模拟器/x86 设备时再加回其他 target
rustup target add aarch64-linux-android
cargo install cargo-ndk --locked
command -v cargo-ndk >/dev/null 2>&1 || cargo install cargo-ndk --locked
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- name: Install Android SDK & NDK
if: steps.cache-android.outputs.cache-hit != 'true'
@@ -117,9 +125,9 @@ jobs:
- name: Init Android project
run: |
# tauri android init 需要 cargo (运行 cargo metadata)。
# Rust 工具链缓存命中时 "Install Rust" 步骤被跳过, 不会把 cargo 加进全局 PATH,
# 因此这里显式加载 cargo 环境 (与 Build release APK 步骤保持一致)。
# Setup Rust toolchain 已把 ~/.cargo/bin 写入 GITHUB_PATH, 这里再 source 一次兜底。
. "$HOME/.cargo/env"
cargo --version
cd src-tauri
npx tauri android init --ci