blob: e5f41ea7dd64c4491b0cb426fd522767f86c1db9 [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 {
Jared Duke63a3da92022-06-02 19:11:14 +000039 // If false, disable all optimization. Defaults to true for android_app and
40 // android_test_helper_app modules, false for android_test, java_library, and java_test modules.
Liz Kammera7a64f32020-07-09 15:16:41 -070041 Enabled *bool
42 // True if the module containing this has it set by default.
43 EnabledByDefault bool `blueprint:"mutated"`
44
Christoffer Adamsenc8fd1f12025-01-06 19:04:03 +010045 // Whether to allow that library classes inherit from program classes.
46 // Defaults to false.
47 Ignore_library_extends_program *bool
48
Ajinkya Chalkeddad41b2023-02-09 14:09:58 +000049 // Whether to continue building even if warnings are emitted. Defaults to true.
Remi NGUYEN VANbdad3142022-08-04 13:19:03 +090050 Ignore_warnings *bool
51
Christoffer Adamsen8ec5f612025-01-09 11:05:11 +010052 // Whether runtime invisible annotations should be kept by R8. Defaults to false.
53 // This is equivalent to:
54 // -keepattributes RuntimeInvisibleAnnotations,
55 // RuntimeInvisibleParameterAnnotations,
56 // RuntimeInvisibleTypeAnnotations
57 // This is only applicable when RELEASE_R8_ONLY_RUNTIME_VISIBLE_ANNOTATIONS is
58 // enabled and will be used to migrate away from keeping runtime invisible
59 // annotations (b/387958004).
60 Keep_runtime_invisible_annotations *bool
61
Jared Dukeaa88b3d2023-08-29 17:07:20 +000062 // If true, runs R8 in Proguard compatibility mode, otherwise runs R8 in full mode.
Christoffer Adamsenc8fd1f12025-01-06 19:04:03 +010063 // Defaults to false for apps and tests, true for libraries.
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +020064 Proguard_compatibility *bool
65
Liz Kammera7a64f32020-07-09 15:16:41 -070066 // If true, optimize for size by removing unused code. Defaults to true for apps,
67 // false for libraries and tests.
68 Shrink *bool
69
70 // If true, optimize bytecode. Defaults to false.
71 Optimize *bool
72
73 // If true, obfuscate bytecode. Defaults to false.
74 Obfuscate *bool
75
76 // If true, do not use the flag files generated by aapt that automatically keep
77 // classes referenced by the app manifest. Defaults to false.
78 No_aapt_flags *bool
79
Jared Duke51b0a102022-09-27 16:53:11 -070080 // If true, optimize for size by removing unused resources. Defaults to false.
Rico Wind351bac92022-09-22 10:41:42 +020081 Shrink_resources *bool
82
Rico Winda2fa2632024-03-13 13:09:17 +010083 // If true, use optimized resource shrinking in R8, overriding the
84 // Shrink_resources setting. Defaults to false.
85 // Optimized shrinking means that R8 will trace and treeshake resources together with code
86 // and apply additional optimizations. This implies non final fields in the R classes.
87 Optimized_shrink_resources *bool
88
Liz Kammera7a64f32020-07-09 15:16:41 -070089 // Flags to pass to proguard.
90 Proguard_flags []string
91
92 // Specifies the locations of files containing proguard flags.
93 Proguard_flags_files []string `android:"path"`
Sam Delmerico95d70942023-08-02 18:00:35 -040094
95 // If true, transitive reverse dependencies of this module will have this
96 // module's proguard spec appended to their optimization action
97 Export_proguard_flags_files *bool
Liz Kammera7a64f32020-07-09 15:16:41 -070098 }
99
100 // Keep the data uncompressed. We always need uncompressed dex for execution,
101 // so this might actually save space by avoiding storing the same data twice.
102 // This defaults to reasonable value based on module and should not be set.
103 // It exists only to support ART tests.
104 Uncompress_dex *bool
Wei Li1e73c652021-12-06 13:35:11 -0800105
Wei Li92cd54b2022-01-12 13:22:55 -0800106 // Exclude kotlinc generate files: *.kotlin_module, *.kotlin_builtins. Defaults to false.
Wei Li1e73c652021-12-06 13:35:11 -0800107 Exclude_kotlinc_generated_files *bool
Ulya Trafimovichc8160582024-07-10 08:32:45 +0100108
109 // Disable dex container (also known as "multi-dex").
110 // This may be necessary as a temporary workaround to mask toolchain bugs (see b/341652226).
111 No_dex_container *bool
Liz Kammera7a64f32020-07-09 15:16:41 -0700112}
113
114type dexer struct {
115 dexProperties DexProperties
116
117 // list of extra proguard flag files
Colin Cross312634e2023-11-21 15:13:56 -0800118 extraProguardFlagsFiles android.Paths
119 proguardDictionary android.OptionalPath
120 proguardConfiguration android.OptionalPath
121 proguardUsageZip android.OptionalPath
122 resourcesInput android.OptionalPath
123 resourcesOutput android.OptionalPath
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500124
Colin Cross9ffaf282024-08-12 13:50:09 -0700125 providesTransitiveHeaderJarsForR8
Liz Kammera7a64f32020-07-09 15:16:41 -0700126}
127
128func (d *dexer) effectiveOptimizeEnabled() bool {
129 return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault)
130}
131
Rico Wind936754c2024-05-07 09:08:31 +0200132func (d *DexProperties) resourceShrinkingEnabled(ctx android.ModuleContext) bool {
133 return !ctx.Config().Eng() && BoolDefault(d.Optimize.Optimized_shrink_resources, Bool(d.Optimize.Shrink_resources))
134}
135
136func (d *DexProperties) optimizedResourceShrinkingEnabled(ctx android.ModuleContext) bool {
Rico Winda7b38592024-08-26 12:10:44 +0200137 return d.resourceShrinkingEnabled(ctx) && BoolDefault(d.Optimize.Optimized_shrink_resources, ctx.Config().UseOptimizedResourceShrinkingByDefault())
Rico Winda2fa2632024-03-13 13:09:17 +0100138}
139
Spandan Das15a67112024-05-30 00:07:40 +0000140func (d *dexer) optimizeOrObfuscateEnabled() bool {
141 return d.effectiveOptimizeEnabled() && (proptools.Bool(d.dexProperties.Optimize.Optimize) || proptools.Bool(d.dexProperties.Optimize.Obfuscate))
142}
143
Colin Cross77cdcfd2021-03-12 11:28:25 -0800144var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
Colin Crossf0056cb2017-12-22 15:56:08 -0800145 blueprint.RuleParams{
146 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
David Srbeckybda964c2023-11-24 15:57:54 +0000147 `$d8Template${config.D8Cmd} ${config.D8Flags} $d8Flags --output $outDir --no-dex-input-jar $in && ` +
Kousik Kumar366afc52020-05-20 11:27:16 -0700148 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
Colin Cross56e28402023-09-28 14:38:06 -0700149 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` +
Haamed Gheibie90a6712024-10-04 12:37:21 -0700150 `rm -f "$outDir"/classes*.dex "$outDir/classes.dex.jar"`,
Colin Crossf0056cb2017-12-22 15:56:08 -0800151 CommandDeps: []string{
152 "${config.D8Cmd}",
153 "${config.SoongZipCmd}",
154 "${config.MergeZipsCmd}",
155 },
Kousik Kumar366afc52020-05-20 11:27:16 -0700156 }, map[string]*remoteexec.REParams{
157 "$d8Template": &remoteexec.REParams{
158 Labels: map[string]string{"type": "compile", "compiler": "d8"},
159 Inputs: []string{"${config.D8Jar}"},
160 ExecStrategy: "${config.RED8ExecStrategy}",
161 ToolchainInputs: []string{"${config.JavaCmd}"},
162 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
163 },
164 "$zipTemplate": &remoteexec.REParams{
165 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
166 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
167 OutputFiles: []string{"$outDir/classes.dex.jar"},
168 ExecStrategy: "${config.RED8ExecStrategy}",
169 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
170 },
Ian Zernydb2d35b2023-10-10 12:22:39 +0200171 }, []string{"outDir", "d8Flags", "zipFlags", "mergeZipsFlags"}, nil)
Colin Crossf0056cb2017-12-22 15:56:08 -0800172
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800173// Include all of the args for d8r8, so that we can generate the partialcompileclean target's build using the same list.
174var d8r8Clean = pctx.AndroidStaticRule("d8r8-partialcompileclean",
175 blueprint.RuleParams{
176 Command: `rm -rf "${outDir}" "${outDict}" "${outConfig}" "${outUsage}" "${outUsageZip}" "${outUsageDir}" ` +
177 `"${resourcesOutput}" "${outR8ArtProfile}" ${builtOut}`,
178 }, "outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir", "builtOut",
179 "d8Flags", "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput", "outR8ArtProfile", "implicits",
180)
181
182var d8r8, d8r8RE = pctx.MultiCommandRemoteStaticRules("d8r8",
183 blueprint.RuleParams{
184 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
185 `rm -f "$outDict" && rm -f "$outConfig" && rm -rf "${outUsageDir}" && ` +
186 `mkdir -p $$(dirname ${outUsage}) && ` +
187 `if [ -n "$${SOONG_USE_PARTIAL_COMPILE}" ]; then ` +
188 ` for f in "${outConfig}" "${outDict}" "${outUsage}" "${resourcesOutput}"; do ` +
189 ` test -n "$${f}" && test ! -f "$${f}" && mkdir -p "$$(dirname "$${f}")" && touch "$${f}" || true; ` +
190 ` done && ` +
191 ` $d8Template${config.D8Cmd} ${config.D8Flags} $d8Flags --output $outDir --no-dex-input-jar $in; ` +
192 `else ` +
193 ` $r8Template${config.R8Cmd} ${config.R8Flags} $r8Flags -injars $in --output $outDir ` +
194 ` --no-data-resources ` +
195 ` -printmapping ${outDict} ` +
196 ` -printconfiguration ${outConfig} ` +
197 ` -printusage ${outUsage} ` +
198 ` --deps-file ${out}.d && ` +
199 ` touch "${outDict}" "${outConfig}" "${outUsage}"; ` +
200 `fi && ` +
201 `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
202 `rm -rf ${outUsageDir} && ` +
203 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
204 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` +
205 `rm -f "$outDir"/classes*.dex "$outDir/classes.dex.jar" `,
206 CommandDeps: []string{
207 "${config.D8Cmd}",
208 "${config.R8Cmd}",
209 "${config.SoongZipCmd}",
210 "${config.MergeZipsCmd}",
211 },
212 }, map[string]*remoteexec.REParams{
213 "$d8Template": &remoteexec.REParams{
214 Labels: map[string]string{"type": "compile", "compiler": "d8"},
215 Inputs: []string{"${config.D8Jar}"},
216 ExecStrategy: "${config.RED8ExecStrategy}",
217 ToolchainInputs: []string{"${config.JavaCmd}"},
218 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
219 },
220 "$r8Template": &remoteexec.REParams{
221 Labels: map[string]string{"type": "compile", "compiler": "r8"},
222 Inputs: []string{"$implicits", "${config.R8Jar}"},
223 OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}", "${outR8ArtProfile}"},
224 ExecStrategy: "${config.RER8ExecStrategy}",
225 ToolchainInputs: []string{"${config.JavaCmd}"},
226 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
227 },
228 "$zipTemplate": &remoteexec.REParams{
229 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
230 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
231 OutputFiles: []string{"$outDir/classes.dex.jar"},
232 ExecStrategy: "${config.RED8ExecStrategy}",
233 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
234 },
235 }, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir",
236 "d8Flags", "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput", "outR8ArtProfile"}, []string{"implicits"})
237
Colin Cross77cdcfd2021-03-12 11:28:25 -0800238var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800239 blueprint.RuleParams{
240 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
Ian Zerny82044f12023-01-25 12:11:27 +0100241 `rm -f "$outDict" && rm -f "$outConfig" && rm -rf "${outUsageDir}" && ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700242 `mkdir -p $$(dirname ${outUsage}) && ` +
David Srbeckybda964c2023-11-24 15:57:54 +0000243 `$r8Template${config.R8Cmd} ${config.R8Flags} $r8Flags -injars $in --output $outDir ` +
Søren Gjesse24f17022018-09-14 15:20:42 +0200244 `--no-data-resources ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700245 `-printmapping ${outDict} ` +
Jared Duke34c6d7d2023-05-05 20:40:20 +0000246 `-printconfiguration ${outConfig} ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700247 `-printusage ${outUsage} ` +
David Srbeckybda964c2023-11-24 15:57:54 +0000248 `--deps-file ${out}.d && ` +
Ian Zerny82044f12023-01-25 12:11:27 +0100249 `touch "${outDict}" "${outConfig}" "${outUsage}" && ` +
Colin Crosscb6143a2020-08-14 17:39:29 -0700250 `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
251 `rm -rf ${outUsageDir} && ` +
Kousik Kumar366afc52020-05-20 11:27:16 -0700252 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
Colin Cross56e28402023-09-28 14:38:06 -0700253 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` +
Haamed Gheibie90a6712024-10-04 12:37:21 -0700254 `rm -f "$outDir"/classes*.dex "$outDir/classes.dex.jar"`,
Colin Cross22e6a6f2022-03-21 12:19:44 -0700255 Depfile: "${out}.d",
256 Deps: blueprint.DepsGCC,
Colin Cross66dbc0b2017-12-28 12:23:20 -0800257 CommandDeps: []string{
Colin Crossa832a042021-08-05 16:56:18 -0700258 "${config.R8Cmd}",
Colin Cross66dbc0b2017-12-28 12:23:20 -0800259 "${config.SoongZipCmd}",
260 "${config.MergeZipsCmd}",
261 },
Kousik Kumar366afc52020-05-20 11:27:16 -0700262 }, map[string]*remoteexec.REParams{
263 "$r8Template": &remoteexec.REParams{
264 Labels: map[string]string{"type": "compile", "compiler": "r8"},
265 Inputs: []string{"$implicits", "${config.R8Jar}"},
Spandan Dasd447bbb2024-06-24 17:13:30 +0000266 OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}", "${outR8ArtProfile}"},
Kousik Kumar366afc52020-05-20 11:27:16 -0700267 ExecStrategy: "${config.RER8ExecStrategy}",
268 ToolchainInputs: []string{"${config.JavaCmd}"},
269 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
270 },
271 "$zipTemplate": &remoteexec.REParams{
272 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
273 Inputs: []string{"${config.SoongZipCmd}", "$outDir"},
274 OutputFiles: []string{"$outDir/classes.dex.jar"},
275 ExecStrategy: "${config.RER8ExecStrategy}",
276 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
277 },
Colin Crosscb6143a2020-08-14 17:39:29 -0700278 "$zipUsageTemplate": &remoteexec.REParams{
279 Labels: map[string]string{"type": "tool", "name": "soong_zip"},
280 Inputs: []string{"${config.SoongZipCmd}", "${outUsage}"},
281 OutputFiles: []string{"${outUsageZip}"},
282 ExecStrategy: "${config.RER8ExecStrategy}",
283 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
284 },
Ian Zerny82044f12023-01-25 12:11:27 +0100285 }, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir",
Spandan Dasd447bbb2024-06-24 17:13:30 +0000286 "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput", "outR8ArtProfile"}, []string{"implicits"})
Colin Cross66dbc0b2017-12-28 12:23:20 -0800287
Colin Cross5ea963e2021-09-16 19:13:43 -0700288func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
Spandan Dasc404cc72023-02-23 18:05:05 +0000289 dexParams *compileDexParams) (flags []string, deps android.Paths) {
Colin Cross5ea963e2021-09-16 19:13:43 -0700290
291 flags = d.dexProperties.Dxflags
Colin Crossbafb8972018-06-06 21:46:32 +0000292 // Translate all the DX flags to D8 ones until all the build files have been migrated
293 // to D8 flags. See: b/69377755
294 flags = android.RemoveListFromList(flags,
295 []string{"--core-library", "--dex", "--multi-dex"})
Colin Crossf0056cb2017-12-22 15:56:08 -0800296
Colin Cross5ea963e2021-09-16 19:13:43 -0700297 for _, f := range android.PathsForModuleSrc(ctx, d.dexProperties.Main_dex_rules) {
298 flags = append(flags, "--main-dex-rules", f.String())
299 deps = append(deps, f)
300 }
301
Jared Duke70b85422025-01-28 19:13:39 +0000302 var requestReleaseMode, requestDebugMode bool
Jared Duked32e85f2024-09-25 23:54:30 +0000303 requestReleaseMode, flags = android.RemoveFromList("--release", flags)
Jared Duke70b85422025-01-28 19:13:39 +0000304 requestDebugMode, flags = android.RemoveFromList("--debug", flags)
Jared Duked32e85f2024-09-25 23:54:30 +0000305
Abdelrahman Daim1cde8fc2024-10-01 06:55:58 -0700306 if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" || ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
Jared Duke70b85422025-01-28 19:13:39 +0000307 requestDebugMode = true
Jared Duked32e85f2024-09-25 23:54:30 +0000308 requestReleaseMode = false
Colin Crossf0056cb2017-12-22 15:56:08 -0800309 }
310
Jared Duked32e85f2024-09-25 23:54:30 +0000311 // Don't strip out debug information for eng builds, unless the target
312 // explicitly provided the `--release` build flag. This allows certain
313 // test targets to remain optimized as part of eng test_suites builds.
Jared Duke70b85422025-01-28 19:13:39 +0000314 if requestDebugMode {
315 flags = append(flags, "--debug")
316 } else if requestReleaseMode {
Jared Duked32e85f2024-09-25 23:54:30 +0000317 flags = append(flags, "--release")
318 } else if ctx.Config().Eng() {
319 flags = append(flags, "--debug")
Jared Duke70b85422025-01-28 19:13:39 +0000320 } else if !d.effectiveOptimizeEnabled() && d.dexProperties.Optimize.EnabledByDefault {
321 // D8 uses --debug by default, whereas R8 uses --release by default.
322 // For targets that default to R8 usage (e.g., apps), but override this default, we still
323 // want D8 to run in release mode, preserving semantics as much as possible between the two.
324 flags = append(flags, "--release")
Colin Crossf0056cb2017-12-22 15:56:08 -0800325 }
326
Jared Duke40d731a2022-09-20 15:32:14 -0700327 // Supplying the platform build flag disables various features like API modeling and desugaring.
328 // For targets with a stable min SDK version (i.e., when the min SDK is both explicitly specified
329 // and managed+versioned), we suppress this flag to ensure portability.
330 // Note: Targets with a min SDK kind of core_platform (e.g., framework.jar) or unspecified (e.g.,
331 // services.jar), are not classified as stable, which is WAI.
332 // TODO(b/232073181): Expand to additional min SDK cases after validation.
Ian Zernyc26029b2023-08-25 13:43:44 +0200333 var addAndroidPlatformBuildFlag = false
Spandan Dasc404cc72023-02-23 18:05:05 +0000334 if !dexParams.sdkVersion.Stable() {
Ian Zernyc26029b2023-08-25 13:43:44 +0200335 addAndroidPlatformBuildFlag = true
Jared Duke40d731a2022-09-20 15:32:14 -0700336 }
337
Spandan Dasc404cc72023-02-23 18:05:05 +0000338 effectiveVersion, err := dexParams.minSdkVersion.EffectiveVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -0700339 if err != nil {
340 ctx.PropertyErrorf("min_sdk_version", "%s", err)
341 }
David Srbecky55b46b02024-11-26 17:16:16 +0000342 if !Bool(d.dexProperties.No_dex_container) && effectiveVersion.FinalOrFutureInt() >= 36 && ctx.Config().UseDexV41() {
Ulya Trofimovich5bb46812024-08-07 19:25:58 +0000343 // W is 36, but we have not bumped the SDK version yet, so check for both.
344 if ctx.Config().PlatformSdkVersion().FinalInt() >= 36 ||
David Srbecky55b46b02024-11-26 17:16:16 +0000345 ctx.Config().PlatformSdkCodename() == "Baklava" {
346 flags = append([]string{"-JDcom.android.tools.r8.dexContainerExperiment"}, flags...)
Ulya Trofimovich5bb46812024-08-07 19:25:58 +0000347 }
348 }
Colin Cross83bb3162018-06-25 15:48:06 -0700349
Ian Zernyc26029b2023-08-25 13:43:44 +0200350 // If the specified SDK level is 10000, then configure the compiler to use the
351 // current platform SDK level and to compile the build as a platform build.
352 var minApiFlagValue = effectiveVersion.FinalOrFutureInt()
353 if minApiFlagValue == 10000 {
354 minApiFlagValue = ctx.Config().PlatformSdkVersion().FinalInt()
355 addAndroidPlatformBuildFlag = true
356 }
357 flags = append(flags, "--min-api "+strconv.Itoa(minApiFlagValue))
358
359 if addAndroidPlatformBuildFlag {
360 flags = append(flags, "--android-platform-build")
361 }
Colin Cross5ea963e2021-09-16 19:13:43 -0700362 return flags, deps
Colin Crossf0056cb2017-12-22 15:56:08 -0800363}
364
Spandan Das3dbda182024-05-20 22:23:10 +0000365func (d *dexer) d8Flags(ctx android.ModuleContext, dexParams *compileDexParams) (d8Flags []string, d8Deps android.Paths, artProfileOutput *android.OutputPath) {
366 flags := dexParams.flags
Colin Crossc2557d12019-10-31 15:22:57 -0700367 d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...)
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700368 d8Flags = append(d8Flags, flags.dexClasspath.FormRepeatedClassPath("--lib ")...)
Colin Crossffb657e2018-09-21 12:29:22 -0700369
Colin Cross6dab9bd2018-09-28 08:06:24 -0700370 d8Deps = append(d8Deps, flags.bootClasspath...)
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700371 d8Deps = append(d8Deps, flags.dexClasspath...)
Colin Cross6dab9bd2018-09-28 08:06:24 -0700372
Spandan Das3dbda182024-05-20 22:23:10 +0000373 if flags, deps, profileOutput := d.addArtProfile(ctx, dexParams); profileOutput != nil {
374 d8Flags = append(d8Flags, flags...)
375 d8Deps = append(d8Deps, deps...)
376 artProfileOutput = profileOutput
377 }
378
379 return d8Flags, d8Deps, artProfileOutput
Colin Crossffb657e2018-09-21 12:29:22 -0700380}
381
Jared Duke91d0bee2024-11-14 23:10:09 +0000382func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams, debugMode bool) (r8Flags []string, r8Deps android.Paths, artProfileOutput *android.OutputPath) {
Spandan Das3dbda182024-05-20 22:23:10 +0000383 flags := dexParams.flags
Liz Kammera7a64f32020-07-09 15:16:41 -0700384 opt := d.dexProperties.Optimize
Colin Cross66dbc0b2017-12-28 12:23:20 -0800385
386 // When an app contains references to APIs that are not in the SDK specified by
387 // its LOCAL_SDK_VERSION for example added by support library or by runtime
Colin Crossbafb8972018-06-06 21:46:32 +0000388 // classes added by desugaring, we artifically raise the "SDK version" "linked" by
Colin Cross66dbc0b2017-12-28 12:23:20 -0800389 // ProGuard, to
390 // - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
391 // - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
392 // See b/20667396
Jared Duke22468442024-08-20 20:45:35 +0000393 // TODO(b/360905238): Remove SdkSystemServer exception after resolving missing class references.
394 if !dexParams.sdkVersion.Stable() || dexParams.sdkVersion.Kind == android.SdkSystemServer {
395 var proguardRaiseDeps classpath
Yu Liuc41eae52025-01-14 01:03:08 +0000396 ctx.VisitDirectDepsProxyWithTag(proguardRaiseTag, func(m android.ModuleProxy) {
Jared Duke22468442024-08-20 20:45:35 +0000397 if dep, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider); ok {
398 proguardRaiseDeps = append(proguardRaiseDeps, dep.RepackagedHeaderJars...)
399 }
400 })
401 r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars"))
402 r8Deps = append(r8Deps, proguardRaiseDeps...)
403 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800404
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500405 r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars"))
Colin Cross6dab9bd2018-09-28 08:06:24 -0700406 r8Deps = append(r8Deps, flags.bootClasspath...)
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500407 r8Flags = append(r8Flags, flags.dexClasspath.FormJavaClassPath("-libraryjars"))
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700408 r8Deps = append(r8Deps, flags.dexClasspath...)
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500409
410 transitiveStaticLibsLookupMap := map[android.Path]bool{}
Colin Crossa14fb6a2024-10-23 16:57:06 -0700411 for _, jar := range d.transitiveStaticLibsHeaderJarsForR8.ToList() {
412 transitiveStaticLibsLookupMap[jar] = true
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500413 }
414 transitiveHeaderJars := android.Paths{}
Colin Crossa14fb6a2024-10-23 16:57:06 -0700415 for _, jar := range d.transitiveLibsHeaderJarsForR8.ToList() {
416 if _, ok := transitiveStaticLibsLookupMap[jar]; ok {
417 // don't include a lib if it is already packaged in the current JAR as a static lib
418 continue
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500419 }
Colin Crossa14fb6a2024-10-23 16:57:06 -0700420 transitiveHeaderJars = append(transitiveHeaderJars, jar)
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500421 }
422 transitiveClasspath := classpath(transitiveHeaderJars)
423 r8Flags = append(r8Flags, transitiveClasspath.FormJavaClassPath("-libraryjars"))
424 r8Deps = append(r8Deps, transitiveClasspath...)
Colin Cross6dab9bd2018-09-28 08:06:24 -0700425
Colin Cross66dbc0b2017-12-28 12:23:20 -0800426 flagFiles := android.Paths{
427 android.PathForSource(ctx, "build/make/core/proguard.flags"),
428 }
429
Colin Cross312634e2023-11-21 15:13:56 -0800430 flagFiles = append(flagFiles, d.extraProguardFlagsFiles...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800431 // TODO(ccross): static android library proguard files
432
Liz Kammera7a64f32020-07-09 15:16:41 -0700433 flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...)
Colin Crossbd1cef52018-08-13 10:28:18 -0700434
Sam Delmericoc8e040c2023-10-31 17:27:02 +0000435 flagFiles = android.FirstUniquePaths(flagFiles)
436
Colin Cross66dbc0b2017-12-28 12:23:20 -0800437 r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include "))
438 r8Deps = append(r8Deps, flagFiles...)
439
440 // TODO(b/70942988): This is included from build/make/core/proguard.flags
441 r8Deps = append(r8Deps, android.PathForSource(ctx,
442 "build/make/core/proguard_basic_keeps.flags"))
443
Liz Kammera7a64f32020-07-09 15:16:41 -0700444 r8Flags = append(r8Flags, opt.Proguard_flags...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800445
Christoffer Adamsenc8fd1f12025-01-06 19:04:03 +0100446 if BoolDefault(opt.Ignore_library_extends_program, false) {
447 r8Flags = append(r8Flags, "--ignore-library-extends-program")
448 }
449
Christoffer Adamsen8ec5f612025-01-09 11:05:11 +0100450 if BoolDefault(opt.Keep_runtime_invisible_annotations, false) {
451 r8Flags = append(r8Flags, "--keep-runtime-invisible-annotations")
452 }
453
Christoffer Adamsenf4f4aa62025-01-14 09:15:11 +0100454 if BoolDefault(opt.Proguard_compatibility, !ctx.Config().UseR8FullModeByDefault()) {
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +0200455 r8Flags = append(r8Flags, "--force-proguard-compatibility")
Jared Dukeb832fbb2023-09-15 17:16:36 +0000456 }
457
Jared Duke91d0bee2024-11-14 23:10:09 +0000458 // Avoid unnecessary stack frame noise by only injecting source map ids for non-debug
459 // optimized or obfuscated targets.
460 if (Bool(opt.Optimize) || Bool(opt.Obfuscate)) && !debugMode {
Ian Zernyfc7df612021-11-02 15:37:06 +0100461 // TODO(b/213833843): Allow configuration of the prefix via a build variable.
462 var sourceFilePrefix = "go/retraceme "
463 var sourceFileTemplate = "\"" + sourceFilePrefix + "%MAP_ID\""
Jared Dukeb832fbb2023-09-15 17:16:36 +0000464 r8Flags = append(r8Flags, "--map-id-template", "%MAP_HASH")
465 r8Flags = append(r8Flags, "--source-file-template", sourceFileTemplate)
Christoffer Quist Adamsenf2d7b162020-08-24 15:56:16 +0200466 }
467
Colin Cross66dbc0b2017-12-28 12:23:20 -0800468 // TODO(ccross): Don't shrink app instrumentation tests by default.
469 if !Bool(opt.Shrink) {
470 r8Flags = append(r8Flags, "-dontshrink")
471 }
472
473 if !Bool(opt.Optimize) {
474 r8Flags = append(r8Flags, "-dontoptimize")
475 }
476
477 // TODO(ccross): error if obufscation + app instrumentation test.
478 if !Bool(opt.Obfuscate) {
479 r8Flags = append(r8Flags, "-dontobfuscate")
480 }
Colin Cross4b964c02018-10-15 16:18:06 -0700481 // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the
482 // dictionary of the app and move the app from libraryjars to injars.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800483
Christoffer Quist Adamsene8507372021-02-22 09:44:09 +0100484 // TODO(b/180878971): missing classes should be added to the relevant builds.
Ajinkya Chalkeddad41b2023-02-09 14:09:58 +0000485 // TODO(b/229727645): do not use true as default for Android platform builds.
486 if proptools.BoolDefault(opt.Ignore_warnings, true) {
Remi NGUYEN VANbdad3142022-08-04 13:19:03 +0900487 r8Flags = append(r8Flags, "-ignorewarnings")
488 }
Christoffer Quist Adamsene8507372021-02-22 09:44:09 +0100489
Rico Winda2fa2632024-03-13 13:09:17 +0100490 // resourcesInput is empty when we don't use resource shrinking, if on, pass these to R8
Rico Wind98e7fa82023-11-27 09:44:03 +0100491 if d.resourcesInput.Valid() {
492 r8Flags = append(r8Flags, "--resource-input", d.resourcesInput.Path().String())
493 r8Deps = append(r8Deps, d.resourcesInput.Path())
494 r8Flags = append(r8Flags, "--resource-output", d.resourcesOutput.Path().String())
Rico Winda7b38592024-08-26 12:10:44 +0200495 if d.dexProperties.optimizedResourceShrinkingEnabled(ctx) {
Rico Winda2fa2632024-03-13 13:09:17 +0100496 r8Flags = append(r8Flags, "--optimized-resource-shrinking")
Rico Wind619ed5c2024-10-22 14:00:23 +0200497 if Bool(d.dexProperties.Optimize.Optimized_shrink_resources) {
498 // Explicitly opted into optimized shrinking, no need for keeping R$id entries
499 r8Flags = append(r8Flags, "--force-optimized-resource-shrinking")
500 }
Rico Winda2fa2632024-03-13 13:09:17 +0100501 }
Rico Wind98e7fa82023-11-27 09:44:03 +0100502 }
503
Spandan Das3dbda182024-05-20 22:23:10 +0000504 if flags, deps, profileOutput := d.addArtProfile(ctx, dexParams); profileOutput != nil {
505 r8Flags = append(r8Flags, flags...)
506 r8Deps = append(r8Deps, deps...)
507 artProfileOutput = profileOutput
508 }
509
Christoffer Adamsenb81fc912024-12-17 14:30:47 +0100510 if ctx.Config().UseR8StoreStoreFenceConstructorInlining() {
511 r8Flags = append(r8Flags, "--store-store-fence-constructor-inlining")
512 }
513
Spandan Das3dbda182024-05-20 22:23:10 +0000514 return r8Flags, r8Deps, artProfileOutput
Colin Cross66dbc0b2017-12-28 12:23:20 -0800515}
516
Spandan Dasc404cc72023-02-23 18:05:05 +0000517type compileDexParams struct {
Spandan Das3dbda182024-05-20 22:23:10 +0000518 flags javaBuilderFlags
519 sdkVersion android.SdkSpec
520 minSdkVersion android.ApiLevel
521 classesJar android.Path
522 jarName string
523 artProfileInput *string
Spandan Dasc404cc72023-02-23 18:05:05 +0000524}
525
Spandan Das3dbda182024-05-20 22:23:10 +0000526// Adds --art-profile to r8/d8 command.
527// r8/d8 will output a generated profile file to match the optimized dex code.
528func (d *dexer) addArtProfile(ctx android.ModuleContext, dexParams *compileDexParams) (flags []string, deps android.Paths, artProfileOutputPath *android.OutputPath) {
Cole Faust4e9f5922024-11-13 16:09:23 -0800529 if dexParams.artProfileInput == nil {
530 return nil, nil, nil
Spandan Das3dbda182024-05-20 22:23:10 +0000531 }
Cole Faust4e9f5922024-11-13 16:09:23 -0800532 artProfileInputPath := android.PathForModuleSrc(ctx, *dexParams.artProfileInput)
533 artProfileOutputPathValue := android.PathForModuleOut(ctx, "profile.prof.txt").OutputPath
534 artProfileOutputPath = &artProfileOutputPathValue
535 flags = []string{
536 "--art-profile",
537 artProfileInputPath.String(),
538 artProfileOutputPath.String(),
539 }
540 deps = append(deps, artProfileInputPath)
Spandan Das3dbda182024-05-20 22:23:10 +0000541 return flags, deps, artProfileOutputPath
542
543}
544
545// Return the compiled dex jar and (optional) profile _after_ r8 optimization
Colin Cross7707b242024-07-26 12:02:36 -0700546func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParams) (android.Path, android.Path) {
Colin Crossf0056cb2017-12-22 15:56:08 -0800547
Colin Crossf0056cb2017-12-22 15:56:08 -0800548 // Compile classes.jar into classes.dex and then javalib.jar
Spandan Dasc404cc72023-02-23 18:05:05 +0000549 javalibJar := android.PathForModuleOut(ctx, "dex", dexParams.jarName).OutputPath
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800550 cleanPhonyPath := android.PathForModuleOut(ctx, "dex", dexParams.jarName+"-partialcompileclean").OutputPath
Colin Crossf0056cb2017-12-22 15:56:08 -0800551 outDir := android.PathForModuleOut(ctx, "dex")
552
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800553 zipFlags := "--ignore_missing_files"
Liz Kammera7a64f32020-07-09 15:16:41 -0700554 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Sasha Smundakd3cf4ee2019-02-15 10:14:23 -0800555 zipFlags += " -L 0"
Colin Cross5a0dcd52018-10-05 14:20:06 -0700556 }
557
Spandan Dasc404cc72023-02-23 18:05:05 +0000558 commonFlags, commonDeps := d.dexCommonFlags(ctx, dexParams)
Liz Kammera7a64f32020-07-09 15:16:41 -0700559
Wei Li1e73c652021-12-06 13:35:11 -0800560 // Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true.
561 mergeZipsFlags := ""
562 if proptools.BoolDefault(d.dexProperties.Exclude_kotlinc_generated_files, false) {
563 mergeZipsFlags = "-stripFile META-INF/*.kotlin_module -stripFile **/*.kotlin_builtins"
564 }
565
Liz Kammera7a64f32020-07-09 15:16:41 -0700566 useR8 := d.effectiveOptimizeEnabled()
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800567 useD8 := !useR8 || ctx.Config().PartialCompileFlags().Use_d8
568 rbeR8 := ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8")
569 rbeD8 := ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8")
570 var rule blueprint.Rule
571 var description string
Spandan Das3dbda182024-05-20 22:23:10 +0000572 var artProfileOutputPath *android.OutputPath
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800573 var implicitOutputs android.WritablePaths
574 var flags []string
575 var deps android.Paths
576 args := map[string]string{
577 "zipFlags": zipFlags,
578 "outDir": outDir.String(),
579 "mergeZipsFlags": mergeZipsFlags,
580 }
Colin Cross66dbc0b2017-12-28 12:23:20 -0800581 if useR8 {
Colin Crossc0c664c2018-05-16 16:47:21 -0700582 proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
Liz Kammera7a64f32020-07-09 15:16:41 -0700583 d.proguardDictionary = android.OptionalPathForPath(proguardDictionary)
Ian Zerny82044f12023-01-25 12:11:27 +0100584 proguardConfiguration := android.PathForModuleOut(ctx, "proguard_configuration")
585 d.proguardConfiguration = android.OptionalPathForPath(proguardConfiguration)
Colin Crosscb6143a2020-08-14 17:39:29 -0700586 proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage")
587 proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path,
588 android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
589 proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
590 d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
Rico Wind98e7fa82023-11-27 09:44:03 +0100591 resourcesOutput := android.PathForModuleOut(ctx, "package-res-shrunken.apk")
592 d.resourcesOutput = android.OptionalPathForPath(resourcesOutput)
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800593 implicitOutputs = append(implicitOutputs, android.WritablePaths{
Spandan Das3dbda182024-05-20 22:23:10 +0000594 proguardDictionary,
595 proguardUsageZip,
596 proguardConfiguration,
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800597 }...)
598 description = "r8"
Jared Duke91d0bee2024-11-14 23:10:09 +0000599 debugMode := android.InList("--debug", commonFlags)
600 r8Flags, r8Deps, r8ArtProfileOutputPath := d.r8Flags(ctx, dexParams, debugMode)
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800601 flags = append(flags, r8Flags...)
602 deps = append(deps, r8Deps...)
603 args["r8Flags"] = strings.Join(append(commonFlags, r8Flags...), " ")
Spandan Dasd447bbb2024-06-24 17:13:30 +0000604 if r8ArtProfileOutputPath != nil {
605 artProfileOutputPath = r8ArtProfileOutputPath
606 implicitOutputs = append(
607 implicitOutputs,
608 artProfileOutputPath,
609 )
610 // Add the implicit r8 Art profile output to args so that r8RE knows
611 // about this implicit output
612 args["outR8ArtProfile"] = artProfileOutputPath.String()
613 }
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800614 args["outDict"] = proguardDictionary.String()
615 args["outConfig"] = proguardConfiguration.String()
616 args["outUsageDir"] = proguardUsageDir.String()
617 args["outUsage"] = proguardUsage.String()
618 args["outUsageZip"] = proguardUsageZip.String()
Rico Wind98e7fa82023-11-27 09:44:03 +0100619 if d.resourcesInput.Valid() {
620 implicitOutputs = append(implicitOutputs, resourcesOutput)
621 args["resourcesOutput"] = resourcesOutput.String()
622 }
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800623
624 rule = r8
625 if rbeR8 {
626 rule = r8RE
627 args["implicits"] = strings.Join(deps.Strings(), ",")
628 }
629 }
630 if useD8 {
631 description = "d8"
Spandan Das3dbda182024-05-20 22:23:10 +0000632 d8Flags, d8Deps, d8ArtProfileOutputPath := d.d8Flags(ctx, dexParams)
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800633 flags = append(flags, d8Flags...)
634 deps = append(deps, d8Deps...)
635 deps = append(deps, commonDeps...)
636 args["d8Flags"] = strings.Join(append(commonFlags, d8Flags...), " ")
Spandan Das3dbda182024-05-20 22:23:10 +0000637 if d8ArtProfileOutputPath != nil {
638 artProfileOutputPath = d8ArtProfileOutputPath
639 implicitOutputs = append(
640 implicitOutputs,
641 artProfileOutputPath,
642 )
643 }
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800644 // If we are generating both d8 and r8, only use RBE when both are enabled.
645 switch {
646 case useR8 && rule == r8:
647 rule = d8r8
648 description = "d8r8"
649 case useR8 && rule == r8RE && rbeD8:
650 rule = d8r8RE
651 description = "d8r8"
652 case rbeD8:
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400653 rule = d8RE
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800654 default:
655 rule = d8
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400656 }
Colin Crossf0056cb2017-12-22 15:56:08 -0800657 }
LaMont Jonesed6f2b22025-02-10 16:24:40 -0800658 ctx.Build(pctx, android.BuildParams{
659 Rule: rule,
660 Description: description,
661 Output: javalibJar,
662 ImplicitOutputs: implicitOutputs,
663 Input: dexParams.classesJar,
664 Implicits: deps,
665 Args: args,
666 })
667 if useR8 && useD8 {
668 // Generate the rule for partial compile clean.
669 args["builtOut"] = javalibJar.String()
670 ctx.Build(pctx, android.BuildParams{
671 Rule: d8r8Clean,
672 Description: "d8r8Clean",
673 Output: cleanPhonyPath,
674 Args: args,
675 PhonyOutput: true,
676 })
677 ctx.Phony("partialcompileclean", cleanPhonyPath)
678 }
679
Liz Kammera7a64f32020-07-09 15:16:41 -0700680 if proptools.Bool(d.dexProperties.Uncompress_dex) {
Spandan Dasc404cc72023-02-23 18:05:05 +0000681 alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", dexParams.jarName).OutputPath
Cole Faust51d7bfd2023-09-07 05:31:32 +0000682 TransformZipAlign(ctx, alignedJavalibJar, javalibJar, nil)
Nicolas Geoffray65fd8ba2019-01-21 23:20:23 +0000683 javalibJar = alignedJavalibJar
684 }
Colin Crossf0056cb2017-12-22 15:56:08 -0800685
Spandan Das3dbda182024-05-20 22:23:10 +0000686 return javalibJar, artProfileOutputPath
Colin Crossf0056cb2017-12-22 15:56:08 -0800687}