diff options
| author | Albin <albin@mullvad.net> | 2023-04-24 16:37:00 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-04-24 16:37:00 +0200 |
| commit | de32b2910ce30cc48f8d8537d56042cb8ee406ae (patch) | |
| tree | 8d97cd606daa31b203967b8ef92280f4ed2c0f1c /android | |
| parent | 1fbbf6517c9948c53689d2b1847c8adc2aa404ea (diff) | |
| parent | 21dc63a714d8a6d40fa314ea1845cf092dece421 (diff) | |
| download | mullvadvpn-de32b2910ce30cc48f8d8537d56042cb8ee406ae.tar.xz mullvadvpn-de32b2910ce30cc48f8d8537d56042cb8ee406ae.zip | |
Merge branch 'allow-version-override-using-local-droid-113'
Diffstat (limited to 'android')
| -rw-r--r-- | android/BuildInstructions.md | 48 | ||||
| -rw-r--r-- | android/app/build.gradle.kts | 9 | ||||
| -rw-r--r-- | android/buildSrc/src/main/kotlin/Utils.kt | 28 |
3 files changed, 65 insertions, 20 deletions
diff --git a/android/BuildInstructions.md b/android/BuildInstructions.md index c86dc353c7..8ab2da6d20 100644 --- a/android/BuildInstructions.md +++ b/android/BuildInstructions.md @@ -9,10 +9,11 @@ environment. The build process consist of two main steps. First building the native libraries (`mullvad-daemon` and `wireguard-go`) and then building the Android app/project which will bundle the previously built native libraries. Building the native libraries requires some specific toolchains and packages to be -installed, so it's recommended to build using the provided build script and container image. The -native libraries doesn't have to be rebuilt very often, only when including daemon changes or after -cleaning the project, so apart from that it's possible to build using the Gradle CLI or -the Android Studio GUI. +installed, so it's recommended to build using the provided build script and container image. + +The native libraries doesn't have to be rebuilt very often, only when including daemon changes or +after cleaning the project, so apart from that it's possible to build the Android app/project using +the Gradle CLI or the Android Studio GUI. ## Build with provided container (recommended) @@ -20,9 +21,24 @@ Building both the native libraries and Android project can easily be achieved by [containerized-build.sh](../building/containerized-build.sh) script, which helps using the correct tag and mounting volumes. The script relies on [podman](https://podman.io/getting-started/installation.html) by default, however another container runner such as [docker](https://docs.docker.com/get-started/) -can be used by setting the `CONTAINER_RUNNER` environment variable. Subsequent builds can that -doesn't rely on changes to the native libraries can be ran using the Gradle CLI or the Android -Studio GUI. +can be used by setting the `CONTAINER_RUNNER` environment variable. + +After the native libraries have been built, subsequent builds can that doesn't rely on changes to +the native libraries can be ran using the Gradle CLI or the Android Studio GUI. This requires +either: +* Rust to be installed, since a tooled called `mullvad-version` is used to resolved the version + information for the Android app. + +or + +* Specifying custom version information by following [these instructions](#override-version-code-and-version-name). + +### Setup: + +- Install [podman](https://podman.io/getting-started/installation.html) and make sure it's + configured to run in rootless mode. + +- OPTIONAL: Get the latest **stable** Rust toolchain via [rustup.rs](https://rustup.rs/). ### Debug build Run the following command to trigger a full debug build: @@ -202,3 +218,21 @@ This is easiest done by temporarily removing the lockfile: ```bash rm ./gradle/verification-metadata.xml ``` + +## Gradle properties +Some gradle properties can be set to simplify development. These are listed below. + +### Always show changelog +For development purposes, `ALWAYS_SHOW_CHANGELOG` can be set in `local.properties` to always show +the changelog dialog on each app start. For example: +``` +ALWAYS_SHOW_CHANGELOG=true +``` + +### Override version code and version name +To avoid or override the rust based version generation, the `OVERRIDE_VERSION_CODE` and +`OVERRIDE_VERSION_NAME` properties can be set in `local.properties`. For example: +``` +OVERRIDE_VERSION_CODE=123 +OVERRIDE_VERSION_NAME=1.2.3 +``` diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 46b70c0607..d6b59b6a2d 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -28,15 +28,16 @@ android { compileSdk = Versions.Android.compileSdkVersion defaultConfig { + val localProperties = gradleLocalProperties(rootProject.projectDir) + applicationId = "net.mullvad.mullvadvpn" minSdk = Versions.Android.minSdkVersion targetSdk = Versions.Android.targetSdkVersion - versionCode = generateVersionCode() - versionName = generateVersionName() + versionCode = generateVersionCode(localProperties) + versionName = generateVersionName(localProperties) testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - val alwaysShowChangelog = gradleLocalProperties(rootProject.projectDir) - .getProperty("ALWAYS_SHOW_CHANGELOG") ?: "false" + val alwaysShowChangelog = localProperties.getProperty("ALWAYS_SHOW_CHANGELOG") ?: "false" buildConfigField( type = "boolean", name = "ALWAYS_SHOW_CHANGELOG", diff --git a/android/buildSrc/src/main/kotlin/Utils.kt b/android/buildSrc/src/main/kotlin/Utils.kt index 96c44b78c2..a3f3759960 100644 --- a/android/buildSrc/src/main/kotlin/Utils.kt +++ b/android/buildSrc/src/main/kotlin/Utils.kt @@ -1,8 +1,26 @@ import java.io.ByteArrayOutputStream +import java.util.* import org.gradle.api.Project import org.gradle.process.ExecSpec -fun Project.execWithOutput(spec: ExecSpec.() -> Unit) = +fun Project.generateVersionCode(localProperties: Properties): Int { + return localProperties.getProperty("OVERRIDE_VERSION_CODE")?.toIntOrNull() + ?: execVersionCodeCargoCommand() +} + +fun Project.generateVersionName(localProperties: Properties): String { + return localProperties.getProperty("OVERRIDE_VERSION_NAME") ?: execVersionNameCargoCommand() +} + +private fun Project.execVersionCodeCargoCommand() = + execWithOutput { commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionCode") } + .toInt() + +private fun Project.execVersionNameCargoCommand() = execWithOutput { + commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionName") +} + +private fun Project.execWithOutput(spec: ExecSpec.() -> Unit) = ByteArrayOutputStream().use { outputStream -> exec { this.spec() @@ -10,11 +28,3 @@ fun Project.execWithOutput(spec: ExecSpec.() -> Unit) = } outputStream.toString().trim() } - -fun Project.generateVersionCode() = execWithOutput { - commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionCode") -}.toInt() - -fun Project.generateVersionName() = execWithOutput { - commandLine("cargo", "run", "-q", "--bin", "mullvad-version", "versionName") -} |
