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

new: support building with compact entries #3708

Merged
merged 2 commits into from
Oct 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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