Skip to content

Commit

Permalink
[PM-15176] Rename bundle and apk files to match applicationId and fla…
Browse files Browse the repository at this point in the history
…vor (#4474)
  • Loading branch information
SaintPatrck authored Dec 14, 2024
1 parent e37cefe commit be88cdf
Showing 1 changed file with 28 additions and 41 deletions.
69 changes: 28 additions & 41 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import com.android.utils.cxx.io.removeExtensionIfPresent
import com.google.firebase.crashlytics.buildtools.gradle.tasks.InjectMappingFileIdTask
import com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask
import com.google.gms.googleservices.GoogleServicesTask
import dagger.hilt.android.plugin.util.capitalize
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.io.FileInputStream
import java.util.Properties
Expand Down Expand Up @@ -64,7 +66,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField(
type ="String",
type = "String",
name = "CI_INFO",
value = "\"${ciProperties.getOrDefault("ci.info", "local")}\""
)
Expand Down Expand Up @@ -133,14 +135,35 @@ android {
}

applicationVariants.all {
val bundlesDir = "${layout.buildDirectory.get()}/outputs/bundle"
outputs
.mapNotNull { it as? BaseVariantOutputImpl }
.forEach { output ->
output.outputFileName = when (flavorName) {
"fdroid" -> "$applicationId-$flavorName.apk"
"standard" -> "$applicationId.apk"
else -> output.outputFileName
val fileNameWithoutExtension = when (flavorName) {
"fdroid" -> "$applicationId-$flavorName"
"standard" -> "$applicationId"
else -> output.outputFileName.removeExtensionIfPresent(".apk")
}

// Set the APK output filename.
output.outputFileName = "$fileNameWithoutExtension.apk"

val variantName = name
val renameTaskName = "rename${variantName.capitalize()}AabFiles"
tasks.register(renameTaskName) {
group = "build"
description = "Renames the bundle files for $variantName variant"
doLast {
renameFile(
"$bundlesDir/$variantName/$namespace-$flavorName-${buildType.name}.aab",
"$fileNameWithoutExtension.aab",
)
}
}
// Force renaming task to execute after the variant is built.
tasks
.getByName("bundle${variantName.capitalize()}")
.finalizedBy(renameTaskName)
}
}

Expand Down Expand Up @@ -354,42 +377,6 @@ afterEvaluate {
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 {
Expand Down

0 comments on commit be88cdf

Please sign in to comment.