diff --git a/.github/workflows/revancedbuild.yml b/.github/workflows/revancedbuild.yml index 2a60d519..8c081e9c 100644 --- a/.github/workflows/revancedbuild.yml +++ b/.github/workflows/revancedbuild.yml @@ -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 diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index 5a11f5ce..bca62458 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -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); } diff --git a/brut.j.util/src/main/java/brut/util/AaptManager.java b/brut.j.util/src/main/java/brut/util/AaptManager.java index b4ef17d8..b08656cb 100644 --- a/brut.j.util/src/main/java/brut/util/AaptManager.java +++ b/brut.j.util/src/main/java/brut/util/AaptManager.java @@ -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); + } } diff --git a/brut.j.util/src/main/java/brut/util/AaptProvider.java b/brut.j.util/src/main/java/brut/util/AaptProvider.java new file mode 100644 index 00000000..8e876ff1 --- /dev/null +++ b/brut.j.util/src/main/java/brut/util/AaptProvider.java @@ -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")); + }; +} diff --git a/brut.j.util/src/main/java/brut/util/Jar.java b/brut.j.util/src/main/java/brut/util/Jar.java index 16146093..f72f4316 100644 --- a/brut.j.util/src/main/java/brut/util/Jar.java +++ b/brut.j.util/src/main/java/brut/util/Jar.java @@ -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();