blob: 84665e7b531343ca7d8e9edab8a43487c0ef6e02 [file] [log] [blame]
Colin Crossf0056cb2017-12-22 15:56:08 -08001// Copyright 2017 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
15package java
16
17import (
Jiyong Park54105c42021-03-31 18:17:53 +090018 "strconv"
Colin Crossf0056cb2017-12-22 15:56:08 -080019 "strings"
20
21 "github.com/google/blueprint"
David Srbeckye033cba2020-05-20 22:20:28 +010022 "github.com/google/blueprint/proptools"
Colin Crossf0056cb2017-12-22 15:56:08 -080023
24 "android/soong/android"
Ramy Medhat1dcc27e2020-04-21 21:36:23 -040025 "android/soong/remoteexec"
Colin Crossf0056cb2017-12-22 15:56:08 -080026)
27
Liz Kammera7a64f32020-07-09 15:16:41 -070028type DexProperties struct {
29 // If set to true, compile dex regardless of installable. Defaults to false.
30 Compile_dex *bool
31
32 // list of module-specific flags that will be used for dex compiles
33 Dxflags []string `android:"arch_variant"`
34
Colin Cross5ea963e2021-09-16 19:13:43 -070035 // A list of files containing rules that specify the classes to keep in the main dex file.
36 Main_dex_rules []string `android:"path"`
37
Liz Kammera7a64f32020-07-09 15:16:41 -070038 Optimize struct {
39 // If false, disable all optimization. Defaults to true for android_app and android_test
40 // modules, false for java_library and java_test modules.
41 Enabled *bool
42 // True if the module containing this has it set by default.
43 EnabledByDefault bool `blueprint:"mutated"`
44
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +020045 // If true, runs R8 in Proguard compatibility mode (default).
46 // Otherwise, runs R8 in full mode.
47 Proguard_compatibility *bool
48
Liz Kammera7a64f32020-07-09 15:16:41 -070049 // If true, optimize for size by removing unused code. Defaults to true for apps,
50 // false for libraries and tests.
51 Shrink *bool
52
53 // If true, optimize bytecode. Defaults to false.
54 Optimize *bool
55
56 // If true, obfuscate bytecode. Defaults to false.
57 Obfuscate *bool
58
59 // If true, do not use the flag files generated by aapt that automatically keep
60 // classes referenced by the app manifest. Defaults to false.
61 No_aapt_flags *bool
62
63 // Flags to pass to proguard.
64 Proguard_flags []string
65
66 // Specifies the locations of files containing proguard flags.
67 Proguard_flags_files []string `android:"path"`
68 }
69
70 // Keep the data uncompressed. We always need uncompressed dex for execution,
71 // so this might actually save space by avoiding storing the same data twice.
72 // This defaults to reasonable value based on module and should not be set.
73 // It exists only to support ART tests.
74 Uncompress_dex *bool
Wei Li1e73c652021-12-06 13:35:11 -080075
Wei Li92cd54b2022-01-12 13:22:55 -080076 // Exclude kotlinc generate files: *.kotlin_module, *.kotlin_builtins. Defaults to false.
Wei Li1e73c652021-12-06 13:35:11 -080077 Exclude_kotlinc_generated_files *bool
Liz Kammera7a64f32020-07-09 15:16:41 -070078}
79
80type dexer struct {
81 dexProperties DexProperties
82
83 // list of extra proguard flag files
84 extraProguardFlagFiles android.Paths
85 proguardDictionary android.OptionalPath
Colin Crosscb6143a2020-08-14 17:39:29 -070086 proguardUsageZip android.OptionalPath
Liz Kammera7a64f32020-07-09 15:16:41 -070087}
88
89func (d *dexer) effectiveOptimizeEnabled() bool {
90 return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault)
91}
92
Colin Cross77cdcfd2021-03-12 11:28:25 -080093var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
Colin Crossf0056cb2017-12-22 15:56:08 -080094 blueprint.RuleParams{
95 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
Colin Crossa79a52c2021-08-04 10:52:44 -070096 `mkdir -p $$(dirname $tmpJar) && ` +
97 `${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` +
98 `$d8Template${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $tmpJar && ` +
Kousik Kumar366afc52020-05-20 11:27:16 -070099 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
Wei Li1e73c652021-12-06 13:35:11 -0800100 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in`,
Colin Crossf0056cb2017-12-22 15:56:08 -0800101 CommandDeps: []string{
102 "${config.D8Cmd}",
Colin Crossa79a52c2021-08-04 10:52:44 -0700103 "${config.Zip2ZipCmd}",
Colin Crossf0056cb2017-12-22 15:56:08 -0800104 "${config.SoongZipCmd}",
105 "${config.MergeZipsCmd}",
106 },
Kousik Kumar366afc52020-05-20 11:27:16 -0700107 }, map[string]*remoteexec.REParams{
108 "$d8Template": &remoteexec.REParams{
109 Labels: map[string]string{"type": "compile", "compiler": "d8"},
110 Inputs: []string{"${config.D8Jar}"},
111 ExecStrategy: "${config.RED8ExecStrategy}",
112 ToolchainInputs: []string{"${config.JavaCmd}"},
113 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
114 },
115 "$zipTemplate": &remoteexec.REParams{
116 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
117 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
118 OutputFiles: []string{"$outDir/classes.dex.jar"},
119 ExecStrategy: "${config.RED8ExecStrategy}",
120 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
121 },
Wei Li1e73c652021-12-06 13:35:11 -0800122 }, []string{"outDir", "d8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, nil)
Colin Crossf0056cb2017-12-22 15:56:08 -0800123
Colin Cross77cdcfd2021-03-12 11:28:25 -0800124var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800125 blueprint.RuleParams{
126 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700127 `rm -f "$outDict" && rm -rf "${outUsageDir}" && ` +
128 `mkdir -p $$(dirname ${outUsage}) && ` +
Colin Crossa79a52c2021-08-04 10:52:44 -0700129 `mkdir -p $$(dirname $tmpJar) && ` +
130 `${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` +
131 `$r8Template${config.R8Cmd} ${config.DexFlags} -injars $tmpJar --output $outDir ` +
Søren Gjesse24f17022018-09-14 15:20:42 +0200132 `--no-data-resources ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700133 `-printmapping ${outDict} ` +
134 `-printusage ${outUsage} ` +
Colin Cross22e6a6f2022-03-21 12:19:44 -0700135 `--deps-file ${out}.d ` +
Colin Crossffb657e2018-09-21 12:29:22 -0700136 `$r8Flags && ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700137 `touch "${outDict}" "${outUsage}" && ` +
138 `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
139 `rm -rf ${outUsageDir} && ` +
Kousik Kumar366afc52020-05-20 11:27:16 -0700140 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
Wei Li1e73c652021-12-06 13:35:11 -0800141 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in`,
Colin Cross22e6a6f2022-03-21 12:19:44 -0700142 Depfile: "${out}.d",
143 Deps: blueprint.DepsGCC,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800144 CommandDeps: []string{
Colin Crossa832a042021-08-05 16:56:18 -0700145 "${config.R8Cmd}",
Colin Crossa79a52c2021-08-04 10:52:44 -0700146 "${config.Zip2ZipCmd}",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800147 "${config.SoongZipCmd}",
148 "${config.MergeZipsCmd}",
149 },
Kousik Kumar366afc52020-05-20 11:27:16 -0700150 }, map[string]*remoteexec.REParams{
151 "$r8Template": &remoteexec.REParams{
152 Labels: map[string]string{"type": "compile", "compiler": "r8"},
153 Inputs: []string{"$implicits", "${config.R8Jar}"},
Colin Crosse00c0e72020-09-17 11:54:30 -0700154 OutputFiles: []string{"${outUsage}"},
Kousik Kumar366afc52020-05-20 11:27:16 -0700155 ExecStrategy: "${config.RER8ExecStrategy}",
156 ToolchainInputs: []string{"${config.JavaCmd}"},
157 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
158 },
159 "$zipTemplate": &remoteexec.REParams{
160 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
161 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
162 OutputFiles: []string{"$outDir/classes.dex.jar"},
163 ExecStrategy: "${config.RER8ExecStrategy}",
164 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
165 },
Colin Crosscb6143a2020-08-14 17:39:29 -0700166 "$zipUsageTemplate": &remoteexec.REParams{
167 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
168 Inputs: []string{"${config.SoongZipCmd}", "${outUsage}"},
169 OutputFiles: []string{"${outUsageZip}"},
170 ExecStrategy: "${config.RER8ExecStrategy}",
171 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
172 },
173 }, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
Wei Li1e73c652021-12-06 13:35:11 -0800174 "r8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, []string{"implicits"})
Colin Cross66dbc0b2017-12-28 12:23:20 -0800175
Colin Cross5ea963e2021-09-16 19:13:43 -0700176func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
177 minSdkVersion android.SdkSpec) (flags []string, deps android.Paths) {
178
179 flags = d.dexProperties.Dxflags
Colin Crossbafb8972018-06-06 21:46:32 +0000180 // Translate all the DX flags to D8 ones until all the build files have been migrated
181 // to D8 flags. See: b/69377755
182 flags = android.RemoveListFromList(flags,
183 []string{"--core-library", "--dex", "--multi-dex"})
Colin Crossf0056cb2017-12-22 15:56:08 -0800184
Colin Cross5ea963e2021-09-16 19:13:43 -0700185 for _, f := range android.PathsForModuleSrc(ctx, d.dexProperties.Main_dex_rules) {
186 flags = append(flags, "--main-dex-rules", f.String())
187 deps = append(deps, f)
188 }
189
Colin Crossf0056cb2017-12-22 15:56:08 -0800190 if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Crossbafb8972018-06-06 21:46:32 +0000191 flags = append(flags, "--debug")
Colin Crossf0056cb2017-12-22 15:56:08 -0800192 }
193
194 if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
195 flags = append(flags,
196 "--debug",
197 "--verbose")
Colin Crossf0056cb2017-12-22 15:56:08 -0800198 }
199
Jiyong Parkf1691d22021-03-29 20:11:58 +0900200 effectiveVersion, err := minSdkVersion.EffectiveVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -0700201 if err != nil {
202 ctx.PropertyErrorf("min_sdk_version", "%s", err)
203 }
204
Jiyong Park54105c42021-03-31 18:17:53 +0900205 flags = append(flags, "--min-api "+strconv.Itoa(effectiveVersion.FinalOrFutureInt()))
Colin Cross5ea963e2021-09-16 19:13:43 -0700206 return flags, deps
Colin Crossf0056cb2017-12-22 15:56:08 -0800207}
208
Liz Kammera7a64f32020-07-09 15:16:41 -0700209func d8Flags(flags javaBuilderFlags) (d8Flags []string, d8Deps android.Paths) {
Colin Crossc2557d12019-10-31 15:22:57 -0700210 d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...)
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700211 d8Flags = append(d8Flags, flags.dexClasspath.FormRepeatedClassPath("--lib ")...)
Colin Crossffb657e2018-09-21 12:29:22 -0700212
Colin Cross6dab9bd2018-09-28 08:06:24 -0700213 d8Deps = append(d8Deps, flags.bootClasspath...)
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700214 d8Deps = append(d8Deps, flags.dexClasspath...)
Colin Cross6dab9bd2018-09-28 08:06:24 -0700215
216 return d8Flags, d8Deps
Colin Crossffb657e2018-09-21 12:29:22 -0700217}
218
Liz Kammera7a64f32020-07-09 15:16:41 -0700219func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Flags []string, r8Deps android.Paths) {
220 opt := d.dexProperties.Optimize
Colin Cross66dbc0b2017-12-28 12:23:20 -0800221
222 // When an app contains references to APIs that are not in the SDK specified by
223 // its LOCAL_SDK_VERSION for example added by support library or by runtime
Colin Crossbafb8972018-06-06 21:46:32 +0000224 // classes added by desugaring, we artifically raise the "SDK version" "linked" by
Colin Cross66dbc0b2017-12-28 12:23:20 -0800225 // ProGuard, to
226 // - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
227 // - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
228 // See b/20667396
229 var proguardRaiseDeps classpath
Colin Crossdcf71b22021-02-01 13:59:03 -0800230 ctx.VisitDirectDepsWithTag(proguardRaiseTag, func(m android.Module) {
231 dep := ctx.OtherModuleProvider(m, JavaInfoProvider).(JavaInfo)
232 proguardRaiseDeps = append(proguardRaiseDeps, dep.HeaderJars...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800233 })
234
235 r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars"))
236 r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars"))
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700237 r8Flags = append(r8Flags, flags.dexClasspath.FormJavaClassPath("-libraryjars"))
Colin Cross66dbc0b2017-12-28 12:23:20 -0800238
Colin Cross6dab9bd2018-09-28 08:06:24 -0700239 r8Deps = append(r8Deps, proguardRaiseDeps...)
240 r8Deps = append(r8Deps, flags.bootClasspath...)
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700241 r8Deps = append(r8Deps, flags.dexClasspath...)
Colin Cross6dab9bd2018-09-28 08:06:24 -0700242
Colin Cross66dbc0b2017-12-28 12:23:20 -0800243 flagFiles := android.Paths{
244 android.PathForSource(ctx, "build/make/core/proguard.flags"),
245 }
246
Liz Kammera7a64f32020-07-09 15:16:41 -0700247 flagFiles = append(flagFiles, d.extraProguardFlagFiles...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800248 // TODO(ccross): static android library proguard files
249
Liz Kammera7a64f32020-07-09 15:16:41 -0700250 flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...)
Colin Crossbd1cef52018-08-13 10:28:18 -0700251
Colin Cross66dbc0b2017-12-28 12:23:20 -0800252 r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include "))
253 r8Deps = append(r8Deps, flagFiles...)
254
255 // TODO(b/70942988): This is included from build/make/core/proguard.flags
256 r8Deps = append(r8Deps, android.PathForSource(ctx,
257 "build/make/core/proguard_basic_keeps.flags"))
258
Liz Kammera7a64f32020-07-09 15:16:41 -0700259 r8Flags = append(r8Flags, opt.Proguard_flags...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800260
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +0200261 if BoolDefault(opt.Proguard_compatibility, true) {
262 r8Flags = append(r8Flags, "--force-proguard-compatibility")
Ian Zernyfc7df612021-11-02 15:37:06 +0100263 } else {
264 // TODO(b/213833843): Allow configuration of the prefix via a build variable.
265 var sourceFilePrefix = "go/retraceme "
266 var sourceFileTemplate = "\"" + sourceFilePrefix + "%MAP_ID\""
267 // TODO(b/200967150): Also tag the source file in compat builds.
268 if Bool(opt.Optimize) || Bool(opt.Obfuscate) {
269 r8Flags = append(r8Flags, "--map-id-template", "%MAP_HASH")
270 r8Flags = append(r8Flags, "--source-file-template", sourceFileTemplate)
271 }
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +0200272 }
273
Colin Cross66dbc0b2017-12-28 12:23:20 -0800274 // TODO(ccross): Don't shrink app instrumentation tests by default.
275 if !Bool(opt.Shrink) {
276 r8Flags = append(r8Flags, "-dontshrink")
277 }
278
279 if !Bool(opt.Optimize) {
280 r8Flags = append(r8Flags, "-dontoptimize")
281 }
282
283 // TODO(ccross): error if obufscation + app instrumentation test.
284 if !Bool(opt.Obfuscate) {
285 r8Flags = append(r8Flags, "-dontobfuscate")
286 }
Colin Cross4b964c02018-10-15 16:18:06 -0700287 // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the
288 // dictionary of the app and move the app from libraryjars to injars.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800289
Jaewoong Jung1d6eb682018-11-29 15:08:44 -0800290 // Don't strip out debug information for eng builds.
291 if ctx.Config().Eng() {
292 r8Flags = append(r8Flags, "--debug")
293 }
294
Christoffer Quist Adamsene8507372021-02-22 09:44:09 +0100295 // TODO(b/180878971): missing classes should be added to the relevant builds.
296 r8Flags = append(r8Flags, "-ignorewarnings")
297
Colin Cross66dbc0b2017-12-28 12:23:20 -0800298 return r8Flags, r8Deps
299}
300
Jiyong Parkf1691d22021-03-29 20:11:58 +0900301func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion android.SdkSpec,
Paul Duffin612e6102021-02-02 13:38:13 +0000302 classesJar android.Path, jarName string) android.OutputPath {
Colin Crossf0056cb2017-12-22 15:56:08 -0800303
Colin Crossf0056cb2017-12-22 15:56:08 -0800304 // Compile classes.jar into classes.dex and then javalib.jar
Paul Duffin612e6102021-02-02 13:38:13 +0000305 javalibJar := android.PathForModuleOut(ctx, "dex", jarName).OutputPath
Colin Crossf0056cb2017-12-22 15:56:08 -0800306 outDir := android.PathForModuleOut(ctx, "dex")
Colin Crossa79a52c2021-08-04 10:52:44 -0700307 tmpJar := android.PathForModuleOut(ctx, "withres-withoutdex", jarName)
Colin Crossf0056cb2017-12-22 15:56:08 -0800308
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800309 zipFlags := "--ignore_missing_files"
Liz Kammera7a64f32020-07-09 15:16:41 -0700310 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800311 zipFlags += " -L 0"
Colin Cross5a0dcd52018-10-05 14:20:06 -0700312 }
313
Colin Cross5ea963e2021-09-16 19:13:43 -0700314 commonFlags, commonDeps := d.dexCommonFlags(ctx, minSdkVersion)
Liz Kammera7a64f32020-07-09 15:16:41 -0700315
Wei Li1e73c652021-12-06 13:35:11 -0800316 // Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true.
317 mergeZipsFlags := ""
318 if proptools.BoolDefault(d.dexProperties.Exclude_kotlinc_generated_files, false) {
319 mergeZipsFlags = "-stripFile META-INF/*.kotlin_module -stripFile **/*.kotlin_builtins"
320 }
321
Liz Kammera7a64f32020-07-09 15:16:41 -0700322 useR8 := d.effectiveOptimizeEnabled()
Colin Cross66dbc0b2017-12-28 12:23:20 -0800323 if useR8 {
Colin Crossc0c664c2018-05-16 16:47:21 -0700324 proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
Liz Kammera7a64f32020-07-09 15:16:41 -0700325 d.proguardDictionary = android.OptionalPathForPath(proguardDictionary)
Colin Crosscb6143a2020-08-14 17:39:29 -0700326 proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage")
327 proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path,
328 android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
329 proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
330 d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
Liz Kammera7a64f32020-07-09 15:16:41 -0700331 r8Flags, r8Deps := d.r8Flags(ctx, flags)
Colin Cross5ea963e2021-09-16 19:13:43 -0700332 r8Deps = append(r8Deps, commonDeps...)
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400333 rule := r8
334 args := map[string]string{
Wei Li1e73c652021-12-06 13:35:11 -0800335 "r8Flags": strings.Join(append(commonFlags, r8Flags...), " "),
336 "zipFlags": zipFlags,
337 "outDict": proguardDictionary.String(),
338 "outUsageDir": proguardUsageDir.String(),
339 "outUsage": proguardUsage.String(),
340 "outUsageZip": proguardUsageZip.String(),
341 "outDir": outDir.String(),
342 "tmpJar": tmpJar.String(),
343 "mergeZipsFlags": mergeZipsFlags,
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400344 }
Ramy Medhat16f23a42020-09-03 01:29:49 -0400345 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") {
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400346 rule = r8RE
347 args["implicits"] = strings.Join(r8Deps.Strings(), ",")
348 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800349 ctx.Build(pctx, android.BuildParams{
Colin Crosscb6143a2020-08-14 17:39:29 -0700350 Rule: rule,
351 Description: "r8",
352 Output: javalibJar,
353 ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip},
354 Input: classesJar,
355 Implicits: r8Deps,
356 Args: args,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800357 })
358 } else {
Liz Kammera7a64f32020-07-09 15:16:41 -0700359 d8Flags, d8Deps := d8Flags(flags)
Colin Cross5ea963e2021-09-16 19:13:43 -0700360 d8Deps = append(d8Deps, commonDeps...)
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400361 rule := d8
Ramy Medhat16f23a42020-09-03 01:29:49 -0400362 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") {
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400363 rule = d8RE
364 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800365 ctx.Build(pctx, android.BuildParams{
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400366 Rule: rule,
Colin Crossbafb8972018-06-06 21:46:32 +0000367 Description: "d8",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800368 Output: javalibJar,
369 Input: classesJar,
Colin Cross6dab9bd2018-09-28 08:06:24 -0700370 Implicits: d8Deps,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800371 Args: map[string]string{
Wei Li1e73c652021-12-06 13:35:11 -0800372 "d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
373 "zipFlags": zipFlags,
374 "outDir": outDir.String(),
375 "tmpJar": tmpJar.String(),
376 "mergeZipsFlags": mergeZipsFlags,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800377 },
378 })
Colin Crossf0056cb2017-12-22 15:56:08 -0800379 }
Liz Kammera7a64f32020-07-09 15:16:41 -0700380 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Paul Duffin612e6102021-02-02 13:38:13 +0000381 alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath
Nicolas Geoffray65fd8ba2019-01-21 23:20:23 +0000382 TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
383 javalibJar = alignedJavalibJar
384 }
Colin Crossf0056cb2017-12-22 15:56:08 -0800385
Colin Crossf0056cb2017-12-22 15:56:08 -0800386 return javalibJar
387}