mirror of
https://github.com/revanced/Apktool.git
synced 2025-06-13 05:27:36 +02:00
aapt2: refactor loading of aapt/aapt2 binaries
- change: die out if invalid aapt path is provided
This commit is contained in:
@ -576,34 +576,16 @@ final public class AndrolibResources {
|
|||||||
public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include)
|
public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include)
|
||||||
throws AndrolibException {
|
throws AndrolibException {
|
||||||
|
|
||||||
boolean customAapt = false;
|
|
||||||
String aaptPath = apkOptions.aaptPath;
|
String aaptPath = apkOptions.aaptPath;
|
||||||
|
boolean customAapt = !aaptPath.isEmpty();
|
||||||
List<String> cmd = new ArrayList<String>();
|
List<String> cmd = new ArrayList<String>();
|
||||||
|
|
||||||
// path for aapt binary
|
try {
|
||||||
if (! aaptPath.isEmpty()) {
|
String aaptCommand = AaptManager.getAaptExecutionCommand(aaptPath, getAaptBinaryFile());
|
||||||
File aaptFile = new File(aaptPath);
|
cmd.add(aaptCommand);
|
||||||
if (aaptFile.canRead() && aaptFile.exists()) {
|
} catch (BrutException ex) {
|
||||||
aaptFile.setExecutable(true);
|
LOGGER.warning("aapt: " + ex.getMessage() + " (defaulting to $PATH binary)");
|
||||||
cmd.add(aaptFile.getPath());
|
cmd.add(AaptManager.getAaptBinaryName(getAaptVersion()));
|
||||||
customAapt = true;
|
|
||||||
|
|
||||||
LOGGER.fine(aaptFile.getPath() + " being used as aapt location.");
|
|
||||||
} else {
|
|
||||||
LOGGER.warning("aapt location could not be found. Defaulting back to default");
|
|
||||||
|
|
||||||
try {
|
|
||||||
cmd.add(getAaptBinaryFile().getAbsolutePath());
|
|
||||||
} catch (BrutException ignored) {
|
|
||||||
cmd.add("aapt");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
cmd.add(getAaptBinaryFile().getAbsolutePath());
|
|
||||||
} catch (BrutException ignored) {
|
|
||||||
cmd.add("aapt");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apkOptions.isAapt2()) {
|
if (apkOptions.isAapt2()) {
|
||||||
@ -979,7 +961,7 @@ final public class AndrolibResources {
|
|||||||
|
|
||||||
private File getAaptBinaryFile() throws AndrolibException {
|
private File getAaptBinaryFile() throws AndrolibException {
|
||||||
try {
|
try {
|
||||||
if (apkOptions.useAapt2 || apkOptions.aaptVersion == 2) {
|
if (getAaptVersion() == 2) {
|
||||||
return AaptManager.getAppt2();
|
return AaptManager.getAppt2();
|
||||||
}
|
}
|
||||||
return AaptManager.getAppt1();
|
return AaptManager.getAppt1();
|
||||||
@ -988,6 +970,10 @@ final public class AndrolibResources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getAaptVersion() {
|
||||||
|
return apkOptions.isAapt2() ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
public File getAndroidResourcesFile() throws AndrolibException {
|
public File getAndroidResourcesFile() throws AndrolibException {
|
||||||
try {
|
try {
|
||||||
return Jar.getResourceAsFile("/brut/androlib/android-framework.jar");
|
return Jar.getResourceAsFile("/brut/androlib/android-framework.jar");
|
||||||
|
@ -33,7 +33,7 @@ public class AaptManager {
|
|||||||
|
|
||||||
private static File getAppt(Integer version) throws BrutException {
|
private static File getAppt(Integer version) throws BrutException {
|
||||||
File aaptBinary;
|
File aaptBinary;
|
||||||
String aaptVersion = "aapt" + (version == 2 ? "2" : "");
|
String aaptVersion = getAaptBinaryName(version);
|
||||||
|
|
||||||
if (! OSDetection.is64Bit() && ! OSDetection.isWindows()) {
|
if (! OSDetection.is64Bit() && ! OSDetection.isWindows()) {
|
||||||
throw new BrutException("32 bit OS detected. No 32 bit binaries available.");
|
throw new BrutException("32 bit OS detected. No 32 bit binaries available.");
|
||||||
@ -60,10 +60,28 @@ public class AaptManager {
|
|||||||
throw new BrutException("Can't set aapt binary as executable");
|
throw new BrutException("Can't set aapt binary as executable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getAaptExecutionCommand(String aaptPath, File aapt) throws BrutException {
|
||||||
|
if (! aaptPath.isEmpty()) {
|
||||||
|
File aaptFile = new File(aaptPath);
|
||||||
|
if (aaptFile.canRead() && aaptFile.exists()) {
|
||||||
|
aaptFile.setExecutable(true);
|
||||||
|
return aaptFile.getPath();
|
||||||
|
} else {
|
||||||
|
throw new BrutException("binary could not be read: " + aaptFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return aapt.getAbsolutePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int getAaptVersion(String aaptLocation) throws BrutException {
|
public static int getAaptVersion(String aaptLocation) throws BrutException {
|
||||||
return getApptVersion(new File(aaptLocation));
|
return getApptVersion(new File(aaptLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getAaptBinaryName(Integer version) {
|
||||||
|
return "aapt" + (version == 2 ? "2" : "");
|
||||||
|
}
|
||||||
|
|
||||||
public static int getApptVersion(File aapt) throws BrutException {
|
public static int getApptVersion(File aapt) throws BrutException {
|
||||||
if (!aapt.isFile()) {
|
if (!aapt.isFile()) {
|
||||||
throw new BrutException("Could not identify aapt binary as executable.");
|
throw new BrutException("Could not identify aapt binary as executable.");
|
||||||
|
Reference in New Issue
Block a user