|
| 1 | +import com.android.build.gradle.internal.api.BaseVariantOutputImpl |
1 | 2 | import com.google.protobuf.gradle.proto |
| 3 | +import dagger.hilt.android.plugin.util.capitalize |
2 | 4 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
3 | 5 |
|
4 | 6 | plugins { |
@@ -54,6 +56,7 @@ android { |
54 | 56 |
|
55 | 57 | buildTypes { |
56 | 58 | debug { |
| 59 | + applicationIdSuffix = ".dev" |
57 | 60 | manifestPlaceholders["targetBitwardenAppId"] = "com.x8bit.bitwarden.dev" |
58 | 61 | buildConfigField( |
59 | 62 | type = "com.bitwarden.authenticatorbridge.manager.model.AuthenticatorBridgeConnectionType", |
@@ -81,6 +84,32 @@ android { |
81 | 84 | buildConfigField(type = "boolean", name = "HAS_DEBUG_MENU", value = "false") |
82 | 85 | } |
83 | 86 | } |
| 87 | + applicationVariants.all { |
| 88 | + val bundlesDir = "${layout.buildDirectory.get()}/outputs/bundle" |
| 89 | + outputs |
| 90 | + .mapNotNull { it as? BaseVariantOutputImpl } |
| 91 | + .forEach { output -> |
| 92 | + // Set the APK output filename. |
| 93 | + output.outputFileName = "$applicationId.apk" |
| 94 | + |
| 95 | + val variantName = name |
| 96 | + val renameTaskName = "rename${variantName.capitalize()}AabFiles" |
| 97 | + tasks.register(renameTaskName) { |
| 98 | + group = "build" |
| 99 | + description = "Renames the bundle files for $variantName variant" |
| 100 | + doLast { |
| 101 | + renameFile( |
| 102 | + "$bundlesDir/$variantName/$namespace-${buildType.name}.aab", |
| 103 | + "$applicationId.aab", |
| 104 | + ) |
| 105 | + } |
| 106 | + } |
| 107 | + // Force renaming task to execute after the variant is built. |
| 108 | + tasks |
| 109 | + .getByName("bundle${variantName.capitalize()}") |
| 110 | + .finalizedBy(renameTaskName) |
| 111 | + } |
| 112 | + } |
84 | 113 | compileOptions { |
85 | 114 | sourceCompatibility(libs.versions.jvmTarget.get()) |
86 | 115 | targetCompatibility(libs.versions.jvmTarget.get()) |
@@ -285,3 +314,18 @@ tasks { |
285 | 314 | dependsOn("check") |
286 | 315 | } |
287 | 316 | } |
| 317 | + |
| 318 | +private fun renameFile(path: String, newName: String) { |
| 319 | + val originalFile = File(path) |
| 320 | + if (!originalFile.exists()) { |
| 321 | + println("File $originalFile does not exist!") |
| 322 | + return |
| 323 | + } |
| 324 | + |
| 325 | + val newFile = File(originalFile.parentFile, newName) |
| 326 | + if (originalFile.renameTo(newFile)) { |
| 327 | + println("Renamed $originalFile to $newFile") |
| 328 | + } else { |
| 329 | + throw RuntimeException("Failed to rename $originalFile to $newFile") |
| 330 | + } |
| 331 | +} |
0 commit comments