From 3a515c5fe1ce4c94d5424305afe2eaf4812a635d Mon Sep 17 00:00:00 2001 From: 5ec1cff Date: Mon, 29 Jul 2024 23:59:15 +0800 Subject: [PATCH] refine gradle --- build.gradle.kts | 14 -------------- module/build.gradle.kts | 19 +++++++++++++------ service/build.gradle.kts | 4 ++-- settings.gradle.kts | 4 +--- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 69f3271..3d6b7a7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,6 @@ import com.android.build.gradle.AppExtension import com.android.build.gradle.LibraryExtension -import org.jetbrains.kotlin.daemon.common.toHexString import java.io.ByteArrayOutputStream -import java.security.MessageDigest plugins { alias(libs.plugins.agp.app) apply false @@ -33,18 +31,6 @@ val verCode by extra(gitCommitCount) val commitHash by extra(gitCommitHash) val abiList by extra(listOf("arm64-v8a", "x86_64")) -fun calculateChecksum(): String { - return MessageDigest.getInstance("SHA-256").run { - update(moduleId.toByteArray(Charsets.UTF_8)) - update(moduleName.toByteArray(Charsets.UTF_8)) - update(verName.toByteArray(Charsets.UTF_8)) - update(verCode.toString().toByteArray(Charsets.UTF_8)) - update(author.toByteArray(Charsets.UTF_8)) - update(description.toByteArray(Charsets.UTF_8)) - digest().toHexString() - } -} - val androidMinSdkVersion by extra(31) val androidTargetSdkVersion by extra(34) val androidCompileSdkVersion by extra(34) diff --git a/module/build.gradle.kts b/module/build.gradle.kts index 500fca0..e0ba1e7 100644 --- a/module/build.gradle.kts +++ b/module/build.gradle.kts @@ -60,11 +60,14 @@ dependencies { implementation(libs.cxx) } -androidComponents.onVariants { variant -> - afterEvaluate { +evaluationDependsOn(":service") + +afterEvaluate { + android.applicationVariants.forEach { variant -> val variantLowered = variant.name.lowercase() val variantCapped = variant.name.capitalizeUS() - val buildTypeLowered = variant.buildType?.lowercase() + val buildTypeCapped = variant.buildType.name.replaceFirstChar { it.uppercase() } + val buildTypeLowered = variant.buildType.name.lowercase() val supportedAbis = abiList.map { when (it) { "arm64-v8a" -> "arm64" @@ -81,7 +84,10 @@ androidComponents.onVariants { variant -> val prepareModuleFilesTask = task("prepareModuleFiles$variantCapped") { group = "module" - dependsOn("assemble$variantCapped", ":service:assemble$variantCapped") + dependsOn( + "assemble$variantCapped", + ":service:package$buildTypeCapped" + ) into(moduleDir) from(rootProject.layout.projectDirectory.file("README.md")) from(layout.projectDirectory.file("template")) { @@ -110,8 +116,9 @@ androidComponents.onVariants { variant -> filter("tokens" to tokens) filter("eol" to FixCrLfFilter.CrLf.newInstance("lf")) } - from(project(":service").layout.buildDirectory.file("outputs/apk/$variantLowered/service-$variantLowered.apk")) { - rename { "service.apk" } + from(project(":service").tasks.getByName("package$buildTypeCapped").outputs) { + include("*.apk") + rename(".*\\.apk", "service.apk") } from(layout.buildDirectory.file("intermediates/stripped_native_libs/$variantLowered/strip${variantCapped}DebugSymbols/out/lib")) { exclude("**/libbinder.so", "**/libutils.so") diff --git a/service/build.gradle.kts b/service/build.gradle.kts index c4667f7..766eab8 100644 --- a/service/build.gradle.kts +++ b/service/build.gradle.kts @@ -84,8 +84,8 @@ dependencies { implementation(libs.bcpkix.jdk18on) } -androidComponents.onVariants { variant -> - afterEvaluate { +afterEvaluate { + android.applicationVariants.forEach { variant -> val variantLowered = variant.name.lowercase() val variantCapped = variant.name.capitalizeUS() val pushTask = task("pushService$variantCapped") { diff --git a/settings.gradle.kts b/settings.gradle.kts index 8042952..a1d9916 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,8 +15,6 @@ dependencyResolutionManagement { } rootProject.name = "TrickyStore" -include( - ":module" -) +include(":module") include(":service") include(":stub")