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
This commit is contained in:
Seb Patane 2018-07-24 13:54:37 +10:00
parent 6231edfcfd
commit b0fd764df4
3 changed files with 18 additions and 0 deletions

View File

@ -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 <tag>.")
@ -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() {

View File

@ -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<String> doNotCompress;
public String frameworkFolderLocation = null;

View File

@ -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) {