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