Expose '--force-sparse-encoding' flag for 'optimize' and 'convert' commands.
This allows to use sparse encoding for APKs that do not specify minSdk
version inside. This is common for split APKs generated by bundletool
when Android App Bundle (AAB) is split into multiple APKs.
Bug: b/223394605
Test: TableFlattener_test
Change-Id: I2a99a611f855cffbcea20018d869e1eb54d1b3d5
diff --git a/tools/aapt2/cmd/Optimize.h b/tools/aapt2/cmd/Optimize.h
index ff63e8d..10b84b0c 100644
--- a/tools/aapt2/cmd/Optimize.h
+++ b/tools/aapt2/cmd/Optimize.h
@@ -61,6 +61,12 @@
// Path to the output map of original resource paths to shortened paths.
std::optional<std::string> shortened_paths_map_path;
+
+ // Whether sparse encoding should be used for O+ resources.
+ bool enable_sparse_encoding = false;
+
+ // Whether sparse encoding should be used for all resources.
+ bool force_sparse_encoding = false;
};
class OptimizeCommand : public Command {
@@ -96,10 +102,18 @@
"Comma separated list of artifacts to keep. If none are specified,\n"
"all artifacts will be kept.",
&kept_artifacts_);
- AddOptionalSwitch("--enable-sparse-encoding",
+ AddOptionalSwitch(
+ "--enable-sparse-encoding",
"Enables encoding sparse entries using a binary search tree.\n"
- "This decreases APK size at the cost of resource retrieval performance.",
- &options_.table_flattener_options.use_sparse_entries);
+ "This decreases APK size at the cost of resource retrieval performance.\n"
+ "Only applies sparse encoding to Android O+ resources or all resources if minSdk of "
+ "the APK is O+",
+ &options_.enable_sparse_encoding);
+ AddOptionalSwitch("--force-sparse-encoding",
+ "Enables encoding sparse entries using a binary search tree.\n"
+ "This decreases APK size at the cost of resource retrieval performance.\n"
+ "Applies sparse encoding to all resources regardless of minSdk.",
+ &options_.force_sparse_encoding);
AddOptionalSwitch("--collapse-resource-names",
"Collapses resource names to a single value in the key string pool. Resources can \n"
"be exempted using the \"no_collapse\" directive in a file specified by "