Skip to content

Commit 2b80c8a

Browse files
PM-31922: Remove deprecated Android block where possible
1 parent 31d480d commit 2b80c8a

File tree

10 files changed

+225
-148
lines changed

10 files changed

+225
-148
lines changed

annotation/build.gradle.kts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
import com.android.build.api.dsl.LibraryExtension
12
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
plugins {
45
alias(libs.plugins.android.library)
56
}
67

7-
android {
8+
configure<LibraryExtension> {
89
namespace = "com.bitwarden.annotation"
9-
compileSdk = libs.versions.compileSdk.get().toInt()
10+
compileSdk {
11+
version = release(libs.versions.compileSdk.get().toInt())
12+
}
1013

1114
defaultConfig {
12-
minSdk = libs.versions.minSdkBwa.get().toInt()
13-
15+
minSdk {
16+
version = release(libs.versions.minSdkBwa.get().toInt())
17+
}
1418
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1519
consumerProguardFiles("consumer-rules.pro")
1620
}
@@ -36,6 +40,6 @@ android {
3640

3741
kotlin {
3842
compilerOptions {
39-
jvmTarget = JvmTarget.fromTarget(libs.versions.jvmTarget.get())
43+
jvmTarget.set(JvmTarget.fromTarget(libs.versions.jvmTarget.get()))
4044
}
4145
}

app/build.gradle.kts

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
1+
import com.android.build.api.dsl.ApplicationExtension
2+
import com.android.build.api.variant.impl.VariantOutputImpl
23
import com.android.utils.cxx.io.removeExtensionIfPresent
34
import com.google.firebase.crashlytics.buildtools.gradle.tasks.InjectMappingFileIdTask
45
import com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask
56
import com.google.gms.googleservices.GoogleServicesTask
6-
import dagger.hilt.android.plugin.util.capitalize
7+
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
78
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
89
import java.io.FileInputStream
910
import java.util.Properties
@@ -42,27 +43,35 @@ val ciProperties = Properties().apply {
4243
}
4344
}
4445

45-
android {
46-
namespace = "com.x8bit.bitwarden"
47-
compileSdk = libs.versions.compileSdk.get().toInt()
46+
base {
47+
// Set the base archive name for publishing purposes. This is used to derive the
48+
// APK and AAB artifact names when uploading to Firebase and Play Store.
49+
archivesName.set("com.x8bit.bitwarden")
50+
}
51+
52+
room {
53+
schemaDirectory("$projectDir/schemas")
54+
}
4855

49-
room {
50-
schemaDirectory("$projectDir/schemas")
56+
configure<ApplicationExtension> {
57+
namespace = "com.x8bit.bitwarden"
58+
compileSdk {
59+
version = release(libs.versions.compileSdk.get().toInt())
5160
}
5261

5362
defaultConfig {
5463
applicationId = "com.x8bit.bitwarden"
55-
minSdk = libs.versions.minSdk.get().toInt()
56-
targetSdk = libs.versions.targetSdk.get().toInt()
64+
minSdk {
65+
version = release(libs.versions.minSdk.get().toInt())
66+
}
67+
targetSdk {
68+
version = release(libs.versions.targetSdk.get().toInt())
69+
}
5770
versionCode = libs.versions.appVersionCode.get().toInt()
5871
versionName = libs.versions.appVersionName.get()
5972

6073
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
6174

62-
// Set the base archive name for publishing purposes. This is used to derive the APK and AAB
63-
// artifact names when uploading to Firebase and Play Store.
64-
base.archivesName = "com.x8bit.bitwarden"
65-
6675
buildConfigField(
6776
type = "String",
6877
name = "CI_INFO",
@@ -140,39 +149,6 @@ android {
140149
}
141150
}
142151

143-
applicationVariants.all {
144-
val bundlesDir = "${layout.buildDirectory.get()}/outputs/bundle"
145-
outputs
146-
.mapNotNull { it as? BaseVariantOutputImpl }
147-
.forEach { output ->
148-
val fileNameWithoutExtension = when (flavorName) {
149-
"fdroid" -> "$applicationId-$flavorName"
150-
"standard" -> "$applicationId"
151-
else -> output.outputFileName.removeExtensionIfPresent(".apk")
152-
}
153-
154-
// Set the APK output filename.
155-
output.outputFileName = "$fileNameWithoutExtension.apk"
156-
157-
val variantName = name
158-
val renameTaskName = "rename${variantName.capitalize()}AabFiles"
159-
tasks.register(renameTaskName) {
160-
group = "build"
161-
description = "Renames the bundle files for $variantName variant"
162-
doLast {
163-
renameFile(
164-
"$bundlesDir/$variantName/$namespace-$flavorName-${buildType.name}.aab",
165-
"$fileNameWithoutExtension.aab",
166-
)
167-
}
168-
}
169-
// Force renaming task to execute after the variant is built.
170-
tasks
171-
.getByName("bundle${variantName.capitalize()}")
172-
.finalizedBy(renameTaskName)
173-
}
174-
}
175-
176152
compileOptions {
177153
sourceCompatibility(libs.versions.jvmTarget.get())
178154
targetCompatibility(libs.versions.jvmTarget.get())
@@ -199,9 +175,50 @@ android {
199175
}
200176
}
201177

178+
androidComponents {
179+
onVariants { appVariant ->
180+
val bundlesDir = "${layout.buildDirectory.get()}/outputs/bundle"
181+
val applicationId = appVariant.applicationId.get()
182+
val flavorName = appVariant.flavorName
183+
val variantName = appVariant.name
184+
val buildType = appVariant.buildType
185+
appVariant
186+
.outputs
187+
.mapNotNull { it as? VariantOutputImpl }
188+
.forEach { output ->
189+
val fileNameWithoutExtension = when (flavorName) {
190+
"fdroid" -> "$applicationId-$flavorName"
191+
"standard" -> applicationId
192+
else -> output.outputFileName.get().removeExtensionIfPresent(".apk")
193+
}
194+
195+
// Set the APK output filename.
196+
output.outputFileName.set("$fileNameWithoutExtension.apk")
197+
198+
val renameTaskName = "rename${variantName.uppercaseFirstChar()}AabFiles"
199+
tasks.register(renameTaskName) {
200+
group = "build"
201+
description = "Renames the bundle files for $variantName variant"
202+
doLast {
203+
val namespace = appVariant.namespace.get()
204+
renameFile(
205+
"$bundlesDir/$variantName/$namespace-$flavorName-$buildType.aab",
206+
"$fileNameWithoutExtension.aab",
207+
)
208+
}
209+
}
210+
// Force renaming task to execute after the variant is built.
211+
val bundleTaskName = "bundle${variantName.uppercaseFirstChar()}"
212+
tasks
213+
.named { it == bundleTaskName }
214+
.configureEach { finalizedBy(renameTaskName) }
215+
}
216+
}
217+
}
218+
202219
kotlin {
203220
compilerOptions {
204-
jvmTarget = JvmTarget.fromTarget(libs.versions.jvmTarget.get())
221+
jvmTarget.set(JvmTarget.fromTarget(libs.versions.jvmTarget.get()))
205222
}
206223
}
207224

authenticator/build.gradle.kts

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
1+
import com.android.build.api.dsl.ApplicationExtension
2+
import com.android.build.api.variant.impl.VariantOutputImpl
23
import com.google.protobuf.gradle.proto
3-
import dagger.hilt.android.plugin.util.capitalize
4+
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
45
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
56
import java.io.FileInputStream
67
import java.util.Properties
@@ -29,27 +30,35 @@ val ciProperties = Properties().apply {
2930
}
3031
}
3132

32-
android {
33-
namespace = "com.bitwarden.authenticator"
34-
compileSdk = libs.versions.compileSdk.get().toInt()
33+
base {
34+
// Set the base archive name for publishing purposes. This is used to derive the
35+
// APK and AAB artifact names when uploading to Firebase and Play Store.
36+
archivesName.set("com.bitwarden.authenticator")
37+
}
38+
39+
room {
40+
schemaDirectory("$projectDir/schemas")
41+
}
3542

36-
room {
37-
schemaDirectory("$projectDir/schemas")
43+
configure<ApplicationExtension> {
44+
namespace = "com.bitwarden.authenticator"
45+
compileSdk {
46+
version = release(libs.versions.compileSdk.get().toInt())
3847
}
3948

4049
defaultConfig {
4150
applicationId = "com.bitwarden.authenticator"
42-
minSdk = libs.versions.minSdkBwa.get().toInt()
43-
targetSdk = libs.versions.targetSdk.get().toInt()
51+
minSdk {
52+
version = release(libs.versions.minSdkBwa.get().toInt())
53+
}
54+
targetSdk {
55+
version = release(libs.versions.targetSdk.get().toInt())
56+
}
4457
versionCode = libs.versions.appVersionCode.get().toInt()
4558
versionName = libs.versions.appVersionName.get()
4659

4760
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
4861

49-
// Set the base archive name for publishing purposes. This is used to derive the APK and AAB
50-
// artifact names when uploading to Firebase and Play Store.
51-
base.archivesName = "com.bitwarden.authenticator"
52-
5362
buildConfigField(
5463
type = "String",
5564
name = "CI_INFO",
@@ -108,32 +117,6 @@ android {
108117
buildConfigField(type = "boolean", name = "HAS_DEBUG_MENU", value = "false")
109118
}
110119
}
111-
applicationVariants.all {
112-
val bundlesDir = "${layout.buildDirectory.get()}/outputs/bundle"
113-
outputs
114-
.mapNotNull { it as? BaseVariantOutputImpl }
115-
.forEach { output ->
116-
// Set the APK output filename.
117-
output.outputFileName = "$applicationId.apk"
118-
119-
val variantName = name
120-
val renameTaskName = "rename${variantName.capitalize()}AabFiles"
121-
tasks.register(renameTaskName) {
122-
group = "build"
123-
description = "Renames the bundle files for $variantName variant"
124-
doLast {
125-
renameFile(
126-
"$bundlesDir/$variantName/$namespace-${buildType.name}.aab",
127-
"$applicationId.aab",
128-
)
129-
}
130-
}
131-
// Force renaming task to execute after the variant is built.
132-
tasks
133-
.getByName("bundle${variantName.capitalize()}")
134-
.finalizedBy(renameTaskName)
135-
}
136-
}
137120
compileOptions {
138121
sourceCompatibility(libs.versions.jvmTarget.get())
139122
targetCompatibility(libs.versions.jvmTarget.get())
@@ -167,9 +150,43 @@ android {
167150
}
168151
}
169152

153+
androidComponents {
154+
onVariants { appVariant ->
155+
val bundlesDir = "${layout.buildDirectory.get()}/outputs/bundle"
156+
val applicationId = appVariant.applicationId.get()
157+
val variantName = appVariant.name
158+
val buildType = appVariant.buildType
159+
appVariant
160+
.outputs
161+
.mapNotNull { it as? VariantOutputImpl }
162+
.forEach { output ->
163+
// Set the APK output filename.
164+
output.outputFileName.set("$applicationId.apk")
165+
166+
val renameTaskName = "rename${variantName.uppercaseFirstChar()}AabFiles"
167+
tasks.register(renameTaskName) {
168+
group = "build"
169+
description = "Renames the bundle files for $variantName variant"
170+
doLast {
171+
val namespace = appVariant.namespace.get()
172+
renameFile(
173+
"$bundlesDir/$variantName/$namespace-$buildType.aab",
174+
"$applicationId.aab",
175+
)
176+
}
177+
}
178+
// Force renaming task to execute after the variant is built.
179+
val bundleTaskName = "bundle${variantName.uppercaseFirstChar()}"
180+
tasks
181+
.named { it == bundleTaskName }
182+
.configureEach { finalizedBy(renameTaskName) }
183+
}
184+
}
185+
}
186+
170187
kotlin {
171188
compilerOptions {
172-
jvmTarget = JvmTarget.fromTarget(libs.versions.jvmTarget.get())
189+
jvmTarget.set(JvmTarget.fromTarget(libs.versions.jvmTarget.get()))
173190
}
174191
}
175192

authenticatorbridge/build.gradle.kts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import com.android.build.api.dsl.LibraryExtension
2+
import com.android.build.gradle.tasks.BundleAar
3+
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
14
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
25

36
// For more info on versioning, see the README.
@@ -9,14 +12,18 @@ plugins {
912
alias(libs.plugins.kotlin.serialization)
1013
}
1114

12-
android {
15+
configure<LibraryExtension> {
1316
namespace = "com.bitwarden.authenticatorbridge"
14-
compileSdk = libs.versions.compileSdk.get().toInt()
17+
setVersion(version)
18+
compileSdk {
19+
version = release(libs.versions.compileSdk.get().toInt())
20+
}
1521

1622
defaultConfig {
1723
// This min value is selected to accommodate known consumers
18-
minSdk = libs.versions.minSdkBwa.get().toInt()
19-
24+
minSdk {
25+
version = release(libs.versions.minSdkBwa.get().toInt())
26+
}
2027
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2128
consumerProguardFiles("consumer-rules.pro")
2229
buildConfigField("String", "VERSION", "\"$version\"")
@@ -39,21 +46,23 @@ android {
3946
buildConfig = true
4047
aidl = true
4148
}
42-
// Add version name to the output .aar file:
43-
libraryVariants.all {
44-
val variant = this
45-
outputs
46-
.map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl }
47-
.forEach { output ->
48-
val outputFileName = "authenticatorbridge-$version-${variant.baseName}.aar"
49-
output.outputFileName = outputFileName
49+
}
50+
51+
androidComponents {
52+
onVariants { libVariant ->
53+
val bundleTaskName = "bundle${libVariant.name.uppercaseFirstChar()}Aar"
54+
tasks
55+
.withType<BundleAar>()
56+
.named { it == bundleTaskName }
57+
.configureEach {
58+
archiveFileName.set("authenticatorbridge-$version-${libVariant.name}.aar")
5059
}
5160
}
5261
}
5362

5463
kotlin {
5564
compilerOptions {
56-
jvmTarget = JvmTarget.fromTarget(libs.versions.jvmTarget.get())
65+
jvmTarget.set(JvmTarget.fromTarget(libs.versions.jvmTarget.get()))
5766
}
5867
}
5968

0 commit comments

Comments
 (0)