Skip to content

Commit dc73426

Browse files
committed
Start migration to AGP 9.0.0
1 parent 28352bf commit dc73426

File tree

40 files changed

+85
-7810
lines changed

40 files changed

+85
-7810
lines changed

android/app/build.gradle.kts

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.android.build.api.variant.BuildConfigField
12
import com.android.build.gradle.internal.tasks.factory.dependsOn
23
import com.github.triplet.gradle.androidpublisher.ReleaseStatus
34
import java.io.FileInputStream
@@ -24,14 +25,13 @@ plugins {
2425
alias(libs.plugins.mullvad.utilities)
2526
alias(libs.plugins.android.application)
2627
alias(libs.plugins.play.publisher)
27-
alias(libs.plugins.kotlin.android)
2828
alias(libs.plugins.kotlin.parcelize)
2929
alias(libs.plugins.kotlin.ksp)
3030
alias(libs.plugins.compose)
3131
alias(libs.plugins.baselineprofile)
3232
alias(libs.plugins.mullvad.unit.test)
33+
alias(libs.plugins.rust.android)
3334
id("de.mannodermaus.android-junit5")
34-
id("net.mullvad.rust-android")
3535
}
3636

3737
val repoRootPath = rootProject.projectDir.absoluteFile.parentFile.absolutePath
@@ -222,69 +222,78 @@ android {
222222
)
223223
}
224224
}
225+
}
226+
227+
androidComponents {
228+
onVariants { variant ->
229+
val mainSources = variant.sources.getByName("main")
230+
mainSources.addStaticSourceDirectory(relayListDirectory)
231+
mainSources.addStaticSourceDirectory(changelogAssetsDirectory)
232+
}
225233

226-
applicationVariants.configureEach {
227-
buildConfigField(
228-
"boolean",
234+
onVariants {
235+
it.buildConfigFields!!.put(
229236
"ENABLE_IN_APP_VERSION_NOTIFICATIONS",
230-
getBooleanProperty("mullvad.app.config.inAppVersionNotifications.enable").toString(),
237+
BuildConfigField(
238+
"boolean",
239+
getBooleanProperty("mullvad.app.config.inAppVersionNotifications.enable"),
240+
"Show in-app version notifications",
241+
),
231242
)
232243
val shouldRequireBundleRelayFile = isReleaseBuild() && !appVersion.isDev
233-
buildConfigField(
234-
"Boolean",
244+
it.buildConfigFields!!.put(
235245
"REQUIRE_BUNDLED_RELAY_FILE",
236-
shouldRequireBundleRelayFile.toString(),
246+
BuildConfigField(
247+
"boolean",
248+
shouldRequireBundleRelayFile.toString(),
249+
"Whether to require a bundled relay list or not.",
250+
),
237251
)
238252
}
253+
onVariants {
254+
val productFlavors = it.productFlavors.map { it.first }
255+
// buildType.name?
256+
val buildType = it.buildType
239257

240-
applicationVariants.all {
241258
val artifactSuffix = buildString {
242-
productFlavors.getOrNull(0)?.name?.let { billingFlavorName ->
259+
productFlavors.getOrNull(0)?.let { billingFlavorName ->
243260
if (billingFlavorName != Flavors.OSS) {
244261
append(".$billingFlavorName")
245262
}
246263
}
247264

248-
productFlavors.getOrNull(1)?.name?.let { infrastructureFlavorName ->
265+
productFlavors.getOrNull(1)?.let { infrastructureFlavorName ->
249266
if (infrastructureFlavorName != Flavors.PROD) {
250267
append(".$infrastructureFlavorName")
251268
}
252269
}
253270

254-
if (buildType.name != BuildTypes.RELEASE) {
255-
append(".${buildType.name}")
271+
if (buildType != BuildTypes.RELEASE) {
272+
append(".${buildType}")
256273
}
257274
}
258275

259276
val variantName = name
260277
val capitalizedVariantName = variantName.toString().capitalized()
261-
val artifactName = "MullvadVPN-${versionName}${artifactSuffix}"
262-
263-
tasks.register<Copy>("create${capitalizedVariantName}DistApk") {
264-
from(packageApplicationProvider)
265-
into("${rootDir.parent}/dist")
266-
include { it.name.endsWith(".apk") }
267-
rename { "$artifactName.apk" }
268-
}
269-
270-
val createDistBundle =
271-
tasks.register<Copy>("create${capitalizedVariantName}DistBundle") {
272-
from("${layout.buildDirectory.get()}/outputs/bundle/$variantName")
273-
into("${rootDir.parent}/dist")
274-
include { it.name.endsWith(".aab") }
275-
rename { "$artifactName.aab" }
276-
}
277-
278-
createDistBundle.dependsOn("bundle$capitalizedVariantName")
279-
280-
// Ensure that we have all the JNI libs before merging them.
281-
tasks["merge${capitalizedVariantName}JniLibFolders"].apply {
282-
// This is required for the merge task to run every time the .so files are updated.
283-
// See this comment for more information:
284-
// https://github.com/mozilla/rust-android-gradle/issues/118#issuecomment-1569407058
285-
inputs.dir(rustJniLibsDir)
286-
dependsOn("cargoBuild")
287-
}
278+
val artifactName = "MullvadVPN-${appVersion.name}${artifactSuffix}"
279+
280+
// TODO How to access packageApplicationProvider?
281+
// Replace with: it.outputProviders.provideApkOutputToTask() ?
282+
// tasks.register<Copy>("create${capitalizedVariantName}DistApk") {
283+
// from(packageApplicationProvider)
284+
// into("${rootDir.parent}/dist")
285+
// include { it.name.endsWith(".apk") }
286+
// rename { "$artifactName.apk" }
287+
// }
288+
289+
// val createDistBundle =
290+
// tasks.register<Copy>("create${capitalizedVariantName}DistBundle") {
291+
// from("${layout.buildDirectory.get()}/outputs/bundle/$variantName")
292+
// into("${rootDir.parent}/dist")
293+
// include { it.name.endsWith(".aab") }
294+
// rename { "$artifactName.aab" }
295+
// }
296+
// createDistBundle.dependsOn("bundle$capitalizedVariantName")
288297

289298
tasks.findByPath("generate${capitalizedVariantName}BaselineProfile")?.let {
290299
it.doLast {
@@ -298,12 +307,20 @@ android {
298307
}
299308
}
300309

301-
junitPlatform {
302-
instrumentationTests {
303-
version.set(libs.versions.junit5.android.asProvider())
304-
includeExtensions.set(true)
310+
// Don't merge the jni lib folders until after the Rust libraries have been built.
311+
tasks
312+
.matching { it.name.matches(Regex("merge.*JniLibFolders")) }
313+
.configureEach {
314+
inputs.dir(rustJniLibsDir)
315+
dependsOn("cargoBuild")
305316
}
306-
}
317+
318+
// junitPlatform {
319+
// instrumentationTests {
320+
// version.set(libs.versions.junit5.android.asProvider())
321+
// includeExtensions.set(true)
322+
// }
323+
// }
307324

308325
cargo {
309326
val isReleaseBuild = isReleaseBuild()

android/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ plugins {
1111
alias(libs.plugins.ktfmt) apply false
1212
alias(libs.plugins.compose) apply false
1313
alias(libs.plugins.play.publisher) apply false
14-
alias(libs.plugins.kotlin.android) apply false
1514
alias(libs.plugins.kotlin.ksp) apply false
1615
alias(libs.plugins.kotlin.parcelize) apply false
1716
alias(libs.plugins.protobuf.core) apply false
18-
id("net.mullvad.rust-android") apply false
17+
alias(libs.plugins.rust.android) apply false
1918

2019
alias(libs.plugins.detekt) apply true
2120
alias(libs.plugins.dependency.versions) apply true

android/gradle/build-logic/src/main/kotlin/AndroidLibraryPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import com.android.build.gradle.LibraryExtension
1+
import com.android.build.api.dsl.CommonExtension
2+
import com.android.build.api.dsl.LibraryExtension
23
import org.gradle.api.Plugin
34
import org.gradle.api.Project
45
import org.gradle.internal.Actions.with
@@ -12,7 +13,6 @@ class AndroidLibraryPlugin : Plugin<Project> {
1213
override fun apply(target: Project) {
1314
with(target) {
1415
apply(plugin = "com.android.library")
15-
apply(plugin = "org.jetbrains.kotlin.android")
1616
apply(plugin = "mullvad.kotlin-toolchain")
1717

1818
extensions.configure<LibraryExtension> {

android/gradle/build-logic/src/main/kotlin/utilities/AndroidCompose.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.android.build.api.dsl.CommonExtension
44
import org.gradle.api.Project
55
import org.gradle.kotlin.dsl.dependencies
66

7-
internal fun Project.configureAndroidCompose(commonExtension: CommonExtension<*, *, *, *, *, *>) {
7+
internal fun Project.configureAndroidCompose(commonExtension: CommonExtension) {
88
commonExtension.apply {
99
buildFeatures.apply { compose = true }
1010

android/gradle/libs.versions.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ndk = "27.3.13750724"
1414
# Find the relevant AAPT version here:
1515
# https://mvnrepository.com/artifact/com.android.tools.build/aapt2
1616
android-gradle-aapt = "14304508"
17-
android-gradle-plugin = "8.13.2"
17+
android-gradle-plugin = "9.1.0"
1818
# Other
1919
android-billingclient = "8.3.0"
2020
androidx-activitycompose = "1.13.0"
@@ -35,7 +35,7 @@ androidx-tv = "1.0.1"
3535
androidx-uiautomator = "2.4.0-beta02"
3636
androidx-work = "2.11.2"
3737
arrow = "2.2.2.1"
38-
baselineprofile = "1.4.1"
38+
baselineprofile = "1.5.0-alpha04"
3939
benchmark-macro-junit4 = "1.4.1"
4040
commonsvalidator = "1.10.1"
4141
compose = "1.10.6"
@@ -50,8 +50,8 @@ grpc = "1.80.0"
5050
grpc-kotlin = "1.5.0"
5151
junit = "5.13.4"
5252
junit4 = "1.3.0"
53-
junit5-android = "1.8.0"
54-
junit5-android-plugin = "1.13.1.0"
53+
junit5-android = "2.0.1"
54+
junit5-android-plugin = "2.0.1"
5555
kermit = "2.1.0"
5656
koin = "4.2.0"
5757
koin-compose = "4.2.0"
@@ -66,7 +66,7 @@ ktfmt = "0.26.0"
6666
ktor = "3.4.1"
6767
leakcanary = "2.14"
6868
mockk = "1.14.9"
69-
play-publisher = "3.13.0"
69+
play-publisher = "4.0.0"
7070
play-services-location = "21.3.0"
7171
profileinstaller = "1.4.1"
7272
protobuf = "4.34.1"
@@ -75,6 +75,7 @@ turbine = "1.2.1"
7575
annotation-jvm = "1.9.1"
7676
junit-version = "4.13.2"
7777
material = "1.13.0"
78+
rust-android = "0.10.0"
7879

7980
[libraries]
8081
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" }
@@ -197,6 +198,7 @@ ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" }
197198
play-publisher = { id = "com.github.triplet.play", version.ref = "play-publisher" }
198199
protobuf-core = { id = "com.google.protobuf", version.ref = "protobuf-gradle-plugin" }
199200
protobuf-protoc = { id = "com.google.protobuf:protoc", version.ref = "protobuf" }
201+
rust-android = { id = "net.mullvad.rust-android", version.ref = "rust-android" }
200202
# Convention plugins
201203
mullvad-android-library = { id = "mullvad.android-library" }
202204
mullvad-android-library-feature-api = { id = "mullvad.android-library-feature-api" }

0 commit comments

Comments
 (0)