resourceshrinker.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2022 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package java
  15. import (
  16. "android/soong/android"
  17. "github.com/google/blueprint"
  18. )
  19. var shrinkResources = pctx.AndroidStaticRule("shrinkResources",
  20. blueprint.RuleParams{
  21. // Note that we suppress stdout to avoid successful log confirmations.
  22. Command: `${config.ResourceShrinkerCmd} --output $out --input $in --raw_resources $raw_resources >/dev/null`,
  23. CommandDeps: []string{"${config.ResourceShrinkerCmd}"},
  24. }, "raw_resources")
  25. func ShrinkResources(ctx android.ModuleContext, apk android.Path, outputFile android.WritablePath) {
  26. protoFile := android.PathForModuleOut(ctx, apk.Base()+".proto.apk")
  27. aapt2Convert(ctx, protoFile, apk, "proto")
  28. strictModeFile := android.PathForSource(ctx, "prebuilts/cmdline-tools/shrinker.xml")
  29. protoOut := android.PathForModuleOut(ctx, apk.Base()+".proto.out.apk")
  30. ctx.Build(pctx, android.BuildParams{
  31. Rule: shrinkResources,
  32. Input: protoFile,
  33. Output: protoOut,
  34. Args: map[string]string{
  35. "raw_resources": strictModeFile.String(),
  36. },
  37. })
  38. aapt2Convert(ctx, outputFile, protoOut, "binary")
  39. }