Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AAB asset compression breaking media files #2530

Merged
merged 1 commit into from Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,12 +15,20 @@
import java.io.IOException;
import java.io.PrintStream;

import java.nio.charset.StandardCharsets;

import java.util.ArrayList;
import java.util.List;

import java.util.concurrent.Callable;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
* This Callable class will convert the compiled files into an Android App Bundle.
* An AAB file structure looks like this:
Expand All @@ -34,6 +42,45 @@
* - lib/
*/
public class AabCompiler implements Callable<Boolean> {

// These regexes were taken from a project compiled via Android Studio
private static final String[] NONCOMPRESSIBLE_EXTS = new String[] {
"**.3[gG]2",
"**.3[gG][pP]",
"**.3[gG][pP][pP]",
"**.3[gG][pP][pP]2",
"**.[aA][aA][cC]",
"**.[aA][mM][rR]",
"**.[aA][wW][bB]",
"**.[gG][iI][fF]",
"**.[iI][mM][yY]",
"**.[jJ][eE][tT]",
"**.[jJ][pP][eE][gG]",
"**.[jJ][pP][gG]",
"**.[mM]4[aA]",
"**.[mM]4[vV]",
"**.[mM][iI][dD]",
"**.[mM][iI][dD][iI]",
"**.[mM][kK][vV]",
"**.[mM][pP]2",
"**.[mM][pP]3",
"**.[mM][pP]4",
"**.[mM][pP][eE][gG]",
"**.[mM][pP][gG]",
"**.[oO][gG][gG]",
"**.[oO][pP][uU][sS]",
"**.[pP][nN][gG]",
"**.[rR][tT][tT][tT][lL]",
"**.[sS][mM][fF]",
"**.[tT][fF][lL][iI][tT][eE]",
"**.[wW][aA][vV]",
"**.[wW][eE][bB][mM]",
"**.[wW][eE][bB][pP]",
"**.[wW][mM][aA]",
"**.[wW][mM][vV]",
"**.[xX][mM][fF]"
};

private PrintStream out;
private File buildDir;
private int mx;
Expand Down Expand Up @@ -284,6 +331,27 @@ private boolean extractProtobuf() {
}

private boolean bundletool() {
// Create the bundle configuration
File configFile;
try {
configFile = File.createTempFile("BundleConfig", ".pb.json");
} catch (IOException e) {
throw new RuntimeException("Unable to generate bundle config", e);
}
try (FileOutputStream out = new FileOutputStream(configFile)) {
JSONObject config = new JSONObject();
JSONObject compression = new JSONObject();
JSONArray uncompressedGlob = new JSONArray();
config.put("compression", compression);
compression.put("uncompressedGlob", uncompressedGlob);
for (String ext : NONCOMPRESSIBLE_EXTS) {
uncompressedGlob.put(ext);
}
out.write(config.toString().getBytes(StandardCharsets.UTF_8));
} catch (JSONException | IOException e) {
throw new RuntimeException("Unable to generate AAB", e);
}

aab.setBase(new File(buildDir, "base.zip"));

if (!AabZipper.zipBundle(aab.getRoot(), aab.getBase(), aab.getRoot().getName() + File.separator)) {
Expand All @@ -297,6 +365,7 @@ private boolean bundletool() {
bundletoolCommandLine.add(bundletool);
bundletoolCommandLine.add("build-bundle");
bundletoolCommandLine.add("--modules=" + aab.getBase());
bundletoolCommandLine.add("--config=" + configFile.getAbsolutePath());
bundletoolCommandLine.add("--output=" + deploy);
String[] bundletoolBuildCommandLine = bundletoolCommandLine.toArray(new String[0]);

Expand Down
2 changes: 1 addition & 1 deletion appinventor/components/build.xml
Expand Up @@ -168,7 +168,7 @@
<copy toFile="${public.deps.dir}/android.jar" file="${android.lib}" />
<copy toFile="${public.deps.dir}/dx.jar" file="${lib.dir}/android/tools/dx.jar" />
<copy toFile="${public.deps.dir}/apksigner.jar" file="${lib.dir}/android/tools/apksigner.jar" />
<copy toFile="${public.deps.dir}/bundletool.jar" file="${lib.dir}/android/tools/bundletool-all-0.15.0.jar" />
<copy toFile="${public.deps.dir}/bundletool.jar" file="${lib.dir}/android/tools/bundletool-all-1.7.1.jar" />
<copy toFile="${public.deps.dir}/CommonVersion.jar" file="${build.dir}/common/CommonVersion.jar" />

<!-- Add extension libraries here -->
Expand Down
Binary file not shown.