diff --git a/Makefile b/Makefile index 4569704..e65d5c2 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,18 @@ -.PHONY: runner run test lint apk ipa build-web +.PHONY: runner run test lint apk ipa build-web rename_release_apk jinzhi_shorebird_android jinzhi_shorebird_ios jinzhi_shorebird_android_patch jinzhi_shorebird_ios_patch WEB_API_URL ?= https://jinzhi.api.local WEB_BASE_HREF ?= /flutter/ +SHOREBIRD_TOKEN_FILE ?= $(HOME)/.shorebird_tokens/jinzhi.env +SHOREBIRD = if [ ! -f "$(SHOREBIRD_TOKEN_FILE)" ]; then echo "错误: 缺少 Shorebird token 文件: $(SHOREBIRD_TOKEN_FILE)"; exit 1; fi; set -a; . "$(SHOREBIRD_TOKEN_FILE)"; set +a; shorebird GITVERSION := $(shell git describe --tags --always --dirty 2>/dev/null || git rev-parse --short HEAD) -COMMON_DART_DEFINES := --dart-define=GITVERSION=$(GITVERSION) +RELEASE_VERSION ?= latest +PATCH_TRACK ?= staging +COMMON_DART_DEFINES := --dart-define="GITVERSION=$(GITVERSION)" +APP_VERSION := $(shell sed -n 's/^version: *//p' pubspec.yaml | head -n 1) +APK_VERSION_NAME := $(subst .,,${word 1,$(subst +, ,$(APP_VERSION))}) +APK_VERSION_CODE := $(word 2,$(subst +, ,$(APP_VERSION))) +RELEASE_APK := jinzhi-$(APK_VERSION_NAME)-$(APK_VERSION_CODE)-release.apk +RELEASE_APK_DIR := build/app/outputs/flutter-apk runner: dart run build_runner build --delete-conflicting-outputs @@ -18,10 +27,29 @@ lint: flutter analyze apk: - flutter build apk $(COMMON_DART_DEFINES) --release --target-platform android-arm64 + flutter build apk --obfuscate --split-debug-info=./build/symbos $(COMMON_DART_DEFINES) --release --target-platform android-arm64 + $(MAKE) rename_release_apk + +rename_release_apk: + @test -f "$(RELEASE_APK_DIR)/app-release.apk" || (echo "错误: 未找到 release APK: $(RELEASE_APK_DIR)/app-release.apk"; exit 1) + cp "$(RELEASE_APK_DIR)/app-release.apk" "$(RELEASE_APK_DIR)/$(RELEASE_APK)" + @echo "Release APK: $(RELEASE_APK_DIR)/$(RELEASE_APK)" ipa: - flutter build ipa $(COMMON_DART_DEFINES) --release + flutter build ipa --obfuscate --split-debug-info=./build/symbos $(COMMON_DART_DEFINES) --release + +jinzhi_shorebird_android: + $(SHOREBIRD) release android --flutter-version=3.35.6 --split-debug-info=./build/symbos --target-platform android-arm64 --artifact apk -- --dart-define="GITVERSION=$(GITVERSION)" + $(MAKE) rename_release_apk + +jinzhi_shorebird_ios: + $(SHOREBIRD) release ios --flutter-version=3.35.6 --split-debug-info=./build/symbos -- --dart-define="GITVERSION=$(GITVERSION)" + +jinzhi_shorebird_android_patch: + $(SHOREBIRD) patch --platforms=android --release-version=$(RELEASE_VERSION) --split-debug-info=./build/symbos --track=$(PATCH_TRACK) -- --dart-define="GITVERSION=$(GITVERSION)" + +jinzhi_shorebird_ios_patch: + $(SHOREBIRD) patch --platforms=ios --release-version=$(RELEASE_VERSION) --split-debug-info=./build/symbos --track=$(PATCH_TRACK) -- --dart-define="GITVERSION=$(GITVERSION)" build-web: API_BASE_URL=$(WEB_API_URL) BASE_HREF=$(WEB_BASE_HREF) bash scripts/build_web.sh diff --git a/lib/app/bootstrap.dart b/lib/app/bootstrap.dart index 028b87c..67483d2 100644 --- a/lib/app/bootstrap.dart +++ b/lib/app/bootstrap.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io' show Platform; import 'package:flutter/foundation.dart' show kIsWeb; @@ -29,8 +30,9 @@ Future bootstrap() async { } } if (!kIsWeb) { - await ShorebirdService.instance.initCurrentPatch(); - ShorebirdService.instance.checkForUpdateInBackground(); + // Shorebird's native updater performs the automatic launch-time update. + // Reading the running patch is diagnostic state and must not delay startup. + unawaited(ShorebirdService.instance.initCurrentPatch()); } return const JinzhiApp(); }