onionwire/android/app/build.gradle.kts

132 lines
4.9 KiB
Kotlin
Raw Permalink Normal View History

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}
fun envOrNull(name: String): String? =
System.getenv(name)?.takeIf { it.isNotBlank() }
android {
namespace = "com.siriusdevops.onionwire"
compileSdk = 36
// Same ABI selection as :sdk. JNA ships libjnidispatch.so for several ABIs;
// without this filter the APK carries native code for ABIs we never built
// our Rust lib for.
val onionwireAbis: List<String> = (findProperty("onionwire.abis") as String?)
?.split(',')?.map(String::trim)?.filter(String::isNotEmpty)
?: listOf("arm64-v8a")
defaultConfig {
applicationId = "com.siriusdevops.onionwire"
minSdk = 26
targetSdk = 36
// CI/local release scripts override both via -P. Committed values are
// the offline default and match the first automated tag (v0.1.0 → 100).
versionCode = (findProperty("onionwire.versionCode") as String?)?.toIntOrNull() ?: 100
versionName = (findProperty("onionwire.versionName") as String?) ?: "0.1.0"
ndk {
abiFilters += onionwireAbis
}
}
signingConfigs {
create("release") {
val ksPath = envOrNull("ANDROID_KEYSTORE_FILE")
if (ksPath != null) {
storeFile = file(ksPath)
storePassword = envOrNull("ANDROID_KEYSTORE_PASSWORD")
?: error("ANDROID_KEYSTORE_PASSWORD is required when ANDROID_KEYSTORE_FILE is set")
keyAlias = envOrNull("ANDROID_KEY_ALIAS")
?: error("ANDROID_KEY_ALIAS is required when ANDROID_KEYSTORE_FILE is set")
keyPassword = envOrNull("ANDROID_KEY_PASSWORD")
?: error("ANDROID_KEY_PASSWORD is required when ANDROID_KEYSTORE_FILE is set")
}
}
}
buildTypes {
debug {
// Sideload / device-test builds. Signed with the standard debug key.
applicationIdSuffix = ".debug"
versionNameSuffix = "-debug"
}
release {
// Deliberately NOT minified in this card: there is no on-device
// crash-deobfuscation story yet, and shipping R8 without testing
// the JNI/uniffi surface on a real device is how you get a
// mysterious UnsatisfiedLinkError in the field.
// Enable together with mapping-file upload; keeps already exist in
// :sdk/consumer-rules.pro.
isMinifyEnabled = false
isShrinkResources = false
// Repo-owned release keystore via ANDROID_KEYSTORE_* env (Forgejo
// secrets in CI, ~/.android/onionwire-release.env locally). CI sets
// ONIONWIRE_REQUIRE_RELEASE_KEY=true and fails closed if missing —
// the debug keystore is per-machine and would break in-place upgrades.
val requireReleaseKey =
(findProperty("onionwire.requireReleaseKey") as String?) == "true" ||
envOrNull("ONIONWIRE_REQUIRE_RELEASE_KEY") == "true"
val releaseSigning = signingConfigs.getByName("release")
val releaseStore = releaseSigning.storeFile
signingConfig = when {
releaseStore != null && releaseStore.isFile -> releaseSigning
requireReleaseKey -> error(
"Release keystore required but ANDROID_KEYSTORE_FILE is missing or not a file"
)
else -> {
logger.warn(
"No ANDROID_KEYSTORE_FILE; signing the release APK with the debug keystore. " +
"CI must not do this — in-place upgrades will break."
)
signingConfigs.getByName("debug")
}
}
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
dependencies {
implementation(project(":sdk"))
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.navigation.compose)
implementation(platform(libs.compose.bom))
implementation(libs.compose.ui)
implementation(libs.compose.ui.graphics)
implementation(libs.compose.ui.tooling.preview)
implementation(libs.compose.material3)
debugImplementation(libs.compose.ui.tooling)
testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
}