From f74471e162e5cd76a360c45df9a98cbe32a5725f Mon Sep 17 00:00:00 2001 From: yovinchen Date: Wed, 27 Nov 2024 09:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E9=85=8D=E7=BD=AE:=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96APK=E8=BE=93=E5=87=BA=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 添加自定义APK输出文件名配置 2. 文件名包含版本号、构建类型和时间信息 3. 更新Java编译版本到11 4. 启用代码混淆和资源压缩 5. 忽略启动器图标文件的Git跟踪 --- app/build.gradle.kts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6ba06c7..e3d89d3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -4,6 +4,10 @@ plugins { id("com.google.devtools.ksp") } +import java.text.SimpleDateFormat +import java.util.Date +import com.android.build.api.variant.FilterConfiguration + android { namespace = "com.yovinchen.bookkeeping" compileSdk = 34 @@ -13,7 +17,7 @@ android { minSdk = 26 targetSdk = 34 versionCode = 1 - versionName = "1.0" + versionName = "1.0.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { @@ -23,19 +27,37 @@ android { buildTypes { release { - isMinifyEnabled = false + isMinifyEnabled = true + isShrinkResources = true proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) + signingConfig = signingConfigs.getByName("debug") // 使用debug签名,实际发布时应该使用正式的签名配置 } } + + applicationVariants.all { + val variant = this + variant.outputs + .map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl } + .forEach { output -> + // 获取当前时间 + val date = SimpleDateFormat("yyyyMMdd_HHmm").format(Date()) + // 获取CPU架构,如果没有则使用universal + val buildType = variant.buildType.name + // 构建文件名 + val outputFileName = "轻记账_${buildType}_v${variant.versionName}_${date}.apk" + output.outputFileName = outputFileName + } + } + compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "11" } buildFeatures { compose = true