Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Make MergeAssets respect aapt no-compress extensions for resources
Browse files Browse the repository at this point in the history
Summary:
Previously, it was respecting aapt's decision on whether to compress any
given resource.  However, aapt2 currently compresses everything, leading
to compressed sounds that cannot be played.

For now, use the aapt extensions list as a double-check.

Test Plan: Integration test.

fbshipit-source-id: c11d1f6
  • Loading branch information
dreiss authored and facebook-github-bot committed May 9, 2017
1 parent ff4e7ef commit 466f8ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/com/facebook/buck/android/MergeAssets.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,18 @@ public StepExecutionResult execute(ExecutionContext context)
for (ZipEntry inputEntry = base.getNextEntry();
inputEntry != null;
base.closeEntry(), inputEntry = base.getNextEntry()) {
String extension = Files.getFileExtension(inputEntry.getName());
// Only compress if aapt compressed it and the extension looks compressible.
// This is a workaround for aapt2 compressing everything.
boolean shouldCompress =
inputEntry.getMethod() != ZipEntry.STORED
&& !NO_COMPRESS_EXTENSIONS.contains(extension);
byte[] data = ByteStreams.toByteArray(base);
addEntry(
output,
data,
inputEntry.getName(),
inputEntry.getMethod() == ZipEntry.STORED ? 0 : Deflater.BEST_COMPRESSION,
shouldCompress ? Deflater.BEST_COMPRESSION : 0,
inputEntry.isDirectory());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ public void testSimpleAapt2App() throws IOException {
zipInspector.assertFileExists("res/layout/top_layout.xml");
zipInspector.assertFileExists("assets/asset_file.txt");

zipInspector.assertFileIsNotCompressed("res/drawable/tiny_black.png");

Map<String, String> rDotJavaContents =
parseRDotJavaSmali(outputs.get("//apps/sample:disassemble_app_with_aapt2"));
Map<String, String> resourceBundleContents =
Expand Down

0 comments on commit 466f8ac

Please sign in to comment.