3.3 KiB · text History 24a90d7
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.android)
    alias(libs.plugins.kotlin.compose)
}

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

// Seconds, and taken from the environment when it's there. CI sets it
// once per run so every artifact from that run agrees; a local build
// computes it, which is fine because local builds are never published.
//
// SOURCE_DATE_EPOCH first because it's the cross-toolchain convention
// for exactly this, and honouring it means a reproducible-build harness
// that already sets it gets a reproducible versionName for free.
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.mediabubbles"
    compileSdk = 34

    defaultConfig {
        applicationId = "org.neiam.mediabubbles"
        minSdk = 26
        targetSdk = 34
        // Android refuses an update whose versionCode isn't higher than
        // what's installed, and F-Droid orders versions by it — so a
        // hardcoded 1 means no phone ever sees a second release. It also
        // means every CI build publishes the same filename with
        // different bytes, which the registry correctly refuses with a
        // 409.
        //
        // The CI run number is monotonic and needs no state kept
        // anywhere. Local builds stay at 1, which is fine: they are
        // never published.
        versionCode = (System.getenv("GITHUB_RUN_NUMBER") ?: "").toIntOrNull() ?: 1

        // Not the commit: versionCode is the CI run number, and a run
        // knows its own commit, so the sha is one lookup away and the
        // timestamp orders builds at a glance in a list that versionCode
        // alone renders as bare integers.
        versionName = appVersionName
    }

    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
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime)
    implementation(libs.androidx.lifecycle.service)
    implementation(libs.androidx.lifecycle.runtime.compose)
    implementation(libs.androidx.activity.compose)

    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)

    testImplementation(libs.junit)
}