From b0fd764df47af7c1056038ba694b75e2fdfd98ea Mon Sep 17 00:00:00 2001 From: Seb Patane Date: Tue, 24 Jul 2018 13:54:37 +1000 Subject: [PATCH] feat: Expose the aapt --no-crunch option - Add a --no-crunch/-nc flag to apktool which gets passed through to aapt - This allows apktool to make a byte-for-byte copy of resource files - refs: #1232 --- .../apktool-cli/src/main/java/brut/apktool/Main.java | 10 ++++++++++ .../src/main/java/brut/androlib/ApkOptions.java | 1 + .../main/java/brut/androlib/res/AndrolibResources.java | 7 +++++++ 3 files changed, 18 insertions(+) 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 69c9c45c..abaee387 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 @@ -218,6 +218,9 @@ public class Main { if (cli.hasOption("p") || cli.hasOption("frame-path")) { apkOptions.frameworkFolderLocation = cli.getOptionValue("p"); } + if (cli.hasOption("nc") || cli.hasOption("no-crunch")) { + apkOptions.noCrunch = true; + } // Temporary flag to enable the use of aapt2. This will tranform in time to a use-aapt1 flag, which will be // legacy and eventually removed. @@ -397,6 +400,11 @@ public class Main { .desc("Copies original AndroidManifest.xml and META-INF. See project page for more info.") .build(); + Option noCrunchOption = Option.builder("nc") + .longOpt("no-crunch") + .desc("Disable crunching of resource files during the build step.") + .build(); + Option tagOption = Option.builder("t") .longOpt("tag") .desc("Tag frameworks using .") @@ -439,6 +447,7 @@ public class Main { BuildOptions.addOption(aaptOption); BuildOptions.addOption(originalOption); BuildOptions.addOption(aapt2Option); + BuildOptions.addOption(noCrunchOption); } // add global options @@ -492,6 +501,7 @@ public class Main { allOptions.addOption(verboseOption); allOptions.addOption(quietOption); allOptions.addOption(aapt2Option); + allOptions.addOption(noCrunchOption); } private static String verbosityHelp() { diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java index 0a81ef07..b1ddb4a2 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java @@ -28,6 +28,7 @@ public class ApkOptions { public boolean isFramework = false; public boolean resourcesAreCompressed = false; public boolean useAapt2 = false; + public boolean noCrunch = false; public Collection doNotCompress; public String frameworkFolderLocation = null; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index b8ceeec9..b4c3d44a 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -350,6 +350,10 @@ final public class AndrolibResources { cmd.add("-v"); } + if (apkOptions.noCrunch) { + cmd.add("--no-crunch"); + } + try { OS.exec(cmd.toArray(new String[0])); LOGGER.fine("aapt2 compile command ran: "); @@ -485,6 +489,9 @@ final public class AndrolibResources { if (apkOptions.debugMode) { // inject debuggable="true" into manifest cmd.add("--debug-mode"); } + if (apkOptions.noCrunch) { + cmd.add("--no-crunch"); + } // force package id so that some frameworks build with correct id // disable if user adds own aapt (can't know if they have this feature) if (mPackageId != null && ! customAapt && ! mSharedLibrary) {