3.8 KiB · text History dc2edab
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.android)
    alias(libs.plugins.kotlin.compose)
    alias(libs.plugins.kotlin.serialization)
}

// Bumped by hand; everything after it is generated.
val baseVersion = "0.1.0"

// Seconds, from the environment when it's there. CI sets it once per run
// so every artifact of that run agrees; a local build computes it, which
// is fine because local builds are never published. SOURCE_DATE_EPOCH
// first, because it is the cross-toolchain convention for exactly this.
val buildTimestamp: Long =
    (System.getenv("SOURCE_DATE_EPOCH") ?: System.getenv("BUILD_TIMESTAMP"))
        ?.toLongOrNull()
        ?: (System.currentTimeMillis() / 1000)

// A real release overrides the whole string; until there is one, every
// build says so in its name rather than claiming to be 0.1.0.
val appVersionName: String =
    System.getenv("RELEASE_VERSION")?.takeIf { it.isNotBlank() }
        ?: "$baseVersion-dev-$buildTimestamp"

android {
    namespace = "org.neiam.diogramos.app"
    compileSdk = 34

    defaultConfig {
        applicationId = "org.neiam.diogramos.app"
        minSdk = 26
        targetSdk = 34

        // Android refuses an update whose versionCode is not higher than
        // what is installed, and F-Droid orders by it, so a hardcoded 1
        // would mean no phone ever sees a second release. The CI run
        // number is monotonic and needs no state kept anywhere. Local
        // builds stay at 1; they are never published.
        versionCode = (System.getenv("GITHUB_RUN_NUMBER") ?: "").toIntOrNull() ?: 1
        versionName = appVersionName

        // Host used for the magic-link App Link. Override once the
        // production domain is settled.
        manifestPlaceholders["appLinksHost"] = "diogramos.example.com"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro",
            )
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    buildFeatures {
        compose = true
    }

    lint {
        // assembleRelease is a packaging step here, not a review gate.
        // lintVital doubles the release build and fails for reasons that
        // have nothing to do with this code (it throws on JDK 25 with
        // only the version string as the error), so a release built on a
        // modern local JDK fails while the same commit builds fine in the
        // container's JDK. Lint still runs on demand: ./gradlew :app:lint
        checkReleaseBuilds = false
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime)
    implementation(libs.androidx.lifecycle.viewmodel.compose)
    implementation(libs.androidx.activity.compose)
    implementation(libs.androidx.navigation.compose)
    implementation(libs.androidx.security.crypto)

    implementation(platform(libs.compose.bom))
    implementation(libs.compose.ui)
    implementation(libs.compose.ui.tooling.preview)
    implementation(libs.compose.material3)
    implementation(libs.compose.material.icons)
    debugImplementation(libs.compose.ui.tooling)

    implementation(libs.kotlinx.coroutines)
    implementation(libs.kotlinx.serialization.json)
    implementation(libs.retrofit)
    implementation(libs.retrofit.kotlinx.serialization)
    implementation(libs.okhttp)
    implementation(libs.okhttp.logging)

    implementation(libs.zxing.android.embedded)
    implementation(libs.phoenix.client)

    testImplementation(libs.junit)
}