Create file containing the do-not-compress extensions and pass it to aapt.

This commit is contained in:
Peter Retzlaff 2019-10-06 12:59:54 +02:00 committed by Connor Tumbleson
parent 11ea666c13
commit 5d488e5f22

View File

@ -317,6 +317,29 @@ final public class AndrolibResources {
return Integer.toString(target);
}
private File createDoNotCompressExtensionsFile(ApkOptions apkOptions) throws AndrolibException {
if (apkOptions.doNotCompress == null || apkOptions.doNotCompress.isEmpty()) {
return null;
}
File doNotCompressFile;
try {
doNotCompressFile = File.createTempFile("APKTOOL", null);
doNotCompressFile.deleteOnExit();
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(doNotCompressFile));
for (String extension : apkOptions.doNotCompress) {
fileWriter.write(extension);
fileWriter.newLine();
}
fileWriter.close();
return doNotCompressFile;
} catch (IOException ex) {
throw new AndrolibException(ex);
}
}
private void aapt2Package(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include,
List<String> cmd)
throws AndrolibException {
@ -426,10 +449,9 @@ final public class AndrolibResources {
}
if (apkOptions.doNotCompress != null) {
for (String file : apkOptions.doNotCompress) {
cmd.add("-0");
cmd.add(file);
}
String extensionsFilePath = createDoNotCompressExtensionsFile(apkOptions).getAbsolutePath();
cmd.add("-e");
cmd.add(extensionsFilePath);
}
if (!apkOptions.resourcesAreCompressed) {
@ -542,11 +564,11 @@ final public class AndrolibResources {
}
if (apkOptions.doNotCompress != null) {
for (String file : apkOptions.doNotCompress) {
cmd.add("-0");
cmd.add(file);
}
String extensionsFilePath = createDoNotCompressExtensionsFile(apkOptions).getAbsolutePath();
cmd.add("-e");
cmd.add(extensionsFilePath);
}
if (!apkOptions.resourcesAreCompressed) {
cmd.add("-0");
cmd.add("arsc");