Skip to content

Commit

Permalink
feat: support building with compact entries (#3708)
Browse files Browse the repository at this point in the history
Pretty straightforward change. The motivation is to reproduce the original
structure of the source APK. If it's built with compact resource entries -
then rebuild with compact resource entries.
  • Loading branch information
IgorEisberg authored Oct 4, 2024
1 parent 24541c3 commit 7033f4e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ private void invokeAapt2(File apkFile, File manifest, File resDir, File rawDir,
cmd.add("--enable-sparse-encoding");
}

if (mApkInfo.compactEntries) {
cmd.add("--enable-compact-entries");
}

if (mApkInfo.isFrameworkApk) {
cmd.add("-x");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ApkInfo implements YamlSerializable {
public Map<String, Boolean> featureFlags = new LinkedHashMap<>();
public boolean sharedLibrary;
public boolean sparseResources;
public boolean compactEntries;
public List<String> doNotCompress = new ArrayList<>();

public ApkInfo() {
Expand Down Expand Up @@ -266,6 +267,10 @@ public void readItem(YamlReader reader) throws AndrolibException {
sparseResources = line.getValueBool();
break;
}
case "compactEntries": {
compactEntries = line.getValueBool();
break;
}
case "doNotCompress": {
doNotCompress.clear();
reader.readStringList(doNotCompress);
Expand All @@ -288,6 +293,7 @@ public void write(YamlWriter writer) {
}
writer.writeBool("sharedLibrary", sharedLibrary);
writer.writeBool("sparseResources", sparseResources);
writer.writeBool("compactEntries", compactEntries);
if (!doNotCompress.isEmpty()) {
writer.writeList("doNotCompress", doNotCompress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ public void setSparseResources(boolean flag) {
mApkInfo.sparseResources = flag;
}

public void setCompactEntries(boolean flag) {
if (mApkInfo.compactEntries != flag) {
LOGGER.info("Compactly packed resource entries detected.");
}
mApkInfo.compactEntries = flag;
}

public void addSdkInfo(String key, String value) {
mApkInfo.sdkInfo.put(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ private EntryData readEntryData() throws IOException, AndrolibException {
return null;
}

// Be sure we don't poison mResTable by marking the application as compact
// Only flag the ResTable as compact if the main package is not loaded.
if (isCompact && !mResTable.isMainPkgLoaded()) {
mResTable.setCompactEntries(true);
}

// #3366 - In a compactly packed entry, the key index is the size & type is higher 8 bits on flags.
// We assume a size of 8 bytes for compact entries and the specNamesId is the data itself encoded.
ResValue value;
Expand Down

0 comments on commit 7033f4e

Please sign in to comment.