mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-09 02:04:25 +02:00
aapt2: don't rebuild compile stage unless needed
This commit is contained in:
parent
646eb54102
commit
448d14592f
@ -459,8 +459,10 @@ public class Androlib {
|
||||
LOGGER.info("Checking whether resources has changed...");
|
||||
}
|
||||
File apkDir = new File(appDir, APK_DIRNAME);
|
||||
File resourceFile = new File(apkDir.getParent(), "resources.zip");
|
||||
|
||||
if (apkOptions.forceBuildAll || isModified(newFiles(APP_RESOURCES_FILENAMES, appDir),
|
||||
newFiles(APK_RESOURCES_FILENAMES, apkDir)) || apkOptions.isAapt2()) {
|
||||
newFiles(APK_RESOURCES_FILENAMES, apkDir)) || (apkOptions.isAapt2() && !isFile(resourceFile))) {
|
||||
LOGGER.info("Building resources...");
|
||||
|
||||
if (apkOptions.debugMode) {
|
||||
@ -469,6 +471,7 @@ public class Androlib {
|
||||
|
||||
File apkFile = File.createTempFile("APKTOOL", null);
|
||||
apkFile.delete();
|
||||
resourceFile.delete();
|
||||
|
||||
File ninePatch = new File(appDir, "9patch");
|
||||
if (!ninePatch.exists()) {
|
||||
@ -744,6 +747,10 @@ public class Androlib {
|
||||
return ! stored.exists() || BrutIO.recursiveModifiedTime(working) > BrutIO .recursiveModifiedTime(stored);
|
||||
}
|
||||
|
||||
private boolean isFile(File working) {
|
||||
return working.exists();
|
||||
}
|
||||
|
||||
private boolean isModified(File[] working, File[] stored) {
|
||||
for (int i = 0; i < stored.length; i++) {
|
||||
if (!stored[i].exists()) {
|
||||
|
@ -322,8 +322,14 @@ final public class AndrolibResources {
|
||||
throws AndrolibException {
|
||||
|
||||
List<String> compileCommand = new ArrayList<>(cmd);
|
||||
File tempResourcesZip = null;
|
||||
File resourcesZip = null;
|
||||
|
||||
if (resDir != null) {
|
||||
File buildDir = new File(resDir.getParent(), "build");
|
||||
resourcesZip = new File(buildDir, "resources.zip");
|
||||
}
|
||||
|
||||
if (resDir != null && !resourcesZip.exists()) {
|
||||
|
||||
// Compile the files into flat arsc files
|
||||
cmd.add("compile");
|
||||
@ -334,25 +340,21 @@ final public class AndrolibResources {
|
||||
// Treats error that used to be valid in aapt1 as warnings in aapt2
|
||||
cmd.add("--legacy");
|
||||
|
||||
File buildDir = new File(resDir.getParent(), "build");
|
||||
resourcesZip = new File(buildDir, "resources.zip");
|
||||
|
||||
cmd.add("-o");
|
||||
cmd.add(resourcesZip.getAbsolutePath());
|
||||
|
||||
if (apkOptions.verbose) {
|
||||
cmd.add("-v");
|
||||
}
|
||||
|
||||
try {
|
||||
tempResourcesZip = File.createTempFile("BRUT", ".zip");
|
||||
tempResourcesZip.deleteOnExit();
|
||||
|
||||
cmd.add("-o");
|
||||
cmd.add(tempResourcesZip.getAbsolutePath());
|
||||
|
||||
if (apkOptions.verbose) {
|
||||
cmd.add("-v");
|
||||
}
|
||||
|
||||
try {
|
||||
OS.exec(cmd.toArray(new String[0]));
|
||||
LOGGER.fine("aapt2 compile command ran: ");
|
||||
LOGGER.fine(cmd.toString());
|
||||
} catch (BrutException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
OS.exec(cmd.toArray(new String[0]));
|
||||
LOGGER.fine("aapt2 compile command ran: ");
|
||||
LOGGER.fine(cmd.toString());
|
||||
} catch (BrutException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
}
|
||||
@ -455,8 +457,8 @@ final public class AndrolibResources {
|
||||
cmd.add("-v");
|
||||
}
|
||||
|
||||
if (tempResourcesZip != null) {
|
||||
cmd.add(tempResourcesZip.getAbsolutePath());
|
||||
if (resourcesZip != null) {
|
||||
cmd.add(resourcesZip.getAbsolutePath());
|
||||
}
|
||||
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user