feat: 添加 Android 构建脚本以简化版本管理

- 新增 Makefile,提供构建、清理和安装命令,支持指定版本号和版本代码。
- 更新 build.gradle.kts,支持从命令行参数读取版本号和版本代码,增强构建灵活性。
This commit is contained in:
penghanyuan
2026-02-14 10:44:56 +01:00
parent aa20ce3039
commit df91719a2f
2 changed files with 77 additions and 2 deletions

71
app-android/Makefile Normal file
View File

@@ -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)"

View File

@@ -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"
}