mirror of
https://github.com/revanced/Apktool.git
synced 2024-08-07 06:21:56 +02:00
fix: redo aapt provider implementation
This commit is contained in:
parent
08822dcb98
commit
37470c018d
2
.github/workflows/revancedbuild.yml
vendored
2
.github/workflows/revancedbuild.yml
vendored
@ -56,7 +56,7 @@ jobs:
|
||||
cache: gradle
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x gradlew
|
||||
- name: Build with Gradle
|
||||
- name: Publish with Gradle
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: ./gradlew publish
|
||||
|
@ -45,6 +45,18 @@ import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
final public class AndrolibResources {
|
||||
// The aapt provider. Default is AaptManager for Mac, Linux & Windows.
|
||||
// May be overridden.
|
||||
private static AaptProvider AAPT_PROVIDER = new AaptManager();
|
||||
|
||||
public static AaptProvider getAaptProvider() {
|
||||
return AAPT_PROVIDER;
|
||||
}
|
||||
|
||||
public static void setAaptProvider(AaptProvider aaptProvider) {
|
||||
AAPT_PROVIDER = aaptProvider;
|
||||
}
|
||||
|
||||
public ResTable getResTable(ExtFile apkFile) throws AndrolibException {
|
||||
return getResTable(apkFile, true);
|
||||
}
|
||||
@ -1014,9 +1026,9 @@ final public class AndrolibResources {
|
||||
private File getAaptBinaryFile() throws AndrolibException {
|
||||
try {
|
||||
if (getAaptVersion() == 2) {
|
||||
return AaptManager.getAapt2();
|
||||
return getAaptProvider().getAapt2();
|
||||
}
|
||||
return AaptManager.getAapt1();
|
||||
return getAaptProvider().getAapt1();
|
||||
} catch (BrutException ex) {
|
||||
throw new AndrolibException(ex);
|
||||
}
|
||||
|
@ -17,25 +17,18 @@
|
||||
package brut.util;
|
||||
|
||||
import brut.common.BrutException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AaptManager {
|
||||
|
||||
public static File getAapt2() throws BrutException {
|
||||
return getAapt(2);
|
||||
}
|
||||
|
||||
public static File getAapt1() throws BrutException {
|
||||
return getAapt(1);
|
||||
}
|
||||
public class AaptManager implements AaptProvider {
|
||||
|
||||
private static File getAapt(Integer version) throws BrutException {
|
||||
File aaptBinary;
|
||||
String aaptVersion = getAaptBinaryName(version);
|
||||
|
||||
if (! OSDetection.is64Bit() && OSDetection.isMacOSX()) {
|
||||
if (!OSDetection.is64Bit() && OSDetection.isMacOSX()) {
|
||||
throw new BrutException("32 bit OS detected. No 32 bit binaries available.");
|
||||
}
|
||||
|
||||
@ -64,7 +57,7 @@ public class AaptManager {
|
||||
}
|
||||
|
||||
public static String getAaptExecutionCommand(String aaptPath, File aapt) throws BrutException {
|
||||
if (! aaptPath.isEmpty()) {
|
||||
if (!aaptPath.isEmpty()) {
|
||||
File aaptFile = new File(aaptPath);
|
||||
if (aaptFile.canRead() && aaptFile.exists()) {
|
||||
aaptFile.setExecutable(true);
|
||||
@ -115,4 +108,14 @@ public class AaptManager {
|
||||
|
||||
return getAppVersionFromString(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getAapt2() throws BrutException {
|
||||
return getAapt(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getAapt1() throws BrutException {
|
||||
return getAapt(1);
|
||||
}
|
||||
}
|
||||
|
12
brut.j.util/src/main/java/brut/util/AaptProvider.java
Normal file
12
brut.j.util/src/main/java/brut/util/AaptProvider.java
Normal file
@ -0,0 +1,12 @@
|
||||
package brut.util;
|
||||
|
||||
import brut.common.BrutException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface AaptProvider {
|
||||
File getAapt2() throws BrutException;
|
||||
default File getAapt1() throws BrutException {
|
||||
throw new BrutException(new UnsupportedOperationException("Aapt1 is not supported on this device"));
|
||||
};
|
||||
}
|
@ -20,6 +20,7 @@ import brut.common.BrutException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@ -51,7 +52,7 @@ public abstract class Jar {
|
||||
File fileOut = File.createTempFile(tmpPrefix, suffix + ".tmp");
|
||||
fileOut.deleteOnExit();
|
||||
|
||||
OutputStream out = new FileOutputStream(fileOut);
|
||||
OutputStream out = Files.newOutputStream(fileOut.toPath());
|
||||
IOUtils.copy(in, out);
|
||||
in.close();
|
||||
out.close();
|
||||
|
Loading…
Reference in New Issue
Block a user