1+ /*
2+ * Copyright 2026 Morphe.
3+ * https://github.com/MorpheApp/morphe-cli
4+ *
5+ * Original hard forked code:
6+ * https://github.com/revanced/revanced-cli
7+ */
8+
19package app.morphe.cli.command
210
311import app.morphe.cli.command.model.FailedPatch
@@ -26,6 +34,7 @@ import kotlinx.coroutines.runBlocking
2634import kotlinx.serialization.ExperimentalSerializationApi
2735import kotlinx.serialization.json.Json
2836import kotlinx.serialization.json.encodeToStream
37+ import org.jetbrains.annotations.VisibleForTesting
2938import picocli.CommandLine
3039import picocli.CommandLine.ArgGroup
3140import picocli.CommandLine.Help.Visibility.ALWAYS
@@ -38,6 +47,7 @@ import java.util.concurrent.Callable
3847import java.util.logging.Logger
3948
4049@OptIn(ExperimentalSerializationApi ::class )
50+ @VisibleForTesting
4151@CommandLine.Command (
4252 name = " patch" ,
4353 description = [" Patch an APK file." ],
@@ -249,7 +259,7 @@ internal object PatchCommand : Callable<Int> {
249259
250260 @CommandLine.Option (
251261 names = [" --custom-aapt2-binary" ],
252- description = [" Path to a custom AAPT binary to compile resources with." ],
262+ description = [" Path to a custom AAPT binary to compile resources with. Only valid when --use-arsclib is not specified. " ],
253263 )
254264 @Suppress(" unused" )
255265 private fun setAaptBinaryPath (aaptBinaryPath : File ) {
@@ -262,6 +272,13 @@ internal object PatchCommand : Callable<Int> {
262272 this .aaptBinaryPath = aaptBinaryPath
263273 }
264274
275+ @CommandLine.Option (
276+ names = [" --force-apktool" ],
277+ description = [" Use apktool instead of arsclib to compile resources. Implied if --custom-aapt2-binary is specified." ],
278+ showDefaultValue = ALWAYS ,
279+ )
280+ private var forceApktool: Boolean = false
281+
265282 @CommandLine.Option (
266283 names = [" --unsigned" ],
267284 description = [" Disable signing of the final apk." ],
@@ -436,11 +453,12 @@ internal object PatchCommand : Callable<Int> {
436453 inputApk,
437454 patcherTemporaryFilesPath,
438455 aaptBinaryPath?.path,
439- patcherTemporaryFilesPath.absolutePath
456+ patcherTemporaryFilesPath.absolutePath,
457+ if (aaptBinaryPath != null ) { false } else { ! forceApktool },
440458 ),
441459 ).use { patcher ->
442460 val packageName = patcher.context.packageMetadata.packageName
443- val packageVersion = patcher.context.packageMetadata.packageVersion
461+ val packageVersion = patcher.context.packageMetadata.versionName
444462
445463 patchingResult.packageName = packageName
446464 patchingResult.packageVersion = packageVersion
0 commit comments