You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
#!/bin/bash
|
|
# usage:
|
|
# ./scripts/build_ios.sh --output /absolute/path/to/output [extra flutter build args...]
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
DEFAULT_BUILD_DIR="$PROJECT_ROOT/build/ios_release"
|
|
OUTPUT_DIR="$DEFAULT_BUILD_DIR"
|
|
EXTRA_ARGS=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--output=*)
|
|
OUTPUT_DIR="${1#*=}"
|
|
shift
|
|
;;
|
|
--output)
|
|
if [[ $# -lt 2 ]]; then
|
|
echo "参数错误: --output 需要一个路径" >&2
|
|
exit 1
|
|
fi
|
|
OUTPUT_DIR="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
EXTRA_ARGS+=("$1")
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
mkdir -p "$OUTPUT_DIR"
|
|
|
|
pushd "$PROJECT_ROOT" >/dev/null
|
|
echo "📦 清理旧构建..."
|
|
flutter clean
|
|
|
|
echo "📚 获取依赖..."
|
|
flutter pub get
|
|
|
|
echo "🚀 开始构建 iOS 安装包..."
|
|
if [[ ${#EXTRA_ARGS[@]} -gt 0 ]]; then
|
|
flutter build ios --release "${EXTRA_ARGS[@]}"
|
|
else
|
|
flutter build ios --release
|
|
fi
|
|
|
|
# iOS build output is typically in build/ios/iphoneos/
|
|
BUILD_OUTPUT_DIR="$PROJECT_ROOT/build/ios/iphoneos"
|
|
if [[ -d "$BUILD_OUTPUT_DIR" ]]; then
|
|
echo "📦 复制构建产物到输出目录..."
|
|
mkdir -p "$OUTPUT_DIR"
|
|
cp -R "$BUILD_OUTPUT_DIR"/* "$OUTPUT_DIR/" 2>/dev/null || true
|
|
echo "✅ 构建完成,产物目录:$OUTPUT_DIR"
|
|
else
|
|
echo "⚠️ 警告: 未找到预期的构建输出目录 $BUILD_OUTPUT_DIR"
|
|
echo "构建产物可能在:$PROJECT_ROOT/build/ios/"
|
|
fi
|
|
popd >/dev/null
|
|
|