Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0fadc4b authored by Iurii Makhno's avatar Iurii Makhno Committed by Android (Google) Code Review
Browse files

Merge "Expose '--force-sparse-encoding' flag for 'optimize' and 'convert' commands."

parents b1df3606 da06e4d9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -395,6 +395,12 @@ int ConvertCommand::Action(const std::vector<std::string>& args) {
                                    << output_format_.value());
    return 1;
  }
  if (enable_sparse_encoding_) {
    table_flattener_options_.sparse_entries = SparseEntriesMode::Enabled;
  }
  if (force_sparse_encoding_) {
    table_flattener_options_.sparse_entries = SparseEntriesMode::Forced;
  }

  return Convert(&context, apk.get(), writer.get(), format, table_flattener_options_,
                 xml_flattener_options_);
+13 −3
Original line number Diff line number Diff line
@@ -34,10 +34,18 @@ class ConvertCommand : public Command {
    AddOptionalFlag("--output-format", android::base::StringPrintf("Format of the output. "
            "Accepted values are '%s' and '%s'. When not set, defaults to '%s'.",
        kOutputFormatProto, kOutputFormatBinary, kOutputFormatBinary), &output_format_);
    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.",
         &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+",
        &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.",
                      &force_sparse_encoding_);
    AddOptionalSwitch("--keep-raw-values",
        android::base::StringPrintf("Preserve raw attribute values in xml files when using the"
            " '%s' output format", kOutputFormatBinary),
@@ -56,6 +64,8 @@ class ConvertCommand : public Command {
  std::string output_path_;
  std::optional<std::string> output_format_;
  bool verbose_ = false;
  bool enable_sparse_encoding_ = false;
  bool force_sparse_encoding_ = false;
};

int Convert(IAaptContext* context, LoadedApk* input, IArchiveWriter* output_writer,
+3 −0
Original line number Diff line number Diff line
@@ -2419,6 +2419,9 @@ int LinkCommand::Action(const std::vector<std::string>& args) {
                << "the --merge-only flag can be only used when building a static library");
    return 1;
  }
  if (options_.use_sparse_encoding) {
    options_.table_flattener_options.sparse_entries = SparseEntriesMode::Enabled;
  }

  // The default build type.
  context.SetPackageType(PackageType::kApp);
+3 −2
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ struct LinkOptions {
  bool no_resource_removal = false;
  bool no_xml_namespaces = false;
  bool do_not_compress_anything = false;
  bool use_sparse_encoding = false;
  std::unordered_set<std::string> extensions_to_not_compress;
  std::optional<std::regex> regex_to_not_compress;

@@ -157,7 +158,7 @@ class LinkCommand : public Command {
        &options_.no_resource_removal);
    AddOptionalSwitch("--enable-sparse-encoding",
                      "This decreases APK size at the cost of resource retrieval performance.",
        &options_.table_flattener_options.use_sparse_entries);
                      &options_.use_sparse_encoding);
    AddOptionalSwitch("-x", "Legacy flag that specifies to use the package identifier 0x01.",
        &legacy_x_flag_);
    AddOptionalSwitch("-z", "Require localization of strings marked 'suggested'.",
+7 −0
Original line number Diff line number Diff line
@@ -427,6 +427,13 @@ int OptimizeCommand::Action(const std::vector<std::string>& args) {
    return 1;
  }

  if (options_.enable_sparse_encoding) {
    options_.table_flattener_options.sparse_entries = SparseEntriesMode::Enabled;
  }
  if (options_.force_sparse_encoding) {
    options_.table_flattener_options.sparse_entries = SparseEntriesMode::Forced;
  }

  if (target_densities_) {
    // Parse the target screen densities.
    for (const StringPiece& config_str : util::Tokenize(target_densities_.value(), ',')) {
Loading