Skip to content

Commit

Permalink
feat: minimize apk size & customize output apk signing levels
Browse files Browse the repository at this point in the history
  • Loading branch information
zjns committed Apr 24, 2024
1 parent 1496e82 commit 3c77877
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -64,6 +72,7 @@ tasks {
exclude(dependency("org.jetbrains.kotlin:.*"))
exclude(dependency("org.bouncycastle:.*"))
exclude(dependency("app.revanced:.*"))
exclude(dependency("kofua.app.revanced:.*"))
}
}

Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
17 changes: 17 additions & 0 deletions src/main/kotlin/app/revanced/cli/command/PatchCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Int>()

@CommandLine.Parameters(
description = ["APK file to be patched."],
arity = "1..1",
Expand Down Expand Up @@ -279,6 +288,7 @@ internal object PatchCommand : Runnable {
aaptBinaryPath?.path,
patcherTemporaryFilesPath.absolutePath,
true,
shortenResourcePaths = true,
),
).use { patcher ->
val filteredPatches =
Expand Down Expand Up @@ -328,6 +338,7 @@ internal object PatchCommand : Runnable {
keyStoreEntryAlias,
keyStoreEntryPassword,
),
signLevels,
)
} else {
patchedApkFile.copyTo(outputFilePath, overwrite = true)
Expand Down Expand Up @@ -418,4 +429,10 @@ internal object PatchCommand : Runnable {
}
logger.info(result)
}

class SignLevelsConverter : ITypeConverter<List<Int>> {
override fun convert(value: String): List<Int> {
return value.split(",").map { it.toInt() }
}
}
}

0 comments on commit 3c77877

Please sign in to comment.