From 1aec94ee7dbac639fd6582e561bafd5ba7d21952 Mon Sep 17 00:00:00 2001 From: Patrick Honkonen <1883101+SaintPatrck@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:43:49 -0500 Subject: [PATCH] [PM-15176] Rename AAB outputs to match APK naming convention (#4467) --- app/build.gradle.kts | 59 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 18c910dfa9..0ca4117e7c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -311,6 +311,10 @@ tasks { dependsOn("detekt") } + getByName("sonar") { + dependsOn("check") + } + withType().configureEach { jvmTarget = libs.versions.jvmTarget.get() } @@ -328,12 +332,48 @@ tasks { afterEvaluate { // Disable Fdroid-specific tasks that we want to exclude - val tasks = tasks.withType() + + val fdroidTasksToDisable = tasks.withType() + tasks.withType() + tasks.withType() - tasks + fdroidTasksToDisable .filter { it.name.contains("Fdroid") } .forEach { it.enabled = false } + + tasks.named("bundle") { + finalizedBy("renameAabFiles") + } + tasks.register("renameAabFiles") { + group = "build" + doLast { + val bundlesDir = "${layout.buildDirectory.get()}/outputs/bundle" + println("bundlesDir: $bundlesDir") + renameFile( + "$bundlesDir/standardDebug/com.x8bit.bitwarden-standard-debug.aab", + "com.x8bit.bitwarden.dev.aab" + ) + renameFile( + "$bundlesDir/standardBeta/com.x8bit.bitwarden-standard-beta.aab", + "com.x8bit.bitwarden.beta.aab" + ) + renameFile( + "$bundlesDir/standardRelease/com.x8bit.bitwarden-standard-release.aab", + "com.x8bit.bitwarden.aab" + ) + + renameFile( + "$bundlesDir/fdroidDebug/com.x8bit.bitwarden-fdroid-debug.aab", + "com.x8bit.bitwarden.dev-fdroid.aab" + ) + renameFile( + "$bundlesDir/fdroidBeta/com.x8bit.bitwarden-fdroid-beta.aab", + "com.x8bit.bitwarden.beta-fdroid.aab" + ) + renameFile( + "$bundlesDir/fdroidRelease/com.x8bit.bitwarden-fdroid-release.aab", + "com.x8bit.bitwarden-fdroid.aab" + ) + } + } } sonar { @@ -348,8 +388,17 @@ sonar { } } -tasks { - getByName("sonar") { - dependsOn("check") +private fun renameFile(path: String, newName: String) { + val originalFile = File(path) + if (!originalFile.exists()) { + println("File $originalFile does not exist!") + return + } + + val newFile = File(originalFile.parentFile, newName) + if (originalFile.renameTo(newFile)) { + println("Renamed $originalFile to $newFile") + } else { + throw RuntimeException("Failed to rename $originalFile to $newFile") } }