feat: 通过 local.properties 自动解析 Flutter SDK 路径

This commit is contained in:
root
2026-07-22 23:37:16 -04:00
parent 1112b04516
commit 3574e60a8c
+24 -5
View File
@@ -6,12 +6,31 @@ ENV_FILE="env/prod.json"
OUTPUT_DIR="build/outputs"
APK_SRC="build/app/outputs/flutter-apk/app-release.apk"
APK_DEST="$OUTPUT_DIR/rentaldrivego-release.apk"
LOCAL_PROPERTIES="android/local.properties"
resolve_flutter() {
if command -v flutter &>/dev/null; then
command -v flutter
return 0
fi
if [[ -f "$LOCAL_PROPERTIES" ]]; then
local sdk_path
sdk_path="$(sed -n 's/^flutter\.sdk=//p' "$LOCAL_PROPERTIES" | head -n 1)"
if [[ -n "$sdk_path" && -x "$sdk_path/bin/flutter" ]]; then
echo "$sdk_path/bin/flutter"
return 0
fi
fi
return 1
}
# ── Checks ────────────────────────────────────────────────────────────────────
cd "$(dirname "$0")"
if ! command -v flutter &>/dev/null; then
echo "❌ flutter not found in PATH"
if ! FLUTTER_BIN="$(resolve_flutter)"; then
echo "❌ flutter not found in PATH or $LOCAL_PROPERTIES"
exit 1
fi
@@ -22,13 +41,13 @@ fi
# ── Build ─────────────────────────────────────────────────────────────────────
echo "▶ Cleaning previous build..."
flutter clean
"$FLUTTER_BIN" clean
echo "▶ Fetching dependencies..."
flutter pub get
"$FLUTTER_BIN" pub get
echo "▶ Building release APK (production)..."
flutter build apk --release --dart-define-from-file="$ENV_FILE"
"$FLUTTER_BIN" build apk --release --dart-define-from-file="$ENV_FILE"
# ── Copy to output ────────────────────────────────────────────────────────────
mkdir -p "$OUTPUT_DIR"