Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0

- name: Validate gradle wrapper checksum
uses: gradle/actions/wrapper-validation@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0

- name: Set up JDK 21
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
with:
distribution: 'temurin'
java-version: 21
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
echo "version=${version}" >> "${GITHUB_OUTPUT}"

- name: Check out repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1

- name: Create release
uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090 # v2.4.1
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
with:
tag_name: v${{ steps.get_version.outputs.version }}
name: Version ${{ steps.get_version.outputs.version }}
Expand Down
80 changes: 44 additions & 36 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Andrew Gunnerson
* SPDX-FileCopyrightText: 2022-2026 Andrew Gunnerson
* SPDX-License-Identifier: GPL-3.0-only
*/

import com.android.build.api.artifact.SingleArtifact
import com.android.build.api.variant.VariantOutputConfiguration
import org.eclipse.jgit.api.ArchiveCommand
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.archive.TarFormat
import org.eclipse.jgit.lib.ObjectId
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
import org.json.JSONObject

plugins {
Expand All @@ -21,24 +24,22 @@ java {

buildscript {
dependencies {
"classpath"(libs.jgit)
"classpath"(libs.jgit.archive)
"classpath"(libs.json)
classpath(libs.jgit)
classpath(libs.jgit.archive)
classpath(libs.json)
}
}

typealias VersionTriple = Triple<String?, Int, ObjectId>

fun<T> MutableList<T>.pop(): T = removeAt(size - 1)

fun describeVersion(git: Git): VersionTriple {
// jgit doesn't provide a nice way to get strongly-typed objects from its `describe` command
val describeStr = git.describe().setLong(true).call()

return if (describeStr != null) {
val pieces = describeStr.split('-').toMutableList()
val commit = git.repository.resolve(pieces.pop().substring(1))
val count = pieces.pop().toInt()
val commit = git.repository.resolve(pieces.removeLast().substring(1))
val count = pieces.removeLast().toInt()
val tag = pieces.joinToString("-")

Triple(tag, count, commit)
Expand Down Expand Up @@ -123,13 +124,6 @@ android {
versionCode = gitVersionCode
versionName = gitVersionName
}
sourceSets {
getByName("main") {
assets {
srcDir(archiveDir)
}
}
}
buildTypes {
getByName("debug") {
signingConfig = null
Expand All @@ -153,6 +147,14 @@ android {
}
}

androidComponents.onVariants { variant ->
variant.sources.assets!!.addGeneratedSourceDirectory(archive) {
project.objects.directoryProperty().apply {
set(archiveDir)
}
}
}

val archive = tasks.register("archive") {
inputs.property("gitVersionTriple.third", gitVersionTriple.third)

Expand All @@ -177,33 +179,40 @@ val archive = tasks.register("archive") {
}
}

android.applicationVariants.all {
val variant = this
val capitalized = variant.name.replaceFirstChar { it.uppercase() }
androidComponents.onVariants { variant ->
val capitalized = variant.name.uppercaseFirstChar()
val variantDir = extraDir.map { it.dir(variant.name) }

variant.preBuildProvider.configure {
dependsOn(archive)
val variantOutput = variant.outputs.first {
it.outputType == VariantOutputConfiguration.OutputType.SINGLE
}
val variantVersionCode = variantOutput.versionCode
val variantVersionName = variantOutput.versionName
val variantApkFiles = variant.artifacts.get(SingleArtifact.APK).map {
variant.artifacts.getBuiltArtifactsLoader().load(it)!!.elements.map { element ->
element.outputFile
}
}

variant.lifecycleTasks.registerPreBuild(archive)

val moduleProp = tasks.register("moduleProp${capitalized}") {
inputs.property("projectUrl", projectUrl)
inputs.property("releaseMetadataBranch", releaseMetadataBranch)
inputs.property("rootProject.name", rootProject.name)
inputs.property("variant.applicationId", variant.applicationId)
inputs.property("variant.name", variant.name)
inputs.property("variant.versionCode", variant.versionCode)
inputs.property("variant.versionName", variant.versionName)
inputs.property("variantVersionCode", variantVersionCode)
inputs.property("variantVersionName", variantVersionName)

val outputFile = variantDir.map { it.file("module.prop") }
outputs.file(outputFile)

doLast {
val props = LinkedHashMap<String, String>()
props["id"] = variant.applicationId
props["id"] = variant.applicationId.get()
props["name"] = rootProject.name
props["version"] = "v${variant.versionName}"
props["versionCode"] = variant.versionCode.toString()
props["version"] = "v${variantVersionName.get()}"
props["versionCode"] = variantVersionCode.get().toString()
props["author"] = "chenxiaolong"
props["description"] = "Change PackageManager installer fields on boot"

Expand All @@ -220,20 +229,19 @@ android.applicationVariants.all {
inputs.property("rootProject.name", rootProject.name)
inputs.property("variant.applicationId", variant.applicationId)
inputs.property("variant.name", variant.name)
inputs.property("variant.versionName", variant.versionName)
inputs.property("variantVersionName", variantVersionName)
inputs.files(variantApkFiles)

archiveFileName.set("${rootProject.name}-${variant.versionName}-${variant.name}.zip")
archiveFileName.set("${rootProject.name}-${variantVersionName.get()}-${variant.name}.zip")
// Force instantiation of old value or else this will cause infinite recursion
destinationDirectory.set(destinationDirectory.dir(variant.name).get())

// Make the zip byte-for-byte reproducible (note that the APK is still not reproducible)
isPreserveFileTimestamps = false
isReproducibleFileOrder = true

dependsOn.add(variant.assembleProvider)

from(moduleProp.map { it.outputs })
from(variant.outputs.map { it.outputFile })
from(variantApkFiles)

val moduleDir = File(projectDir, "module")

Expand All @@ -258,8 +266,8 @@ android.applicationVariants.all {
inputs.property("projectUrl", projectUrl)
inputs.property("rootProject.name", rootProject.name)
inputs.property("variant.name", variant.name)
inputs.property("variant.versionCode", variant.versionCode)
inputs.property("variant.versionName", variant.versionName)
inputs.property("variantVersionCode", variantVersionCode)
inputs.property("variantVersionName", variantVersionName)

val moduleDir = File(projectDir, "module")
val updatesDir = File(moduleDir, "updates")
Expand All @@ -274,9 +282,9 @@ android.applicationVariants.all {
}

val root = JSONObject()
root.put("version", variant.versionName)
root.put("versionCode", variant.versionCode)
root.put("zipUrl", "${projectUrl}/releases/download/${gitVersionTriple.first}/${rootProject.name}-${variant.versionName}-release.zip")
root.put("version", variantVersionName.get())
root.put("versionCode", variantVersionCode.get())
root.put("zipUrl", "${projectUrl}/releases/download/${gitVersionTriple.first}/${rootProject.name}-${variantVersionName.get()}-release.zip")
root.put("changelog", "${projectUrl}/raw/${gitVersionTriple.first}/app/module/updates/${variant.name}/changelog.txt")

jsonFile.writer().use {
Expand Down
6 changes: 0 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
android-gradle-plugin = "8.13.0"
jgit = "7.4.0.202509020913-r"
json = "20250517"
android-gradle-plugin = "9.0.0"
jgit = "7.5.0.202512021534-r"
json = "20251224"

[libraries]
# Build script
Expand Down
Loading