Files
jiu/scripts/ci/compile-android.sh
T
wangjia 480ce836bb
Deploy / build-linux-web (push) Successful in 53s
Deploy / build-windows (push) Successful in 1m48s
Deploy / build-macos (push) Successful in 1m17s
Deploy / build-android (push) Successful in 4m13s
Deploy / build-ios (push) Successful in 9s
Deploy / release-deploy (push) Successful in 1m37s
chore: release v1.0.18
移动端响应式适配(抽屉导航/列表卡片/弹窗自适应)、Android 正式签名与 APK 发布、
iOS(TestFlight) 工程与 CI、多平台构建流水线、相关文档同步。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 07:55:33 +08:00

65 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# compile-android.sh <tag> — build signed Flutter Android APK, package into dist/
set -euo pipefail
# shellcheck source=scripts/ci/_env.sh
. "$(dirname "$0")/_env.sh"
TAG="$1"
VER="${TAG#v}"
# versionCode 必须单调递增,否则 Android 无法覆盖升级安装。
# 由版本号推导:major*10000 + minor*100 + patch(如 1.0.17 -> 10017)。
MAJOR="$(echo "$VER" | cut -d. -f1)"
MINOR="$(echo "$VER" | cut -d. -f2)"
PATCH="$(echo "$VER" | cut -d. -f3)"
BUILD=$(( MAJOR * 10000 + MINOR * 100 + PATCH ))
echo "==> compile-android: version=${VER} build=${BUILD}"
# Sync Flutter pubspec version (BSD sed on macOS)
sed -i '' "s/^version:.*/version: ${VER}+${BUILD}/" client/pubspec.yaml
# --- release 签名:从 CI secrets 还原 keystore 与 key.properties ---
if [ -n "${ANDROID_KEYSTORE_BASE64:-}" ]; then
echo "==> compile-android: configuring release signing"
KEYSTORE_PATH="$(pwd)/client/android/jiu-release.jks"
echo "${ANDROID_KEYSTORE_BASE64}" | base64 --decode > "${KEYSTORE_PATH}"
cat > client/android/key.properties <<EOF
storeFile=${KEYSTORE_PATH}
storePassword=${ANDROID_KEYSTORE_PASSWORD}
keyAlias=${ANDROID_KEY_ALIAS}
keyPassword=${ANDROID_KEY_PASSWORD}
EOF
else
echo "==> compile-android: WARNING — no ANDROID_KEYSTORE_BASE64, falling back to debug signing"
fi
# Build APK (universal, all ABIs — simplest for sideload download)
cd client
flutter build apk --release \
"--dart-define=BASE_URL=https://jiu.51yanmei.com" \
"--dart-define=PUBLIC_URL=https://jiu.51yanmei.com" \
"--dart-define=APP_VERSION=${TAG}"
cd ..
# Locate the built APK (path differs across Flutter versions) and copy to dist/
mkdir -p dist
APK=""
for cand in \
client/build/app/outputs/flutter-apk/app-release.apk \
client/build/app/outputs/apk/release/app-release.apk; do
if [ -f "$cand" ]; then APK="$cand"; break; fi
done
if [ -z "$APK" ]; then
echo "ERROR: built APK not found" >&2
exit 1
fi
cp "$APK" dist/jiu-android.apk
# Clean up signing material so it never lingers on the runner workspace
rm -f client/android/key.properties client/android/jiu-release.jks 2>/dev/null || true
echo "==> compile-android: done — dist/ contents:"
ls -lh dist/