blob: bb42c302e591406ae7d9b251397f548780df4893 [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
76 // Exclude kotlinc generate files: *.kotlin_module, *.kotlin_builtins. Defaults to true.
77 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 Crossffb657e2018-09-21 12:29:22 -0700135 `$r8Flags && ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700136 `touch "${outDict}" "${outUsage}" && ` +
137 `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
138 `rm -rf ${outUsageDir} && ` +
Kousik Kumar366afc52020-05-20 11:27:16 -0700139 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
Wei Li1e73c652021-12-06 13:35:11 -0800140 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in`,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800141 CommandDeps: []string{
Colin Crossa832a042021-08-05 16:56:18 -0700142 "${config.R8Cmd}",
Colin Crossa79a52c2021-08-04 10:52:44 -0700143 "${config.Zip2ZipCmd}",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800144 "${config.SoongZipCmd}",
145 "${config.MergeZipsCmd}",
146 },
Kousik Kumar366afc52020-05-20 11:27:16 -0700147 }, map[string]*remoteexec.REParams{
148 "$r8Template": &remoteexec.REParams{
149 Labels: map[string]string{"type": "compile", "compiler": "r8"},
150 Inputs: []string{"$implicits", "${config.R8Jar}"},
Colin Crosse00c0e72020-09-17 11:54:30 -0700151 OutputFiles: []string{"${outUsage}"},
Kousik Kumar366afc52020-05-20 11:27:16 -0700152 ExecStrategy: "${config.RER8ExecStrategy}",
153 ToolchainInputs: []string{"${config.JavaCmd}"},
154 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
155 },
156 "$zipTemplate": &remoteexec.REParams{
157 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
158 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
159 OutputFiles: []string{"$outDir/classes.dex.jar"},
160 ExecStrategy: "${config.RER8ExecStrategy}",
161 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
162 },
Colin Crosscb6143a2020-08-14 17:39:29 -0700163 "$zipUsageTemplate": &remoteexec.REParams{
164 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
165 Inputs: []string{"${config.SoongZipCmd}", "${outUsage}"},
166 OutputFiles: []string{"${outUsageZip}"},
167 ExecStrategy: "${config.RER8ExecStrategy}",
168 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
169 },
170 }, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
Wei Li1e73c652021-12-06 13:35:11 -0800171 "r8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, []string{"implicits"})
Colin Cross66dbc0b2017-12-28 12:23:20 -0800172
Colin Cross5ea963e2021-09-16 19:13:43 -0700173func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
174 minSdkVersion android.SdkSpec) (flags []string, deps android.Paths) {
175
176 flags = d.dexProperties.Dxflags
Colin Crossbafb8972018-06-06 21:46:32 +0000177 // Translate all the DX flags to D8 ones until all the build files have been migrated
178 // to D8 flags. See: b/69377755
179 flags = android.RemoveListFromList(flags,
180 []string{"--core-library", "--dex", "--multi-dex"})
Colin Crossf0056cb2017-12-22 15:56:08 -0800181
Colin Cross5ea963e2021-09-16 19:13:43 -0700182 for _, f := range android.PathsForModuleSrc(ctx, d.dexProperties.Main_dex_rules) {
183 flags = append(flags, "--main-dex-rules", f.String())
184 deps = append(deps, f)
185 }
186
Colin Crossf0056cb2017-12-22 15:56:08 -0800187 if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
Colin Crossbafb8972018-06-06 21:46:32 +0000188 flags = append(flags, "--debug")
Colin Crossf0056cb2017-12-22 15:56:08 -0800189 }
190
191 if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
192 flags = append(flags,
193 "--debug",
194 "--verbose")
Colin Crossf0056cb2017-12-22 15:56:08 -0800195 }
196
Jiyong Parkf1691d22021-03-29 20:11:58 +0900197 effectiveVersion, err := minSdkVersion.EffectiveVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -0700198 if err != nil {
199 ctx.PropertyErrorf("min_sdk_version", "%s", err)
200 }
201
Jiyong Park54105c42021-03-31 18:17:53 +0900202 flags = append(flags, "--min-api "+strconv.Itoa(effectiveVersion.FinalOrFutureInt()))
Colin Cross5ea963e2021-09-16 19:13:43 -0700203 return flags, deps
Colin Crossf0056cb2017-12-22 15:56:08 -0800204}
205
Liz Kammera7a64f32020-07-09 15:16:41 -0700206func d8Flags(flags javaBuilderFlags) (d8Flags []string, d8Deps android.Paths) {
Colin Crossc2557d12019-10-31 15:22:57 -0700207 d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...)
208 d8Flags = append(d8Flags, flags.classpath.FormRepeatedClassPath("--lib ")...)
Colin Crossffb657e2018-09-21 12:29:22 -0700209
Colin Cross6dab9bd2018-09-28 08:06:24 -0700210 d8Deps = append(d8Deps, flags.bootClasspath...)
211 d8Deps = append(d8Deps, flags.classpath...)
212
213 return d8Flags, d8Deps
Colin Crossffb657e2018-09-21 12:29:22 -0700214}
215
Liz Kammera7a64f32020-07-09 15:16:41 -0700216func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Flags []string, r8Deps android.Paths) {
217 opt := d.dexProperties.Optimize
Colin Cross66dbc0b2017-12-28 12:23:20 -0800218
219 // When an app contains references to APIs that are not in the SDK specified by
220 // its LOCAL_SDK_VERSION for example added by support library or by runtime
Colin Crossbafb8972018-06-06 21:46:32 +0000221 // classes added by desugaring, we artifically raise the "SDK version" "linked" by
Colin Cross66dbc0b2017-12-28 12:23:20 -0800222 // ProGuard, to
223 // - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
224 // - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
225 // See b/20667396
226 var proguardRaiseDeps classpath
Colin Crossdcf71b22021-02-01 13:59:03 -0800227 ctx.VisitDirectDepsWithTag(proguardRaiseTag, func(m android.Module) {
228 dep := ctx.OtherModuleProvider(m, JavaInfoProvider).(JavaInfo)
229 proguardRaiseDeps = append(proguardRaiseDeps, dep.HeaderJars...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800230 })
231
232 r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars"))
233 r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars"))
234 r8Flags = append(r8Flags, flags.classpath.FormJavaClassPath("-libraryjars"))
Colin Cross66dbc0b2017-12-28 12:23:20 -0800235
Colin Cross6dab9bd2018-09-28 08:06:24 -0700236 r8Deps = append(r8Deps, proguardRaiseDeps...)
237 r8Deps = append(r8Deps, flags.bootClasspath...)
238 r8Deps = append(r8Deps, flags.classpath...)
239
Colin Cross66dbc0b2017-12-28 12:23:20 -0800240 flagFiles := android.Paths{
241 android.PathForSource(ctx, "build/make/core/proguard.flags"),
242 }
243
Liz Kammera7a64f32020-07-09 15:16:41 -0700244 flagFiles = append(flagFiles, d.extraProguardFlagFiles...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800245 // TODO(ccross): static android library proguard files
246
Liz Kammera7a64f32020-07-09 15:16:41 -0700247 flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...)
Colin Crossbd1cef52018-08-13 10:28:18 -0700248
Colin Cross66dbc0b2017-12-28 12:23:20 -0800249 r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include "))
250 r8Deps = append(r8Deps, flagFiles...)
251
252 // TODO(b/70942988): This is included from build/make/core/proguard.flags
253 r8Deps = append(r8Deps, android.PathForSource(ctx,
254 "build/make/core/proguard_basic_keeps.flags"))
255
Liz Kammera7a64f32020-07-09 15:16:41 -0700256 r8Flags = append(r8Flags, opt.Proguard_flags...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800257
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +0200258 if BoolDefault(opt.Proguard_compatibility, true) {
259 r8Flags = append(r8Flags, "--force-proguard-compatibility")
260 }
261
Colin Cross66dbc0b2017-12-28 12:23:20 -0800262 // TODO(ccross): Don't shrink app instrumentation tests by default.
263 if !Bool(opt.Shrink) {
264 r8Flags = append(r8Flags, "-dontshrink")
265 }
266
267 if !Bool(opt.Optimize) {
268 r8Flags = append(r8Flags, "-dontoptimize")
269 }
270
271 // TODO(ccross): error if obufscation + app instrumentation test.
272 if !Bool(opt.Obfuscate) {
273 r8Flags = append(r8Flags, "-dontobfuscate")
274 }
Colin Cross4b964c02018-10-15 16:18:06 -0700275 // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the
276 // dictionary of the app and move the app from libraryjars to injars.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800277
Jaewoong Jung1d6eb682018-11-29 15:08:44 -0800278 // Don't strip out debug information for eng builds.
279 if ctx.Config().Eng() {
280 r8Flags = append(r8Flags, "--debug")
281 }
282
Christoffer Quist Adamsene8507372021-02-22 09:44:09 +0100283 // TODO(b/180878971): missing classes should be added to the relevant builds.
284 r8Flags = append(r8Flags, "-ignorewarnings")
285
Colin Cross66dbc0b2017-12-28 12:23:20 -0800286 return r8Flags, r8Deps
287}
288
Jiyong Parkf1691d22021-03-29 20:11:58 +0900289func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion android.SdkSpec,
Paul Duffin612e6102021-02-02 13:38:13 +0000290 classesJar android.Path, jarName string) android.OutputPath {
Colin Crossf0056cb2017-12-22 15:56:08 -0800291
Colin Crossf0056cb2017-12-22 15:56:08 -0800292 // Compile classes.jar into classes.dex and then javalib.jar
Paul Duffin612e6102021-02-02 13:38:13 +0000293 javalibJar := android.PathForModuleOut(ctx, "dex", jarName).OutputPath
Colin Crossf0056cb2017-12-22 15:56:08 -0800294 outDir := android.PathForModuleOut(ctx, "dex")
Colin Crossa79a52c2021-08-04 10:52:44 -0700295 tmpJar := android.PathForModuleOut(ctx, "withres-withoutdex", jarName)
Colin Crossf0056cb2017-12-22 15:56:08 -0800296
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800297 zipFlags := "--ignore_missing_files"
Liz Kammera7a64f32020-07-09 15:16:41 -0700298 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800299 zipFlags += " -L 0"
Colin Cross5a0dcd52018-10-05 14:20:06 -0700300 }
301
Colin Cross5ea963e2021-09-16 19:13:43 -0700302 commonFlags, commonDeps := d.dexCommonFlags(ctx, minSdkVersion)
Liz Kammera7a64f32020-07-09 15:16:41 -0700303
Wei Li1e73c652021-12-06 13:35:11 -0800304 // Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true.
305 mergeZipsFlags := ""
306 if proptools.BoolDefault(d.dexProperties.Exclude_kotlinc_generated_files, false) {
307 mergeZipsFlags = "-stripFile META-INF/*.kotlin_module -stripFile **/*.kotlin_builtins"
308 }
309
Liz Kammera7a64f32020-07-09 15:16:41 -0700310 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{
Wei Li1e73c652021-12-06 13:35:11 -0800323 "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(),
330 "tmpJar": tmpJar.String(),
331 "mergeZipsFlags": mergeZipsFlags,
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400332 }
Ramy Medhat16f23a42020-09-03 01:29:49 -0400333 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") {
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400334 rule = r8RE
335 args["implicits"] = strings.Join(r8Deps.Strings(), ",")
336 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800337 ctx.Build(pctx, android.BuildParams{
Colin Crosscb6143a2020-08-14 17:39:29 -0700338 Rule: rule,
339 Description: "r8",
340 Output: javalibJar,
341 ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip},
342 Input: classesJar,
343 Implicits: r8Deps,
344 Args: args,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800345 })
346 } else {
Liz Kammera7a64f32020-07-09 15:16:41 -0700347 d8Flags, d8Deps := d8Flags(flags)
Colin Cross5ea963e2021-09-16 19:13:43 -0700348 d8Deps = append(d8Deps, commonDeps...)
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400349 rule := d8
Ramy Medhat16f23a42020-09-03 01:29:49 -0400350 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") {
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400351 rule = d8RE
352 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800353 ctx.Build(pctx, android.BuildParams{
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400354 Rule: rule,
Colin Crossbafb8972018-06-06 21:46:32 +0000355 Description: "d8",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800356 Output: javalibJar,
357 Input: classesJar,
Colin Cross6dab9bd2018-09-28 08:06:24 -0700358 Implicits: d8Deps,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800359 Args: map[string]string{
Wei Li1e73c652021-12-06 13:35:11 -0800360 "d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
361 "zipFlags": zipFlags,
362 "outDir": outDir.String(),
363 "tmpJar": tmpJar.String(),
364 "mergeZipsFlags": mergeZipsFlags,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800365 },
366 })
Colin Crossf0056cb2017-12-22 15:56:08 -0800367 }
Liz Kammera7a64f32020-07-09 15:16:41 -0700368 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Paul Duffin612e6102021-02-02 13:38:13 +0000369 alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath
Nicolas Geoffray65fd8ba2019-01-21 23:20:23 +0000370 TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
371 javalibJar = alignedJavalibJar
372 }
Colin Crossf0056cb2017-12-22 15:56:08 -0800373
Colin Crossf0056cb2017-12-22 15:56:08 -0800374 return javalibJar
375}