blob: c59c3396d1518b5f5c81d77cf47ab403c6d0709a [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
75}
76
77type dexer struct {
78 dexProperties DexProperties
79
80 // list of extra proguard flag files
81 extraProguardFlagFiles android.Paths
82 proguardDictionary android.OptionalPath
Colin Crosscb6143a2020-08-14 17:39:29 -070083 proguardUsageZip android.OptionalPath
Liz Kammera7a64f32020-07-09 15:16:41 -070084}
85
86func (d *dexer) effectiveOptimizeEnabled() bool {
87 return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault)
88}
89
Colin Cross77cdcfd2021-03-12 11:28:25 -080090var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
Colin Crossf0056cb2017-12-22 15:56:08 -080091 blueprint.RuleParams{
92 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
Colin Crossa79a52c2021-08-04 10:52:44 -070093 `mkdir -p $$(dirname $tmpJar) && ` +
94 `${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` +
95 `$d8Template${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $tmpJar && ` +
Kousik Kumar366afc52020-05-20 11:27:16 -070096 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
Colin Cross4c03f682018-07-15 08:16:31 -070097 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
Colin Crossf0056cb2017-12-22 15:56:08 -080098 CommandDeps: []string{
99 "${config.D8Cmd}",
Colin Crossa79a52c2021-08-04 10:52:44 -0700100 "${config.Zip2ZipCmd}",
Colin Crossf0056cb2017-12-22 15:56:08 -0800101 "${config.SoongZipCmd}",
102 "${config.MergeZipsCmd}",
103 },
Kousik Kumar366afc52020-05-20 11:27:16 -0700104 }, map[string]*remoteexec.REParams{
105 "$d8Template": &remoteexec.REParams{
106 Labels: map[string]string{"type": "compile", "compiler": "d8"},
107 Inputs: []string{"${config.D8Jar}"},
108 ExecStrategy: "${config.RED8ExecStrategy}",
109 ToolchainInputs: []string{"${config.JavaCmd}"},
110 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
111 },
112 "$zipTemplate": &remoteexec.REParams{
113 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
114 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
115 OutputFiles: []string{"$outDir/classes.dex.jar"},
116 ExecStrategy: "${config.RED8ExecStrategy}",
117 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
118 },
Colin Crossa79a52c2021-08-04 10:52:44 -0700119 }, []string{"outDir", "d8Flags", "zipFlags", "tmpJar"}, nil)
Colin Crossf0056cb2017-12-22 15:56:08 -0800120
Colin Cross77cdcfd2021-03-12 11:28:25 -0800121var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800122 blueprint.RuleParams{
123 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700124 `rm -f "$outDict" && rm -rf "${outUsageDir}" && ` +
125 `mkdir -p $$(dirname ${outUsage}) && ` +
Colin Crossa79a52c2021-08-04 10:52:44 -0700126 `mkdir -p $$(dirname $tmpJar) && ` +
127 `${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` +
128 `$r8Template${config.R8Cmd} ${config.DexFlags} -injars $tmpJar --output $outDir ` +
Søren Gjesse24f17022018-09-14 15:20:42 +0200129 `--no-data-resources ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700130 `-printmapping ${outDict} ` +
131 `-printusage ${outUsage} ` +
Colin Crossffb657e2018-09-21 12:29:22 -0700132 `$r8Flags && ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700133 `touch "${outDict}" "${outUsage}" && ` +
134 `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
135 `rm -rf ${outUsageDir} && ` +
Kousik Kumar366afc52020-05-20 11:27:16 -0700136 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
Colin Cross4c03f682018-07-15 08:16:31 -0700137 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800138 CommandDeps: []string{
Colin Crossa832a042021-08-05 16:56:18 -0700139 "${config.R8Cmd}",
Colin Crossa79a52c2021-08-04 10:52:44 -0700140 "${config.Zip2ZipCmd}",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800141 "${config.SoongZipCmd}",
142 "${config.MergeZipsCmd}",
143 },
Kousik Kumar366afc52020-05-20 11:27:16 -0700144 }, map[string]*remoteexec.REParams{
145 "$r8Template": &remoteexec.REParams{
146 Labels: map[string]string{"type": "compile", "compiler": "r8"},
147 Inputs: []string{"$implicits", "${config.R8Jar}"},
Colin Crosse00c0e72020-09-17 11:54:30 -0700148 OutputFiles: []string{"${outUsage}"},
Kousik Kumar366afc52020-05-20 11:27:16 -0700149 ExecStrategy: "${config.RER8ExecStrategy}",
150 ToolchainInputs: []string{"${config.JavaCmd}"},
151 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
152 },
153 "$zipTemplate": &remoteexec.REParams{
154 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
155 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
156 OutputFiles: []string{"$outDir/classes.dex.jar"},
157 ExecStrategy: "${config.RER8ExecStrategy}",
158 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
159 },
Colin Crosscb6143a2020-08-14 17:39:29 -0700160 "$zipUsageTemplate": &remoteexec.REParams{
161 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
162 Inputs: []string{"${config.SoongZipCmd}", "${outUsage}"},
163 OutputFiles: []string{"${outUsageZip}"},
164 ExecStrategy: "${config.RER8ExecStrategy}",
165 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
166 },
167 }, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
Colin Crossa79a52c2021-08-04 10:52:44 -0700168 "r8Flags", "zipFlags", "tmpJar"}, []string{"implicits"})
Colin Cross66dbc0b2017-12-28 12:23:20 -0800169
Colin Cross5ea963e2021-09-16 19:13:43 -0700170func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
171 minSdkVersion android.SdkSpec) (flags []string, deps android.Paths) {
172
173 flags = d.dexProperties.Dxflags
Colin Crossbafb8972018-06-06 21:46:32 +0000174 // Translate all the DX flags to D8 ones until all the build files have been migrated
175 // to D8 flags. See: b/69377755
176 flags = android.RemoveListFromList(flags,
177 []string{"--core-library", "--dex", "--multi-dex"})
Colin Crossf0056cb2017-12-22 15:56:08 -0800178
Colin Cross5ea963e2021-09-16 19:13:43 -0700179 for _, f := range android.PathsForModuleSrc(ctx, d.dexProperties.Main_dex_rules) {
180 flags = append(flags, "--main-dex-rules", f.String())
181 deps = append(deps, f)
182 }
183
Colin Crossf0056cb2017-12-22 15:56:08 -0800184 if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Crossbafb8972018-06-06 21:46:32 +0000185 flags = append(flags, "--debug")
Colin Crossf0056cb2017-12-22 15:56:08 -0800186 }
187
188 if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
189 flags = append(flags,
190 "--debug",
191 "--verbose")
Colin Crossf0056cb2017-12-22 15:56:08 -0800192 }
193
Jiyong Parkf1691d22021-03-29 20:11:58 +0900194 effectiveVersion, err := minSdkVersion.EffectiveVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -0700195 if err != nil {
196 ctx.PropertyErrorf("min_sdk_version", "%s", err)
197 }
198
Jiyong Park54105c42021-03-31 18:17:53 +0900199 flags = append(flags, "--min-api "+strconv.Itoa(effectiveVersion.FinalOrFutureInt()))
Colin Cross5ea963e2021-09-16 19:13:43 -0700200 return flags, deps
Colin Crossf0056cb2017-12-22 15:56:08 -0800201}
202
Liz Kammera7a64f32020-07-09 15:16:41 -0700203func d8Flags(flags javaBuilderFlags) (d8Flags []string, d8Deps android.Paths) {
Colin Crossc2557d12019-10-31 15:22:57 -0700204 d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...)
205 d8Flags = append(d8Flags, flags.classpath.FormRepeatedClassPath("--lib ")...)
Colin Crossffb657e2018-09-21 12:29:22 -0700206
Colin Cross6dab9bd2018-09-28 08:06:24 -0700207 d8Deps = append(d8Deps, flags.bootClasspath...)
208 d8Deps = append(d8Deps, flags.classpath...)
209
210 return d8Flags, d8Deps
Colin Crossffb657e2018-09-21 12:29:22 -0700211}
212
Liz Kammera7a64f32020-07-09 15:16:41 -0700213func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Flags []string, r8Deps android.Paths) {
214 opt := d.dexProperties.Optimize
Colin Cross66dbc0b2017-12-28 12:23:20 -0800215
216 // When an app contains references to APIs that are not in the SDK specified by
217 // its LOCAL_SDK_VERSION for example added by support library or by runtime
Colin Crossbafb8972018-06-06 21:46:32 +0000218 // classes added by desugaring, we artifically raise the "SDK version" "linked" by
Colin Cross66dbc0b2017-12-28 12:23:20 -0800219 // ProGuard, to
220 // - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
221 // - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
222 // See b/20667396
223 var proguardRaiseDeps classpath
Colin Crossdcf71b22021-02-01 13:59:03 -0800224 ctx.VisitDirectDepsWithTag(proguardRaiseTag, func(m android.Module) {
225 dep := ctx.OtherModuleProvider(m, JavaInfoProvider).(JavaInfo)
226 proguardRaiseDeps = append(proguardRaiseDeps, dep.HeaderJars...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800227 })
228
229 r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars"))
230 r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars"))
231 r8Flags = append(r8Flags, flags.classpath.FormJavaClassPath("-libraryjars"))
Colin Cross66dbc0b2017-12-28 12:23:20 -0800232
Colin Cross6dab9bd2018-09-28 08:06:24 -0700233 r8Deps = append(r8Deps, proguardRaiseDeps...)
234 r8Deps = append(r8Deps, flags.bootClasspath...)
235 r8Deps = append(r8Deps, flags.classpath...)
236
Colin Cross66dbc0b2017-12-28 12:23:20 -0800237 flagFiles := android.Paths{
238 android.PathForSource(ctx, "build/make/core/proguard.flags"),
239 }
240
Liz Kammera7a64f32020-07-09 15:16:41 -0700241 flagFiles = append(flagFiles, d.extraProguardFlagFiles...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800242 // TODO(ccross): static android library proguard files
243
Liz Kammera7a64f32020-07-09 15:16:41 -0700244 flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...)
Colin Crossbd1cef52018-08-13 10:28:18 -0700245
Colin Cross66dbc0b2017-12-28 12:23:20 -0800246 r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include "))
247 r8Deps = append(r8Deps, flagFiles...)
248
249 // TODO(b/70942988): This is included from build/make/core/proguard.flags
250 r8Deps = append(r8Deps, android.PathForSource(ctx,
251 "build/make/core/proguard_basic_keeps.flags"))
252
Liz Kammera7a64f32020-07-09 15:16:41 -0700253 r8Flags = append(r8Flags, opt.Proguard_flags...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800254
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +0200255 if BoolDefault(opt.Proguard_compatibility, true) {
256 r8Flags = append(r8Flags, "--force-proguard-compatibility")
Ian Zernyfc7df612021-11-02 15:37:06 +0100257 } else {
258 // TODO(b/213833843): Allow configuration of the prefix via a build variable.
259 var sourceFilePrefix = "go/retraceme "
260 var sourceFileTemplate = "\"" + sourceFilePrefix + "%MAP_ID\""
261 // TODO(b/200967150): Also tag the source file in compat builds.
262 if Bool(opt.Optimize) || Bool(opt.Obfuscate) {
263 r8Flags = append(r8Flags, "--map-id-template", "%MAP_HASH")
264 r8Flags = append(r8Flags, "--source-file-template", sourceFileTemplate)
265 }
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +0200266 }
267
Colin Cross66dbc0b2017-12-28 12:23:20 -0800268 // TODO(ccross): Don't shrink app instrumentation tests by default.
269 if !Bool(opt.Shrink) {
270 r8Flags = append(r8Flags, "-dontshrink")
271 }
272
273 if !Bool(opt.Optimize) {
274 r8Flags = append(r8Flags, "-dontoptimize")
275 }
276
277 // TODO(ccross): error if obufscation + app instrumentation test.
278 if !Bool(opt.Obfuscate) {
279 r8Flags = append(r8Flags, "-dontobfuscate")
280 }
Colin Cross4b964c02018-10-15 16:18:06 -0700281 // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the
282 // dictionary of the app and move the app from libraryjars to injars.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800283
Jaewoong Jung1d6eb682018-11-29 15:08:44 -0800284 // Don't strip out debug information for eng builds.
285 if ctx.Config().Eng() {
286 r8Flags = append(r8Flags, "--debug")
287 }
288
Christoffer Quist Adamsene8507372021-02-22 09:44:09 +0100289 // TODO(b/180878971): missing classes should be added to the relevant builds.
290 r8Flags = append(r8Flags, "-ignorewarnings")
291
Colin Cross66dbc0b2017-12-28 12:23:20 -0800292 return r8Flags, r8Deps
293}
294
Jiyong Parkf1691d22021-03-29 20:11:58 +0900295func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion android.SdkSpec,
Paul Duffin612e6102021-02-02 13:38:13 +0000296 classesJar android.Path, jarName string) android.OutputPath {
Colin Crossf0056cb2017-12-22 15:56:08 -0800297
Colin Crossf0056cb2017-12-22 15:56:08 -0800298 // Compile classes.jar into classes.dex and then javalib.jar
Paul Duffin612e6102021-02-02 13:38:13 +0000299 javalibJar := android.PathForModuleOut(ctx, "dex", jarName).OutputPath
Colin Crossf0056cb2017-12-22 15:56:08 -0800300 outDir := android.PathForModuleOut(ctx, "dex")
Colin Crossa79a52c2021-08-04 10:52:44 -0700301 tmpJar := android.PathForModuleOut(ctx, "withres-withoutdex", jarName)
Colin Crossf0056cb2017-12-22 15:56:08 -0800302
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800303 zipFlags := "--ignore_missing_files"
Liz Kammera7a64f32020-07-09 15:16:41 -0700304 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800305 zipFlags += " -L 0"
Colin Cross5a0dcd52018-10-05 14:20:06 -0700306 }
307
Colin Cross5ea963e2021-09-16 19:13:43 -0700308 commonFlags, commonDeps := d.dexCommonFlags(ctx, minSdkVersion)
Liz Kammera7a64f32020-07-09 15:16:41 -0700309
310 useR8 := d.effectiveOptimizeEnabled()
Colin Cross66dbc0b2017-12-28 12:23:20 -0800311 if useR8 {
Colin Crossc0c664c2018-05-16 16:47:21 -0700312 proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
Liz Kammera7a64f32020-07-09 15:16:41 -0700313 d.proguardDictionary = android.OptionalPathForPath(proguardDictionary)
Colin Crosscb6143a2020-08-14 17:39:29 -0700314 proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage")
315 proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path,
316 android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
317 proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
318 d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
Liz Kammera7a64f32020-07-09 15:16:41 -0700319 r8Flags, r8Deps := d.r8Flags(ctx, flags)
Colin Cross5ea963e2021-09-16 19:13:43 -0700320 r8Deps = append(r8Deps, commonDeps...)
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400321 rule := r8
322 args := map[string]string{
Colin Crosscb6143a2020-08-14 17:39:29 -0700323 "r8Flags": strings.Join(append(commonFlags, r8Flags...), " "),
324 "zipFlags": zipFlags,
325 "outDict": proguardDictionary.String(),
326 "outUsageDir": proguardUsageDir.String(),
327 "outUsage": proguardUsage.String(),
328 "outUsageZip": proguardUsageZip.String(),
329 "outDir": outDir.String(),
Colin Crossa79a52c2021-08-04 10:52:44 -0700330 "tmpJar": tmpJar.String(),
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400331 }
Ramy Medhat16f23a42020-09-03 01:29:49 -0400332 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") {
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400333 rule = r8RE
334 args["implicits"] = strings.Join(r8Deps.Strings(), ",")
335 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800336 ctx.Build(pctx, android.BuildParams{
Colin Crosscb6143a2020-08-14 17:39:29 -0700337 Rule: rule,
338 Description: "r8",
339 Output: javalibJar,
340 ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip},
341 Input: classesJar,
342 Implicits: r8Deps,
343 Args: args,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800344 })
345 } else {
Liz Kammera7a64f32020-07-09 15:16:41 -0700346 d8Flags, d8Deps := d8Flags(flags)
Colin Cross5ea963e2021-09-16 19:13:43 -0700347 d8Deps = append(d8Deps, commonDeps...)
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400348 rule := d8
Ramy Medhat16f23a42020-09-03 01:29:49 -0400349 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") {
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400350 rule = d8RE
351 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800352 ctx.Build(pctx, android.BuildParams{
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400353 Rule: rule,
Colin Crossbafb8972018-06-06 21:46:32 +0000354 Description: "d8",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800355 Output: javalibJar,
356 Input: classesJar,
Colin Cross6dab9bd2018-09-28 08:06:24 -0700357 Implicits: d8Deps,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800358 Args: map[string]string{
Liz Kammera7a64f32020-07-09 15:16:41 -0700359 "d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
Colin Cross5a0dcd52018-10-05 14:20:06 -0700360 "zipFlags": zipFlags,
361 "outDir": outDir.String(),
Colin Crossa79a52c2021-08-04 10:52:44 -0700362 "tmpJar": tmpJar.String(),
Colin Cross66dbc0b2017-12-28 12:23:20 -0800363 },
364 })
Colin Crossf0056cb2017-12-22 15:56:08 -0800365 }
Liz Kammera7a64f32020-07-09 15:16:41 -0700366 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Paul Duffin612e6102021-02-02 13:38:13 +0000367 alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath
Nicolas Geoffray65fd8ba2019-01-21 23:20:23 +0000368 TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
369 javalibJar = alignedJavalibJar
370 }
Colin Crossf0056cb2017-12-22 15:56:08 -0800371
Colin Crossf0056cb2017-12-22 15:56:08 -0800372 return javalibJar
373}