Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
  • Loading branch information
chenxiaolong committed Oct 4, 2023
1 parent 709eaea commit d56bbd9
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 406 deletions.
34 changes: 18 additions & 16 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ val gitVersionName = getVersionName(git, gitVersionTriple)
val projectUrl = "https://github.com/chenxiaolong/BCR"
val releaseMetadataBranch = "master"

val extraDir = File(buildDir, "extra")
val archiveDir = File(extraDir, "archive")
val extraDir = layout.buildDirectory.map { it.dir("extra") }
val archiveDir = extraDir.map { it.dir("archive") }

android {
namespace = "com.chiller3.bcr"
Expand Down Expand Up @@ -212,22 +212,20 @@ dependencies {
implementation(libs.material)
implementation(libs.kudzu)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.espresso)
}

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

val outputFile = File(archiveDir, "archive.tar")
val outputFile = archiveDir.map { it.file("archive.tar") }
outputs.file(outputFile)

doLast {
val format = "tar_for_task_$name"

ArchiveCommand.registerFormat(format, TarFormat())
try {
outputFile.outputStream().use {
outputFile.get().asFile.outputStream().use {
git.archive()
.setTree(git.repository.resolve(gitVersionTriple.third.name))
.setFormat(format)
Expand All @@ -243,7 +241,7 @@ val archive = tasks.register("archive") {
android.applicationVariants.all {
val variant = this
val capitalized = variant.name.replaceFirstChar { it.uppercase() }
val variantDir = File(extraDir, variant.name)
val variantDir = extraDir.map { it.dir(variant.name) }

variant.preBuildProvider.configure {
dependsOn(archive)
Expand All @@ -252,18 +250,19 @@ android.applicationVariants.all {
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)

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

doLast {
val props = LinkedHashMap<String, String>()
props["id"] = variant.applicationId
props["name"] = "BCR"
props["name"] = rootProject.name
props["version"] = "v${variant.versionName}"
props["versionCode"] = variant.versionCode.toString()
props["author"] = "chenxiaolong"
Expand All @@ -273,18 +272,19 @@ android.applicationVariants.all {
props["updateJson"] = "${projectUrl}/raw/${releaseMetadataBranch}/app/magisk/updates/${variant.name}/info.json"
}

outputFile.writeText(props.map { "${it.key}=${it.value}" }.joinToString("\n"))
outputFile.get().asFile.writeText(
props.map { "${it.key}=${it.value}" }.joinToString("\n"))
}
}

val permissionsXml = tasks.register("permissionsXml${capitalized}") {
inputs.property("variant.applicationId", variant.applicationId)

val outputFile = File(variantDir, "privapp-permissions-${variant.applicationId}.xml")
val outputFile = variantDir.map { it.file("privapp-permissions-${variant.applicationId}.xml") }
outputs.file(outputFile)

doLast {
outputFile.writeText("""
outputFile.get().asFile.writeText("""
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<privapp-permissions package="${variant.applicationId}">
Expand All @@ -302,7 +302,7 @@ android.applicationVariants.all {
// To get output apk filename
dependsOn.add(variant.assembleProvider)

val outputFile = File(variantDir, "51-${variant.applicationId}.sh")
val outputFile = variantDir.map { it.file("51-${variant.applicationId}.sh") }
outputs.file(outputFile)

val backupFiles = variant.outputs.map {
Expand All @@ -312,7 +312,7 @@ android.applicationVariants.all {
)

doLast {
outputFile.writeText("""
outputFile.get().asFile.writeText("""
#!/sbin/sh
# ADDOND_VERSION=2
Expand All @@ -332,11 +332,12 @@ android.applicationVariants.all {
}

tasks.register<Zip>("zip${capitalized}") {
inputs.property("rootProject.name", rootProject.name)
inputs.property("variant.applicationId", variant.applicationId)
inputs.property("variant.name", variant.name)
inputs.property("variant.versionName", variant.versionName)

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

Expand Down Expand Up @@ -377,6 +378,7 @@ android.applicationVariants.all {
tasks.register("updateJson${capitalized}") {
inputs.property("gitVersionTriple.first", gitVersionTriple.first)
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)
Expand All @@ -396,7 +398,7 @@ android.applicationVariants.all {
val root = JSONObject()
root.put("version", variant.versionName)
root.put("versionCode", variant.versionCode)
root.put("zipUrl", "${projectUrl}/releases/download/${gitVersionTriple.first}/BCR-${variant.versionName}-release.zip")
root.put("zipUrl", "${projectUrl}/releases/download/${gitVersionTriple.first}/${rootProject.name}-${variant.versionName}-release.zip")
root.put("changelog", "${projectUrl}/raw/${gitVersionTriple.first}/app/magisk/updates/${variant.name}/changelog.txt")

jsonFile.writer().use {
Expand Down
17 changes: 5 additions & 12 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
[versions]
androidx-activity = "1.7.2"
android-gradle-plugin = "8.1.2"
androidx-activity = "1.8.0"
androidx-appcompat = "1.6.1"
androidx-core = "1.10.1"
androidx-core = "1.12.0"
androidx-documentfile = "1.0.1"
androidx-fragment = "1.6.1"
androidx-preference = "1.2.1"
androidx-preference-ktx = "1.2.0"
androidx-test-espresso = "3.5.1"
androidx-test-junit = "1.1.5"
androidGradlePlugin = "8.1.1"
jgit = "6.6.0.202305301015-r"
json = "20230618"
kotlin = "1.9.10"
Expand All @@ -23,14 +20,10 @@ androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref =
androidx-documentfile = { group = "androidx.documentfile", name = "documentfile", version.ref = "androidx-documentfile" }
androidx-fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", version.ref = "androidx-fragment" }
androidx-preference = { group = "androidx.preference", name = "preference", version.ref = "androidx-preference" }
androidx-preference-ktx = { group = "androidx.preference", name = "preference-ktx", version.ref = "androidx-preference-ktx" }
androidx-preference-ktx = { group = "androidx.preference", name = "preference-ktx", version.ref = "androidx-preference" }
kudzu = { group = "io.github.copper-leaf", name = "kudzu-core", version.ref = "kudzu" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }

# Android test
androidx-test-espresso = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-test-espresso" }
androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-junit" }

# Test
junit = { group = "junit", name = "junit", version.ref = "test-junit" }

Expand All @@ -40,6 +33,6 @@ jgit-archive = { group = "org.eclipse.jgit", name = "org.eclipse.jgit.archive",
json = { group = "org.json", name = "json", version.ref = "json" }

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
78 changes: 78 additions & 0 deletions gradle/update_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3

import io
import os
import subprocess
import sys
import tempfile
import xml.etree.ElementTree as ET


def add_source_exclusions(path):
tree = ET.parse(path)
root = tree.getroot()

ns = 'https://schema.gradle.org/dependency-verification'
ET.register_namespace('', ns)
configuration = root.find(f'{{{ns}}}configuration')
trusted_artifacts = ET.SubElement(
configuration, f'{{{ns}}}trusted-artifacts')

for regex in [
r'.*-javadoc[.]jar',
r'.*-sources[.]jar',
r'.*-src[.]zip',
]:
ET.SubElement(trusted_artifacts, f'{{{ns}}}trust', attrib={
'file': regex,
'regex': 'true',
})

# Match gradle's formatting exactly.
ET.indent(tree, ' ')
root.tail = '\n'

with io.BytesIO() as f:
# etree's xml_declaration=True uses single quotes in the header.
f.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
tree.write(f)
serialized = f.getvalue().replace(b' />', b'/>')

with open(path, 'wb') as f:
f.write(serialized)


def main():
root_dir = os.path.join(sys.path[0], '..')
xml_file = os.path.join(sys.path[0], 'verification-metadata.xml')

try:
os.remove(xml_file)
except FileNotFoundError:
pass

# Gradle will sometimes fail to add verification entries for artifacts that
# are already cached.
with tempfile.TemporaryDirectory() as temp_dir:
env = os.environ | {'GRADLE_USER_HOME': temp_dir}

subprocess.check_call(
[
'./gradlew' + ('.bat' if os.name == 'nt' else ''),
'--write-verification-metadata', 'sha512',
'--no-daemon',
'build',
'zipDebug',
# Requires signing.
'-x', 'assembleRelease',
],
env=env,
cwd=root_dir,
)

# Add exclusions to allow Android Studio to download sources.
add_source_exclusions(xml_file)


if __name__ == '__main__':
main()
Loading

0 comments on commit d56bbd9

Please sign in to comment.