| Rico Wind | a9fd59a | 2023-11-03 10:26:38 +0000 | [diff] [blame] | 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 |  | 
|  | 20 | "github.com/google/blueprint" | 
|  | 21 | ) | 
|  | 22 |  | 
|  | 23 | var shrinkResources = pctx.AndroidStaticRule("shrinkResources", | 
|  | 24 | blueprint.RuleParams{ | 
|  | 25 | // Note that we suppress stdout to avoid successful log confirmations. | 
| David Srbecky | 8f35478 | 2023-11-14 12:06:27 +0000 | [diff] [blame] | 26 | Command: `RESOURCESHRINKER_OPTS=-Dcom.android.tools.r8.dexContainerExperiment ` + | 
|  | 27 | `${config.ResourceShrinkerCmd} --output $out --input $in --raw_resources $raw_resources >/dev/null`, | 
| Rico Wind | a9fd59a | 2023-11-03 10:26:38 +0000 | [diff] [blame] | 28 | CommandDeps: []string{"${config.ResourceShrinkerCmd}"}, | 
|  | 29 | }, "raw_resources") | 
|  | 30 |  | 
|  | 31 | func ShrinkResources(ctx android.ModuleContext, apk android.Path, outputFile android.WritablePath) { | 
|  | 32 | protoFile := android.PathForModuleOut(ctx, apk.Base()+".proto.apk") | 
|  | 33 | aapt2Convert(ctx, protoFile, apk, "proto") | 
|  | 34 | strictModeFile := android.PathForSource(ctx, "prebuilts/cmdline-tools/shrinker.xml") | 
|  | 35 | protoOut := android.PathForModuleOut(ctx, apk.Base()+".proto.out.apk") | 
|  | 36 | ctx.Build(pctx, android.BuildParams{ | 
|  | 37 | Rule:   shrinkResources, | 
|  | 38 | Input:  protoFile, | 
|  | 39 | Output: protoOut, | 
|  | 40 | Args: map[string]string{ | 
|  | 41 | "raw_resources": strictModeFile.String(), | 
|  | 42 | }, | 
|  | 43 | }) | 
|  | 44 | aapt2Convert(ctx, outputFile, protoOut, "binary") | 
|  | 45 | } |