From 3c7787714deab524ce253a587c050758613dcd87 Mon Sep 17 00:00:00 2001 From: Kofua <1638183271zjn@gmail.com> Date: Sat, 6 Apr 2024 16:19:49 +0800 Subject: [PATCH] feat: minimize apk size & customize output apk signing levels --- build.gradle.kts | 9 +++++++++ gradle/libs.versions.toml | 6 +++--- .../app/revanced/cli/command/PatchCommand.kt | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f2f0ed22..14d43f79 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,6 +26,14 @@ repositories { password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") } } + maven { + // A repository must be speficied for some reason. "registry" is a dummy. + url = uri("https://maven.pkg.github.com/zjns/registry") + credentials { + username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") + password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") + } + } } dependencies { @@ -64,6 +72,7 @@ tasks { exclude(dependency("org.jetbrains.kotlin:.*")) exclude(dependency("org.bouncycastle:.*")) exclude(dependency("app.revanced:.*")) + exclude(dependency("kofua.app.revanced:.*")) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c3b1bd41..dce4b5b0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,9 +10,9 @@ revanced-library = "2.3.0" kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" } picocli = { module = "info.picocli:picocli", version.ref = "picocli" } -revanced-patcher = { module = "app.revanced:revanced-patcher", version.ref = "revanced-patcher" } -revanced-library = { module = "app.revanced:revanced-library", version.ref = "revanced-library" } +revanced-patcher = { module = "kofua.app.revanced:revanced-patcher", version.ref = "revanced-patcher" } +revanced-library = { module = "kofua.app.revanced:revanced-library", version.ref = "revanced-library" } [plugins] shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } -kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } \ No newline at end of file +kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index 05238c20..74a11adb 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -12,6 +12,7 @@ import app.revanced.patcher.PatcherConfig import kotlinx.coroutines.runBlocking import picocli.CommandLine import picocli.CommandLine.Help.Visibility.ALWAYS +import picocli.CommandLine.ITypeConverter import picocli.CommandLine.Model.CommandSpec import picocli.CommandLine.Spec import java.io.File @@ -173,6 +174,14 @@ internal object PatchCommand : Runnable { ) private var warn: Boolean = false + @CommandLine.Option( + names = ["--signing-levels"], + description = ["Output apk signing levels, eg. \"1,2,3\", empty as default."], + converter = [SignLevelsConverter::class], + arity = "0..1", + ) + private var signLevels = listOf() + @CommandLine.Parameters( description = ["APK file to be patched."], arity = "1..1", @@ -279,6 +288,7 @@ internal object PatchCommand : Runnable { aaptBinaryPath?.path, patcherTemporaryFilesPath.absolutePath, true, + shortenResourcePaths = true, ), ).use { patcher -> val filteredPatches = @@ -328,6 +338,7 @@ internal object PatchCommand : Runnable { keyStoreEntryAlias, keyStoreEntryPassword, ), + signLevels, ) } else { patchedApkFile.copyTo(outputFilePath, overwrite = true) @@ -418,4 +429,10 @@ internal object PatchCommand : Runnable { } logger.info(result) } + + class SignLevelsConverter : ITypeConverter> { + override fun convert(value: String): List { + return value.split(",").map { it.toInt() } + } + } }