Files
tsunagi/android/app/build.gradle
T
Aleksandr Bogomiakov 429fa36e3e Publish a signed Android APK with GitHub releases
Build the ARM64 app on version tags alongside the desktop builds. Stamp
the APK with the tag version and the Release workflow run number so that
updates advance and reruns keep the same code. Sign with the repository's
persistent PKCS12 key in a separate step. Only the verified APK goes into
the run artifact and the release. Require it for both creation and reruns.

Use the same NDK for Cargo and Gradle's native strip step. Check the actual
APK's package, version, release mode, ARM64 library, alignment and signature.
Keep local debug version defaults. Document the two signing secrets, key
backup and the effect of switching from the debug build on a mesh identity.

On macOS, built the debug and release APKs, signed the release with a
throwaway key, and verified its certificate. Checked rejection of missing
credentials, a wrong password, an unsigned APK, a debug APK, incorrect
versions and an unstripped native library. Exercised the release-create
and rerun paths with a local gh stand-in, including a missing artifact.
Actionlint, ShellCheck, cargo fmt, locked all-target workspace Clippy with
warnings denied, and workspace tests passed (547 passed, 2 ignored).
No live release or signing credentials were created in GitHub.
2026-11-24 17:41:44 +02:00

67 lines
2.7 KiB
Groovy

import groovy.json.JsonSlurper
plugins { id 'com.android.application' version '9.2.1' }
def workspace = rootProject.projectDir.parentFile
def abi = 'arm64-v8a'
android {
namespace 'cy.hexor.tsunagi'
compileSdk 35
def cargoNdk = providers.environmentVariable('ANDROID_NDK_HOME')
if (cargoNdk.isPresent()) {
ndkPath = cargoNdk.get()
def ndkProperties = new Properties()
file("$ndkPath/source.properties").withInputStream { ndkProperties.load(it) }
ndkVersion = ndkProperties.getProperty('Pkg.Revision')
}
// Cargo also builds standalone cdylibs for these dependencies. Their code
// is linked into tsunagi_android; the JVM loads only the application library.
packaging.jniLibs.excludes += ['**/libboringtun.so', '**/libiroh.so', '**/libiroh_relay.so']
defaultConfig {
applicationId 'cy.hexor.tsunagi'
minSdk 26
targetSdk 35
versionCode providers.gradleProperty('tsunagiVersionCode').getOrElse('1').toInteger()
versionName providers.gradleProperty('tsunagiVersionName').getOrElse('1.0.0')
ndk { abiFilters abi }
}
}
// rustls ships its Android trust manager as an AAR in the locked Cargo package.
def metadata = providers.exec {
workingDir workspace
commandLine 'cargo', 'metadata', '--locked', '--format-version', '1', '--filter-platform', 'aarch64-linux-android'
}.standardOutput.asText.get()
def verifier = new JsonSlurper().parseText(metadata).packages.find { it.name == 'rustls-platform-verifier-android' }
repositories {
maven {
url new File(new File(verifier.manifest_path).parent, 'maven')
metadataSources { mavenPom() }
content { includeModule 'rustls', 'rustls-platform-verifier' }
}
google()
mavenCentral()
}
dependencies { implementation "rustls:rustls-platform-verifier:${verifier.version}" }
abstract class BuildRust extends Exec {
@OutputDirectory abstract DirectoryProperty getJniLibs()
}
androidComponents.onVariants(androidComponents.selector().all()) { variant ->
def mode = variant.buildType
def libs = layout.buildDirectory.dir("generated/rust/${mode}")
def nativeBuild = tasks.register("cargo${mode.capitalize()}", BuildRust) {
workingDir workspace
inputs.files(fileTree(workspace) {
include 'Cargo.toml', 'Cargo.lock', '.cargo/**', 'crates/**/Cargo.toml', 'crates/**/src/**', 'vendor/**'
})
jniLibs.set(libs)
commandLine 'cargo', 'ndk', '--target', abi, '--platform', '26', '-o', libs.get().asFile,
'build', '--locked', '--lib', '-p', 'tsunagi-android'
if (mode == 'release') args '--release'
}
variant.sources.jniLibs.addGeneratedSourceDirectory(nativeBuild) { it.jniLibs }
}