Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 63 additions & 46 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.android.build.api.variant.BuildConfigField
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.github.triplet.gradle.androidpublisher.ReleaseStatus
import java.io.FileInputStream
Expand All @@ -24,14 +25,13 @@ plugins {
alias(libs.plugins.mullvad.utilities)
alias(libs.plugins.android.application)
alias(libs.plugins.play.publisher)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.kotlin.ksp)
alias(libs.plugins.compose)
alias(libs.plugins.baselineprofile)
alias(libs.plugins.mullvad.unit.test)
alias(libs.plugins.rust.android)
id("de.mannodermaus.android-junit5")
id("net.mullvad.rust-android")
}

val repoRootPath = rootProject.projectDir.absoluteFile.parentFile.absolutePath
Expand Down Expand Up @@ -222,69 +222,78 @@ android {
)
}
}
}

androidComponents {
onVariants { variant ->
val mainSources = variant.sources.getByName("main")
mainSources.addStaticSourceDirectory(relayListDirectory)
mainSources.addStaticSourceDirectory(changelogAssetsDirectory)
}

applicationVariants.configureEach {
buildConfigField(
"boolean",
onVariants {
it.buildConfigFields!!.put(
"ENABLE_IN_APP_VERSION_NOTIFICATIONS",
getBooleanProperty("mullvad.app.config.inAppVersionNotifications.enable").toString(),
BuildConfigField(
"boolean",
getBooleanProperty("mullvad.app.config.inAppVersionNotifications.enable"),
"Show in-app version notifications",
),
)
val shouldRequireBundleRelayFile = isReleaseBuild() && !appVersion.isDev
buildConfigField(
"Boolean",
it.buildConfigFields!!.put(
"REQUIRE_BUNDLED_RELAY_FILE",
shouldRequireBundleRelayFile.toString(),
BuildConfigField(
"boolean",
shouldRequireBundleRelayFile.toString(),
"Whether to require a bundled relay list or not.",
),
)
}
onVariants {
val productFlavors = it.productFlavors.map { it.first }
// buildType.name?
val buildType = it.buildType

applicationVariants.all {
val artifactSuffix = buildString {
productFlavors.getOrNull(0)?.name?.let { billingFlavorName ->
productFlavors.getOrNull(0)?.let { billingFlavorName ->
if (billingFlavorName != Flavors.OSS) {
append(".$billingFlavorName")
}
}

productFlavors.getOrNull(1)?.name?.let { infrastructureFlavorName ->
productFlavors.getOrNull(1)?.let { infrastructureFlavorName ->
if (infrastructureFlavorName != Flavors.PROD) {
append(".$infrastructureFlavorName")
}
}

if (buildType.name != BuildTypes.RELEASE) {
append(".${buildType.name}")
if (buildType != BuildTypes.RELEASE) {
append(".${buildType}")
}
}

val variantName = name
val capitalizedVariantName = variantName.toString().capitalized()
val artifactName = "MullvadVPN-${versionName}${artifactSuffix}"

tasks.register<Copy>("create${capitalizedVariantName}DistApk") {
from(packageApplicationProvider)
into("${rootDir.parent}/dist")
include { it.name.endsWith(".apk") }
rename { "$artifactName.apk" }
}

val createDistBundle =
tasks.register<Copy>("create${capitalizedVariantName}DistBundle") {
from("${layout.buildDirectory.get()}/outputs/bundle/$variantName")
into("${rootDir.parent}/dist")
include { it.name.endsWith(".aab") }
rename { "$artifactName.aab" }
}

createDistBundle.dependsOn("bundle$capitalizedVariantName")

// Ensure that we have all the JNI libs before merging them.
tasks["merge${capitalizedVariantName}JniLibFolders"].apply {
// This is required for the merge task to run every time the .so files are updated.
// See this comment for more information:
// https://github.com/mozilla/rust-android-gradle/issues/118#issuecomment-1569407058
inputs.dir(rustJniLibsDir)
dependsOn("cargoBuild")
}
val artifactName = "MullvadVPN-${appVersion.name}${artifactSuffix}"

// TODO How to access packageApplicationProvider?
// Replace with: it.outputProviders.provideApkOutputToTask() ?
// tasks.register<Copy>("create${capitalizedVariantName}DistApk") {
// from(packageApplicationProvider)
// into("${rootDir.parent}/dist")
// include { it.name.endsWith(".apk") }
// rename { "$artifactName.apk" }
// }

// val createDistBundle =
// tasks.register<Copy>("create${capitalizedVariantName}DistBundle") {
// from("${layout.buildDirectory.get()}/outputs/bundle/$variantName")
// into("${rootDir.parent}/dist")
// include { it.name.endsWith(".aab") }
// rename { "$artifactName.aab" }
// }
// createDistBundle.dependsOn("bundle$capitalizedVariantName")

tasks.findByPath("generate${capitalizedVariantName}BaselineProfile")?.let {
it.doLast {
Expand All @@ -298,12 +307,20 @@ android {
}
}

junitPlatform {
instrumentationTests {
version.set(libs.versions.junit5.android.asProvider())
includeExtensions.set(true)
// Don't merge the jni lib folders until after the Rust libraries have been built.
tasks
.matching { it.name.matches(Regex("merge.*JniLibFolders")) }
.configureEach {
inputs.dir(rustJniLibsDir)
dependsOn("cargoBuild")
}
}

// junitPlatform {
// instrumentationTests {
// version.set(libs.versions.junit5.android.asProvider())
// includeExtensions.set(true)
// }
// }

cargo {
val isReleaseBuild = isReleaseBuild()
Expand Down
3 changes: 1 addition & 2 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ plugins {
alias(libs.plugins.ktfmt) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.play.publisher) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.ksp) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.protobuf.core) apply false
id("net.mullvad.rust-android") apply false
alias(libs.plugins.rust.android) apply false

alias(libs.plugins.detekt) apply true
alias(libs.plugins.dependency.versions) apply true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.android.build.gradle.LibraryExtension
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.internal.Actions.with
Expand All @@ -12,7 +13,6 @@ class AndroidLibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
apply(plugin = "com.android.library")
apply(plugin = "org.jetbrains.kotlin.android")
apply(plugin = "mullvad.kotlin-toolchain")

extensions.configure<LibraryExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies

internal fun Project.configureAndroidCompose(commonExtension: CommonExtension<*, *, *, *, *, *>) {
internal fun Project.configureAndroidCompose(commonExtension: CommonExtension) {
commonExtension.apply {
buildFeatures.apply { compose = true }

Expand Down
12 changes: 7 additions & 5 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ndk = "27.3.13750724"
# Find the relevant AAPT version here:
# https://mvnrepository.com/artifact/com.android.tools.build/aapt2
android-gradle-aapt = "14304508"
android-gradle-plugin = "8.13.2"
android-gradle-plugin = "9.0.0"
# Other
android-billingclient = "8.3.0"
androidx-activitycompose = "1.13.0"
Expand All @@ -33,7 +33,7 @@ androidx-tv = "1.0.1"
androidx-uiautomator = "2.4.0-beta02"
androidx-work = "2.11.1"
arrow = "2.2.2"
baselineprofile = "1.4.1"
baselineprofile = "1.5.0-alpha01"
benchmark-macro-junit4 = "1.4.1"
commonsvalidator = "1.10.1"
compose = "1.10.5"
Expand All @@ -49,8 +49,8 @@ grpc = "1.79.0"
grpc-kotlin = "1.5.0"
junit = "5.13.4"
junit4 = "1.3.0"
junit5-android = "1.8.0"
junit5-android-plugin = "1.13.1.0"
junit5-android = "2.0.1"
junit5-android-plugin = "2.0.1"
kermit = "2.1.0"
koin = "4.1.1"
koin-compose = "4.1.1"
Expand All @@ -65,7 +65,7 @@ ktfmt = "0.25.0"
ktor = "3.4.1"
leakcanary = "2.14"
mockk = "1.14.9"
play-publisher = "3.13.0"
play-publisher = "4.0.0"
play-services-location = "21.3.0"
profileinstaller = "1.4.1"
protobuf = "4.34.0"
Expand All @@ -74,6 +74,7 @@ turbine = "1.2.1"
annotation-jvm = "1.9.1"
junit-version = "4.13.2"
material = "1.13.0"
rust-android = "0.10.0"

[libraries]
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" }
Expand Down Expand Up @@ -194,6 +195,7 @@ ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" }
play-publisher = { id = "com.github.triplet.play", version.ref = "play-publisher" }
protobuf-core = { id = "com.google.protobuf", version.ref = "protobuf-gradle-plugin" }
protobuf-protoc = { id = "com.google.protobuf:protoc", version.ref = "protobuf" }
rust-android = { id = "net.mullvad.rust-android", version.ref = "rust-android" }
# Convention plugins
mullvad-android-library = { id = "mullvad.android-library" }
mullvad-android-library-feature-impl = { id = "mullvad.android-library-feature-impl" }
Expand Down
Loading
Loading