From df91719a2fdacf451ef4befee8c72abf3c9eaea1 Mon Sep 17 00:00:00 2001 From: penghanyuan Date: Sat, 14 Feb 2026 10:44:56 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20Android=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E8=84=9A=E6=9C=AC=E4=BB=A5=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 Makefile,提供构建、清理和安装命令,支持指定版本号和版本代码。 - 更新 build.gradle.kts,支持从命令行参数读取版本号和版本代码,增强构建灵活性。 --- app-android/Makefile | 71 ++++++++++++++++++++++++++++++++ app-android/app/build.gradle.kts | 8 +++- 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 app-android/Makefile diff --git a/app-android/Makefile b/app-android/Makefile new file mode 100644 index 0000000..e00ef97 --- /dev/null +++ b/app-android/Makefile @@ -0,0 +1,71 @@ +# Life Echo Android 构建脚本 +# 使用方法:make release VERSION=1.2.3 CODE=10 + +# 默认版本号 +VERSION ?= 1.0.0 +CODE ?= 1 + +.PHONY: help release debug clean install + +help: + @echo "Life Echo Android 构建命令:" + @echo "" + @echo " make release VERSION=1.2.3 CODE=10 - 构建 Release APK(指定版本号)" + @echo " make debug - 构建 Debug APK" + @echo " make clean - 清理构建文件" + @echo " make install - 安装到连接的设备" + @echo "" + @echo "参数:" + @echo " VERSION - 版本名称,如 1.2.3(默认: $(VERSION))" + @echo " CODE - 版本代码(整数),如 10(默认: $(CODE))" + @echo "" + @echo "示例:" + @echo " make release VERSION=2.0.0 CODE=20" + +# 构建 Release 版本 +release: + @echo "🚀 构建 Release 版本..." + @echo " 版本名称: $(VERSION)" + @echo " 版本代码: $(CODE)" + JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home" ./gradlew assembleRelease \ + -PversionName=$(VERSION) \ + -PversionCode=$(CODE) + @echo "✅ 构建完成!" + @echo "📦 APK 位置: app/build/outputs/apk/release/岁月留书_v$(VERSION)_release.apk" + +# 构建 Debug 版本 +debug: + @echo "🔧 构建 Debug 版本..." + ./gradlew assembleDebug + @echo "✅ Debug 版本构建完成!" + +# 构建 Debug Prod 版本(生产环境调试) +debug-prod: + @echo "🔧 构建 Debug Prod 版本..." + ./gradlew assembleDebugProd \ + -PversionName=$(VERSION) \ + -PversionCode=$(CODE) + @echo "✅ Debug Prod 版本构建完成!" + +# 清理构建 +clean: + @echo "🧹 清理构建文件..." + ./gradlew clean + @echo "✅ 清理完成!" + +# 安装到设备 +install: release + @echo "📱 安装到设备..." + ./gradlew installRelease + @echo "✅ 安装完成!" + +# 列出所有构建变体 +variants: + @echo "📋 可用的构建变体:" + ./gradlew tasks --group=build + +# 显示当前版本信息 +version: + @echo "当前版本配置:" + @echo " VERSION = $(VERSION)" + @echo " CODE = $(CODE)" diff --git a/app-android/app/build.gradle.kts b/app-android/app/build.gradle.kts index 6ee92fe..ba8cf43 100644 --- a/app-android/app/build.gradle.kts +++ b/app-android/app/build.gradle.kts @@ -9,6 +9,10 @@ plugins { alias(libs.plugins.ksp) } +// 版本号配置(支持从命令行参数读取) +val appVersionName: String = project.findProperty("versionName")?.toString() ?: "1.0.0" +val appVersionCode: Int = (project.findProperty("versionCode")?.toString() ?: "1").toInt() + // 加载签名配置(从 keystore.properties 文件读取) val keystorePropertiesFile = rootProject.file("keystore.properties") val keystoreProperties = Properties() @@ -24,8 +28,8 @@ android { applicationId = "com.huaga.life_echo" minSdk = 24 targetSdk = 36 - versionCode = 1 - versionName = "1.0.0" + versionCode = appVersionCode + versionName = appVersionName testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" }