From e033351a852cf40404e65843f6083e0afd801292 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Wed, 4 Oct 2023 20:27:25 -0400 Subject: [PATCH] feat: make aapt2 default --- .../src/main/java/brut/apktool/Main.java | 20 +++++++++++++------ .../src/main/java/brut/androlib/Config.java | 2 +- .../aapt1/AndroidOreoNotSparseTest.java | 1 + .../androlib/aapt1/AndroidOreoSparseTest.java | 1 + .../androlib/aapt1/BuildAndDecodeJarTest.java | 9 ++++----- .../androlib/aapt1/BuildAndDecodeTest.java | 9 ++++----- .../androlib/aapt1/DebugTagRetainedTest.java | 1 + .../aapt1/DefaultBaksmaliVariableTest.java | 9 ++++----- .../aapt1/EmptyResourcesArscTest.java | 1 + .../{decode => aapt1}/ExternalEntityTest.java | 11 +++++----- .../aapt1/LargeIntsInManifestTest.java | 9 ++++----- .../androlib/aapt1/ProviderAttributeTest.java | 9 ++++----- .../androlib/aapt1/SharedLibraryTest.java | 1 + .../aapt1/UnknownCompressionTest.java | 1 + 14 files changed, 46 insertions(+), 38 deletions(-) rename brut.apktool/apktool-lib/src/test/java/brut/androlib/{decode => aapt1}/ExternalEntityTest.java (93%) diff --git a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java index 403801dc9b..e10ed96147 100644 --- a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java +++ b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java @@ -267,11 +267,13 @@ private static void cmdBuild(CommandLine cli, Config config) { if (cli.hasOption("nc") || cli.hasOption("no-crunch")) { config.noCrunch = true; } + if (cli.hasOption("use-aapt1")) { + config.useAapt2 = false; + } - // Temporary flag to enable the use of aapt2. This will transform in time to a use-aapt1 flag, which will be - // legacy and eventually removed. - if (cli.hasOption("use-aapt2")) { - config.useAapt2 = true; + if (cli.hasOption("use-aapt1") && cli.hasOption("use-aapt2")) { + System.err.println("You can only use one of --use-aapt1 or --use-aapt2."); + System.exit(1); } File outFile; @@ -449,9 +451,14 @@ private static void _options() { .desc("Load aapt from specified location.") .build(); + Option aapt1Option = Option.builder() + .longOpt("use-aapt1") + .desc("Use aapt binary instead of aapt2 during the build step.") + .build(); + Option aapt2Option = Option.builder() .longOpt("use-aapt2") - .desc("Use aapt2 binary instead of aapt1 during the build step.") + .desc("Use aapt2 binary instead of aapt during the build step.") .build(); Option originalOption = Option.builder("c") @@ -509,7 +516,7 @@ private static void _options() { buildOptions.addOption(netSecConfOption); buildOptions.addOption(aaptOption); buildOptions.addOption(originalOption); - buildOptions.addOption(aapt2Option); + buildOptions.addOption(aapt1Option); buildOptions.addOption(noCrunchOption); } @@ -568,6 +575,7 @@ private static void _options() { allOptions.addOption(originalOption); allOptions.addOption(verboseOption); allOptions.addOption(quietOption); + allOptions.addOption(aapt1Option); allOptions.addOption(aapt2Option); allOptions.addOption(noCrunchOption); allOptions.addOption(onlyMainClassesOption); diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Config.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Config.java index 7fa561b045..2ffba37dff 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Config.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Config.java @@ -51,7 +51,7 @@ public class Config { public boolean verbose = false; public boolean copyOriginalFiles = false; public boolean updateFiles = false; - public boolean useAapt2 = false; + public boolean useAapt2 = true; public boolean noCrunch = false; public int forceApi = 0; diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoNotSparseTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoNotSparseTest.java index fbbc5b2d84..e13deccdd4 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoNotSparseTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoNotSparseTest.java @@ -47,6 +47,7 @@ public static void beforeClass() throws Exception { LOGGER.info("Building not_sparse.apk..."); Config config = Config.getDefaultConfig(); + config.useAapt2 = false; new ApkBuilder(config, sTestNewDir).build(testApk); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoSparseTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoSparseTest.java index 0acfe7aa26..9461916780 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoSparseTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/AndroidOreoSparseTest.java @@ -47,6 +47,7 @@ public static void beforeClass() throws Exception { LOGGER.info("Building sparse.apk..."); Config config = Config.getDefaultConfig(); + config.useAapt2 = false; new ApkBuilder(config, sTestNewDir).build(testApk); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeJarTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeJarTest.java index ef8588658b..2de35510e6 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeJarTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeJarTest.java @@ -16,10 +16,7 @@ */ package brut.androlib.aapt1; -import brut.androlib.ApkBuilder; -import brut.androlib.ApkDecoder; -import brut.androlib.BaseTest; -import brut.androlib.TestUtils; +import brut.androlib.*; import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; @@ -44,7 +41,9 @@ public static void beforeClass() throws Exception { LOGGER.info("Building testjar.jar..."); File testJar = new File(sTmpDir, "testjar.jar"); - new ApkBuilder(sTestOrigDir).build(testJar); + Config config = Config.getDefaultConfig(); + config.useAapt2 = false; + new ApkBuilder(config, sTestOrigDir).build(testJar); LOGGER.info("Decoding testjar.jar..."); ApkDecoder apkDecoder = new ApkDecoder(testJar); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java index 99117e21c7..316b9644a0 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/BuildAndDecodeTest.java @@ -16,10 +16,7 @@ */ package brut.androlib.aapt1; -import brut.androlib.ApkBuilder; -import brut.androlib.ApkDecoder; -import brut.androlib.BaseTest; -import brut.androlib.TestUtils; +import brut.androlib.*; import brut.androlib.apk.ApkInfo; import brut.common.BrutException; import brut.directory.ExtFile; @@ -52,7 +49,9 @@ public static void beforeClass() throws Exception { LOGGER.info("Building testapp.apk..."); File testApk = new File(sTmpDir, "testapp.apk"); - new ApkBuilder(sTestOrigDir).build(testApk); + Config config = Config.getDefaultConfig(); + config.useAapt2 = false; + new ApkBuilder(config, sTestOrigDir).build(testApk); LOGGER.info("Decoding testapp.apk..."); ApkDecoder apkDecoder = new ApkDecoder(testApk); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DebugTagRetainedTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DebugTagRetainedTest.java index 1ae1d68c01..9c63aa2904 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DebugTagRetainedTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DebugTagRetainedTest.java @@ -48,6 +48,7 @@ public static void beforeClass() throws Exception { LOGGER.info("Building issue1235.apk..."); Config config = Config.getDefaultConfig(); + config.useAapt2 = false; config.debugMode = true; File testApk = new File(sTmpDir, "issue1235.apk"); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DefaultBaksmaliVariableTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DefaultBaksmaliVariableTest.java index 2173efcfd8..ccdd9b1c32 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DefaultBaksmaliVariableTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/DefaultBaksmaliVariableTest.java @@ -16,10 +16,7 @@ */ package brut.androlib.aapt1; -import brut.androlib.ApkBuilder; -import brut.androlib.ApkDecoder; -import brut.androlib.BaseTest; -import brut.androlib.TestUtils; +import brut.androlib.*; import brut.common.BrutException; import brut.directory.ExtFile; import brut.util.OS; @@ -46,7 +43,9 @@ public static void beforeClass() throws Exception { LOGGER.info("Building issue1481.jar..."); File testJar = new File(sTmpDir, "issue1481.jar"); - new ApkBuilder(sTestOrigDir).build(testJar); + Config config = Config.getDefaultConfig(); + config.useAapt2 = false; + new ApkBuilder(config, sTestOrigDir).build(testJar); LOGGER.info("Decoding issue1481.jar..."); ApkDecoder apkDecoder = new ApkDecoder(testJar); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/EmptyResourcesArscTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/EmptyResourcesArscTest.java index fc37fff9d2..240d304076 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/EmptyResourcesArscTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/EmptyResourcesArscTest.java @@ -50,6 +50,7 @@ public static void beforeClass() throws Exception { LOGGER.info("Building issue1730.apk..."); Config config = Config.getDefaultConfig(); + config.useAapt2 = false; new ApkBuilder(config, sTestNewDir).build(testApk); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/ExternalEntityTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/ExternalEntityTest.java similarity index 93% rename from brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/ExternalEntityTest.java rename to brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/ExternalEntityTest.java index 60232eca56..4c673958f8 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/ExternalEntityTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/ExternalEntityTest.java @@ -14,12 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package brut.androlib.decode; +package brut.androlib.aapt1; -import brut.androlib.ApkBuilder; -import brut.androlib.ApkDecoder; -import brut.androlib.BaseTest; -import brut.androlib.TestUtils; +import brut.androlib.*; import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; @@ -43,7 +40,9 @@ public static void beforeClass() throws Exception { LOGGER.info("Building doctype.apk..."); File testApk = new File(sTestOrigDir, "doctype.apk"); - new ApkBuilder(sTestOrigDir).build(testApk); + Config config = Config.getDefaultConfig(); + config.useAapt2 = false; + new ApkBuilder(config, sTestOrigDir).build(testApk); LOGGER.info("Decoding doctype.apk..."); ApkDecoder apkDecoder = new ApkDecoder(testApk); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/LargeIntsInManifestTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/LargeIntsInManifestTest.java index 3481dc23c9..c8e4574c53 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/LargeIntsInManifestTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/LargeIntsInManifestTest.java @@ -16,10 +16,7 @@ */ package brut.androlib.aapt1; -import brut.androlib.ApkBuilder; -import brut.androlib.ApkDecoder; -import brut.androlib.BaseTest; -import brut.androlib.TestUtils; +import brut.androlib.*; import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; @@ -54,8 +51,10 @@ public void checkIfLargeIntsAreHandledTest() throws BrutException, IOException { apkDecoder.decode(outDir); // build issue767 + Config config = Config.getDefaultConfig(); + config.useAapt2 = false; ExtFile testApk = new ExtFile(sTmpDir, apk + ".out"); - new ApkBuilder(testApk).build(null); + new ApkBuilder(config, testApk).build(null); String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk; // decode issue767 again diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/ProviderAttributeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/ProviderAttributeTest.java index abc724ddef..35a9ba9a6d 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/ProviderAttributeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/ProviderAttributeTest.java @@ -16,10 +16,7 @@ */ package brut.androlib.aapt1; -import brut.androlib.ApkBuilder; -import brut.androlib.ApkDecoder; -import brut.androlib.BaseTest; -import brut.androlib.TestUtils; +import brut.androlib.*; import brut.directory.ExtFile; import brut.common.BrutException; import brut.util.OS; @@ -62,7 +59,9 @@ public void isProviderStringReplacementWorking() throws BrutException, IOExcepti // build issue636 ExtFile testApk = new ExtFile(sTmpDir, apk + ".out"); - new ApkBuilder(testApk).build(null); + Config config = Config.getDefaultConfig(); + config.useAapt2 = false; + new ApkBuilder(config, testApk).build(null); String newApk = apk + ".out" + File.separator + "dist" + File.separator + apk; assertTrue(fileExists(newApk)); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/SharedLibraryTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/SharedLibraryTest.java index bc59d963e8..bc7b44f231 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/SharedLibraryTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/SharedLibraryTest.java @@ -81,6 +81,7 @@ public void isSharedResourceDecodingAndRebuildingWorking() throws IOException, B Config config = Config.getDefaultConfig(); config.frameworkDirectory = sTmpDir.getAbsolutePath(); config.frameworkTag = "shared"; + config.useAapt2 = false; // install library/framework new Framework(config).installFramework(new File(sTmpDir + File.separator + library)); diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/UnknownCompressionTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/UnknownCompressionTest.java index dda7c3c5ab..5e087db2fa 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/UnknownCompressionTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/aapt1/UnknownCompressionTest.java @@ -42,6 +42,7 @@ public static void beforeClass() throws Exception { String apk = "deflated_unknowns.apk"; Config config = Config.getDefaultConfig(); config.frameworkDirectory = sTmpDir.getAbsolutePath(); + config.useAapt2 = false; sTestOrigDir = new ExtFile(sTmpDir, apk);