feat: support aapt optimize
This commit is contained in:
parent
fc4a59fb33
commit
6903ce3927
|
@ -23,6 +23,9 @@ import brut.util.AaptManager;
|
|||
import brut.util.OS;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -245,6 +248,35 @@ public class AaptInvoker {
|
|||
} catch (BrutException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
|
||||
if (mConfig.shortenResourcePaths) {
|
||||
Path inputFilePath = new File(apkFile.getParent(), apkFile.getName() + ".tmp").toPath();
|
||||
Path apkFilePath = apkFile.toPath();
|
||||
try {
|
||||
Files.copy(apkFilePath, inputFilePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.delete(apkFilePath);
|
||||
} catch (IOException e) {
|
||||
throw new AndrolibException(e);
|
||||
}
|
||||
|
||||
cmd = new ArrayList<>(compileCommand);
|
||||
cmd.add("optimize");
|
||||
|
||||
cmd.add("-o");
|
||||
cmd.add(apkFilePath.toString());
|
||||
|
||||
cmd.add("--shorten-resource-paths");
|
||||
|
||||
cmd.add(inputFilePath.toString());
|
||||
|
||||
try {
|
||||
OS.exec(cmd.toArray(new String[0]));
|
||||
LOGGER.fine("aapt2 optimize command ran: ");
|
||||
LOGGER.fine(cmd.toString());
|
||||
} catch (BrutException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeAapt1(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include,
|
||||
|
|
|
@ -53,6 +53,7 @@ public class Config {
|
|||
public boolean updateFiles = false;
|
||||
public boolean useAapt2 = true;
|
||||
public boolean noCrunch = false;
|
||||
public boolean shortenResourcePaths = false;
|
||||
|
||||
// Decode options
|
||||
public short decodeSources = DECODE_SOURCES_SMALI;
|
||||
|
|
Loading…
Reference in New Issue