| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 18 | "strconv" | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 19 | "strings" | 
|  | 20 |  | 
|  | 21 | "github.com/google/blueprint" | 
| David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 23 |  | 
|  | 24 | "android/soong/android" | 
| Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 25 | "android/soong/remoteexec" | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 26 | ) | 
|  | 27 |  | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 28 | type 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 Cross | 5ea963e | 2021-09-16 19:13:43 -0700 | [diff] [blame] | 35 | // 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 Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 38 | Optimize struct { | 
| Jared Duke | 63a3da9 | 2022-06-02 19:11:14 +0000 | [diff] [blame] | 39 | // 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 Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 41 | Enabled *bool | 
|  | 42 | // True if the module containing this has it set by default. | 
|  | 43 | EnabledByDefault bool `blueprint:"mutated"` | 
|  | 44 |  | 
| Ajinkya Chalke | ddad41b | 2023-02-09 14:09:58 +0000 | [diff] [blame] | 45 | // Whether to continue building even if warnings are emitted.  Defaults to true. | 
| Remi NGUYEN VAN | bdad314 | 2022-08-04 13:19:03 +0900 | [diff] [blame] | 46 | Ignore_warnings *bool | 
|  | 47 |  | 
| Jared Duke | aa88b3d | 2023-08-29 17:07:20 +0000 | [diff] [blame] | 48 | // If true, runs R8 in Proguard compatibility mode, otherwise runs R8 in full mode. | 
|  | 49 | // Defaults to false for apps, true for libraries and tests. | 
| Christoffer Quist Adamsen | f2d7b16 | 2020-08-24 15:56:16 +0200 | [diff] [blame] | 50 | Proguard_compatibility *bool | 
|  | 51 |  | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 52 | // If true, optimize for size by removing unused code.  Defaults to true for apps, | 
|  | 53 | // false for libraries and tests. | 
|  | 54 | Shrink *bool | 
|  | 55 |  | 
|  | 56 | // If true, optimize bytecode.  Defaults to false. | 
|  | 57 | Optimize *bool | 
|  | 58 |  | 
|  | 59 | // If true, obfuscate bytecode.  Defaults to false. | 
|  | 60 | Obfuscate *bool | 
|  | 61 |  | 
|  | 62 | // If true, do not use the flag files generated by aapt that automatically keep | 
|  | 63 | // classes referenced by the app manifest.  Defaults to false. | 
|  | 64 | No_aapt_flags *bool | 
|  | 65 |  | 
| Jared Duke | 51b0a10 | 2022-09-27 16:53:11 -0700 | [diff] [blame] | 66 | // If true, optimize for size by removing unused resources. Defaults to false. | 
| Rico Wind | 351bac9 | 2022-09-22 10:41:42 +0200 | [diff] [blame] | 67 | Shrink_resources *bool | 
|  | 68 |  | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 69 | // If true, use optimized resource shrinking in R8, overriding the | 
|  | 70 | // Shrink_resources setting. Defaults to false. | 
|  | 71 | // Optimized shrinking means that R8 will trace and treeshake resources together with code | 
|  | 72 | // and apply additional optimizations. This implies non final fields in the R classes. | 
|  | 73 | Optimized_shrink_resources *bool | 
|  | 74 |  | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 75 | // Flags to pass to proguard. | 
|  | 76 | Proguard_flags []string | 
|  | 77 |  | 
|  | 78 | // Specifies the locations of files containing proguard flags. | 
|  | 79 | Proguard_flags_files []string `android:"path"` | 
| Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 80 |  | 
|  | 81 | // If true, transitive reverse dependencies of this module will have this | 
|  | 82 | // module's proguard spec appended to their optimization action | 
|  | 83 | Export_proguard_flags_files *bool | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
|  | 86 | // Keep the data uncompressed. We always need uncompressed dex for execution, | 
|  | 87 | // so this might actually save space by avoiding storing the same data twice. | 
|  | 88 | // This defaults to reasonable value based on module and should not be set. | 
|  | 89 | // It exists only to support ART tests. | 
|  | 90 | Uncompress_dex *bool | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 91 |  | 
| Wei Li | 92cd54b | 2022-01-12 13:22:55 -0800 | [diff] [blame] | 92 | // Exclude kotlinc generate files: *.kotlin_module, *.kotlin_builtins. Defaults to false. | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 93 | Exclude_kotlinc_generated_files *bool | 
| Ulya Trafimovich | c816058 | 2024-07-10 08:32:45 +0100 | [diff] [blame] | 94 |  | 
|  | 95 | // Disable dex container (also known as "multi-dex"). | 
|  | 96 | // This may be necessary as a temporary workaround to mask toolchain bugs (see b/341652226). | 
|  | 97 | No_dex_container *bool | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
|  | 100 | type dexer struct { | 
|  | 101 | dexProperties DexProperties | 
|  | 102 |  | 
|  | 103 | // list of extra proguard flag files | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 104 | extraProguardFlagsFiles android.Paths | 
|  | 105 | proguardDictionary      android.OptionalPath | 
|  | 106 | proguardConfiguration   android.OptionalPath | 
|  | 107 | proguardUsageZip        android.OptionalPath | 
|  | 108 | resourcesInput          android.OptionalPath | 
|  | 109 | resourcesOutput         android.OptionalPath | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 110 |  | 
| Colin Cross | 9ffaf28 | 2024-08-12 13:50:09 -0700 | [diff] [blame] | 111 | providesTransitiveHeaderJarsForR8 | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 112 | } | 
|  | 113 |  | 
|  | 114 | func (d *dexer) effectiveOptimizeEnabled() bool { | 
|  | 115 | return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault) | 
|  | 116 | } | 
|  | 117 |  | 
| Rico Wind | 936754c | 2024-05-07 09:08:31 +0200 | [diff] [blame] | 118 | func (d *DexProperties) resourceShrinkingEnabled(ctx android.ModuleContext) bool { | 
|  | 119 | return !ctx.Config().Eng() && BoolDefault(d.Optimize.Optimized_shrink_resources, Bool(d.Optimize.Shrink_resources)) | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | func (d *DexProperties) optimizedResourceShrinkingEnabled(ctx android.ModuleContext) bool { | 
| Rico Wind | a7b3859 | 2024-08-26 12:10:44 +0200 | [diff] [blame] | 123 | return d.resourceShrinkingEnabled(ctx) && BoolDefault(d.Optimize.Optimized_shrink_resources, ctx.Config().UseOptimizedResourceShrinkingByDefault()) | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
| Spandan Das | 15a6711 | 2024-05-30 00:07:40 +0000 | [diff] [blame] | 126 | func (d *dexer) optimizeOrObfuscateEnabled() bool { | 
|  | 127 | return d.effectiveOptimizeEnabled() && (proptools.Bool(d.dexProperties.Optimize.Optimize) || proptools.Bool(d.dexProperties.Optimize.Obfuscate)) | 
|  | 128 | } | 
|  | 129 |  | 
| Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 130 | var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 131 | blueprint.RuleParams{ | 
|  | 132 | Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + | 
| David Srbecky | bda964c | 2023-11-24 15:57:54 +0000 | [diff] [blame] | 133 | `$d8Template${config.D8Cmd} ${config.D8Flags} $d8Flags --output $outDir --no-dex-input-jar $in && ` + | 
| Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 134 | `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` + | 
| Colin Cross | 56e2840 | 2023-09-28 14:38:06 -0700 | [diff] [blame] | 135 | `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` + | 
| Ian Zerny | db2d35b | 2023-10-10 12:22:39 +0200 | [diff] [blame] | 136 | `rm -f "$outDir/classes*.dex" "$outDir/classes.dex.jar"`, | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 137 | CommandDeps: []string{ | 
|  | 138 | "${config.D8Cmd}", | 
|  | 139 | "${config.SoongZipCmd}", | 
|  | 140 | "${config.MergeZipsCmd}", | 
|  | 141 | }, | 
| Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 142 | }, map[string]*remoteexec.REParams{ | 
|  | 143 | "$d8Template": &remoteexec.REParams{ | 
|  | 144 | Labels:          map[string]string{"type": "compile", "compiler": "d8"}, | 
|  | 145 | Inputs:          []string{"${config.D8Jar}"}, | 
|  | 146 | ExecStrategy:    "${config.RED8ExecStrategy}", | 
|  | 147 | ToolchainInputs: []string{"${config.JavaCmd}"}, | 
|  | 148 | Platform:        map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, | 
|  | 149 | }, | 
|  | 150 | "$zipTemplate": &remoteexec.REParams{ | 
|  | 151 | Labels:       map[string]string{"type": "tool", "name": "soong_zip"}, | 
|  | 152 | Inputs:       []string{"${config.SoongZipCmd}", "$outDir"}, | 
|  | 153 | OutputFiles:  []string{"$outDir/classes.dex.jar"}, | 
|  | 154 | ExecStrategy: "${config.RED8ExecStrategy}", | 
|  | 155 | Platform:     map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, | 
|  | 156 | }, | 
| Ian Zerny | db2d35b | 2023-10-10 12:22:39 +0200 | [diff] [blame] | 157 | }, []string{"outDir", "d8Flags", "zipFlags", "mergeZipsFlags"}, nil) | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 158 |  | 
| Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 159 | var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 160 | blueprint.RuleParams{ | 
|  | 161 | Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + | 
| Ian Zerny | 82044f1 | 2023-01-25 12:11:27 +0100 | [diff] [blame] | 162 | `rm -f "$outDict" && rm -f "$outConfig" && rm -rf "${outUsageDir}" && ` + | 
| Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 163 | `mkdir -p $$(dirname ${outUsage}) && ` + | 
| David Srbecky | bda964c | 2023-11-24 15:57:54 +0000 | [diff] [blame] | 164 | `$r8Template${config.R8Cmd} ${config.R8Flags} $r8Flags -injars $in --output $outDir ` + | 
| Søren Gjesse | 24f1702 | 2018-09-14 15:20:42 +0200 | [diff] [blame] | 165 | `--no-data-resources ` + | 
| Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 166 | `-printmapping ${outDict} ` + | 
| Jared Duke | 34c6d7d | 2023-05-05 20:40:20 +0000 | [diff] [blame] | 167 | `-printconfiguration ${outConfig} ` + | 
| Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 168 | `-printusage ${outUsage} ` + | 
| David Srbecky | bda964c | 2023-11-24 15:57:54 +0000 | [diff] [blame] | 169 | `--deps-file ${out}.d && ` + | 
| Ian Zerny | 82044f1 | 2023-01-25 12:11:27 +0100 | [diff] [blame] | 170 | `touch "${outDict}" "${outConfig}" "${outUsage}" && ` + | 
| Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 171 | `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` + | 
|  | 172 | `rm -rf ${outUsageDir} && ` + | 
| Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 173 | `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` + | 
| Colin Cross | 56e2840 | 2023-09-28 14:38:06 -0700 | [diff] [blame] | 174 | `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` + | 
| Colin Cross | b716ceb | 2023-10-03 09:40:06 -0700 | [diff] [blame] | 175 | `rm -f "$outDir/classes*.dex" "$outDir/classes.dex.jar"`, | 
| Colin Cross | 22e6a6f | 2022-03-21 12:19:44 -0700 | [diff] [blame] | 176 | Depfile: "${out}.d", | 
|  | 177 | Deps:    blueprint.DepsGCC, | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 178 | CommandDeps: []string{ | 
| Colin Cross | a832a04 | 2021-08-05 16:56:18 -0700 | [diff] [blame] | 179 | "${config.R8Cmd}", | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 180 | "${config.SoongZipCmd}", | 
|  | 181 | "${config.MergeZipsCmd}", | 
|  | 182 | }, | 
| Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 183 | }, map[string]*remoteexec.REParams{ | 
|  | 184 | "$r8Template": &remoteexec.REParams{ | 
|  | 185 | Labels:          map[string]string{"type": "compile", "compiler": "r8"}, | 
|  | 186 | Inputs:          []string{"$implicits", "${config.R8Jar}"}, | 
| Spandan Das | d447bbb | 2024-06-24 17:13:30 +0000 | [diff] [blame] | 187 | OutputFiles:     []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}", "${outR8ArtProfile}"}, | 
| Kousik Kumar | 366afc5 | 2020-05-20 11:27:16 -0700 | [diff] [blame] | 188 | ExecStrategy:    "${config.RER8ExecStrategy}", | 
|  | 189 | ToolchainInputs: []string{"${config.JavaCmd}"}, | 
|  | 190 | Platform:        map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, | 
|  | 191 | }, | 
|  | 192 | "$zipTemplate": &remoteexec.REParams{ | 
|  | 193 | Labels:       map[string]string{"type": "tool", "name": "soong_zip"}, | 
|  | 194 | Inputs:       []string{"${config.SoongZipCmd}", "$outDir"}, | 
|  | 195 | OutputFiles:  []string{"$outDir/classes.dex.jar"}, | 
|  | 196 | ExecStrategy: "${config.RER8ExecStrategy}", | 
|  | 197 | Platform:     map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, | 
|  | 198 | }, | 
| Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 199 | "$zipUsageTemplate": &remoteexec.REParams{ | 
|  | 200 | Labels:       map[string]string{"type": "tool", "name": "soong_zip"}, | 
|  | 201 | Inputs:       []string{"${config.SoongZipCmd}", "${outUsage}"}, | 
|  | 202 | OutputFiles:  []string{"${outUsageZip}"}, | 
|  | 203 | ExecStrategy: "${config.RER8ExecStrategy}", | 
|  | 204 | Platform:     map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, | 
|  | 205 | }, | 
| Ian Zerny | 82044f1 | 2023-01-25 12:11:27 +0100 | [diff] [blame] | 206 | }, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir", | 
| Spandan Das | d447bbb | 2024-06-24 17:13:30 +0000 | [diff] [blame] | 207 | "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput", "outR8ArtProfile"}, []string{"implicits"}) | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 208 |  | 
| Colin Cross | 5ea963e | 2021-09-16 19:13:43 -0700 | [diff] [blame] | 209 | func (d *dexer) dexCommonFlags(ctx android.ModuleContext, | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 210 | dexParams *compileDexParams) (flags []string, deps android.Paths) { | 
| Colin Cross | 5ea963e | 2021-09-16 19:13:43 -0700 | [diff] [blame] | 211 |  | 
|  | 212 | flags = d.dexProperties.Dxflags | 
| Colin Cross | bafb897 | 2018-06-06 21:46:32 +0000 | [diff] [blame] | 213 | // Translate all the DX flags to D8 ones until all the build files have been migrated | 
|  | 214 | // to D8 flags. See: b/69377755 | 
|  | 215 | flags = android.RemoveListFromList(flags, | 
|  | 216 | []string{"--core-library", "--dex", "--multi-dex"}) | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 217 |  | 
| Colin Cross | 5ea963e | 2021-09-16 19:13:43 -0700 | [diff] [blame] | 218 | for _, f := range android.PathsForModuleSrc(ctx, d.dexProperties.Main_dex_rules) { | 
|  | 219 | flags = append(flags, "--main-dex-rules", f.String()) | 
|  | 220 | deps = append(deps, f) | 
|  | 221 | } | 
|  | 222 |  | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 223 | if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" { | 
| Colin Cross | bafb897 | 2018-06-06 21:46:32 +0000 | [diff] [blame] | 224 | flags = append(flags, "--debug") | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 225 | } | 
|  | 226 |  | 
|  | 227 | if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" { | 
|  | 228 | flags = append(flags, | 
|  | 229 | "--debug", | 
|  | 230 | "--verbose") | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 231 | } | 
|  | 232 |  | 
| Jared Duke | 40d731a | 2022-09-20 15:32:14 -0700 | [diff] [blame] | 233 | // Supplying the platform build flag disables various features like API modeling and desugaring. | 
|  | 234 | // For targets with a stable min SDK version (i.e., when the min SDK is both explicitly specified | 
|  | 235 | // and managed+versioned), we suppress this flag to ensure portability. | 
|  | 236 | // Note: Targets with a min SDK kind of core_platform (e.g., framework.jar) or unspecified (e.g., | 
|  | 237 | // services.jar), are not classified as stable, which is WAI. | 
|  | 238 | // TODO(b/232073181): Expand to additional min SDK cases after validation. | 
| Ian Zerny | c26029b | 2023-08-25 13:43:44 +0200 | [diff] [blame] | 239 | var addAndroidPlatformBuildFlag = false | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 240 | if !dexParams.sdkVersion.Stable() { | 
| Ian Zerny | c26029b | 2023-08-25 13:43:44 +0200 | [diff] [blame] | 241 | addAndroidPlatformBuildFlag = true | 
| Jared Duke | 40d731a | 2022-09-20 15:32:14 -0700 | [diff] [blame] | 242 | } | 
|  | 243 |  | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 244 | effectiveVersion, err := dexParams.minSdkVersion.EffectiveVersion(ctx) | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 245 | if err != nil { | 
|  | 246 | ctx.PropertyErrorf("min_sdk_version", "%s", err) | 
|  | 247 | } | 
| Ulya Trofimovich | 5bb4681 | 2024-08-07 19:25:58 +0000 | [diff] [blame] | 248 | if !Bool(d.dexProperties.No_dex_container) && effectiveVersion.FinalOrFutureInt() >= 36 { | 
|  | 249 | // W is 36, but we have not bumped the SDK version yet, so check for both. | 
|  | 250 | if ctx.Config().PlatformSdkVersion().FinalInt() >= 36 || | 
|  | 251 | ctx.Config().PlatformSdkCodename() == "Wear" { | 
|  | 252 | // TODO(b/329465418): Skip this module since it causes issue with app DRM | 
|  | 253 | if ctx.ModuleName() != "framework-minus-apex" { | 
|  | 254 | flags = append([]string{"-JDcom.android.tools.r8.dexContainerExperiment"}, flags...) | 
|  | 255 | } | 
|  | 256 | } | 
|  | 257 | } | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 258 |  | 
| Ian Zerny | c26029b | 2023-08-25 13:43:44 +0200 | [diff] [blame] | 259 | // If the specified SDK level is 10000, then configure the compiler to use the | 
|  | 260 | // current platform SDK level and to compile the build as a platform build. | 
|  | 261 | var minApiFlagValue = effectiveVersion.FinalOrFutureInt() | 
|  | 262 | if minApiFlagValue == 10000 { | 
|  | 263 | minApiFlagValue = ctx.Config().PlatformSdkVersion().FinalInt() | 
|  | 264 | addAndroidPlatformBuildFlag = true | 
|  | 265 | } | 
|  | 266 | flags = append(flags, "--min-api "+strconv.Itoa(minApiFlagValue)) | 
|  | 267 |  | 
|  | 268 | if addAndroidPlatformBuildFlag { | 
|  | 269 | flags = append(flags, "--android-platform-build") | 
|  | 270 | } | 
| Colin Cross | 5ea963e | 2021-09-16 19:13:43 -0700 | [diff] [blame] | 271 | return flags, deps | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 272 | } | 
|  | 273 |  | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 274 | func (d *dexer) d8Flags(ctx android.ModuleContext, dexParams *compileDexParams) (d8Flags []string, d8Deps android.Paths, artProfileOutput *android.OutputPath) { | 
|  | 275 | flags := dexParams.flags | 
| Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 276 | d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 277 | d8Flags = append(d8Flags, flags.dexClasspath.FormRepeatedClassPath("--lib ")...) | 
| Colin Cross | ffb657e | 2018-09-21 12:29:22 -0700 | [diff] [blame] | 278 |  | 
| Colin Cross | 6dab9bd | 2018-09-28 08:06:24 -0700 | [diff] [blame] | 279 | d8Deps = append(d8Deps, flags.bootClasspath...) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 280 | d8Deps = append(d8Deps, flags.dexClasspath...) | 
| Colin Cross | 6dab9bd | 2018-09-28 08:06:24 -0700 | [diff] [blame] | 281 |  | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 282 | if flags, deps, profileOutput := d.addArtProfile(ctx, dexParams); profileOutput != nil { | 
|  | 283 | d8Flags = append(d8Flags, flags...) | 
|  | 284 | d8Deps = append(d8Deps, deps...) | 
|  | 285 | artProfileOutput = profileOutput | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | return d8Flags, d8Deps, artProfileOutput | 
| Colin Cross | ffb657e | 2018-09-21 12:29:22 -0700 | [diff] [blame] | 289 | } | 
|  | 290 |  | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 291 | func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams) (r8Flags []string, r8Deps android.Paths, artProfileOutput *android.OutputPath) { | 
|  | 292 | flags := dexParams.flags | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 293 | opt := d.dexProperties.Optimize | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 294 |  | 
|  | 295 | // When an app contains references to APIs that are not in the SDK specified by | 
|  | 296 | // its LOCAL_SDK_VERSION for example added by support library or by runtime | 
| Colin Cross | bafb897 | 2018-06-06 21:46:32 +0000 | [diff] [blame] | 297 | // classes added by desugaring, we artifically raise the "SDK version" "linked" by | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 298 | // ProGuard, to | 
|  | 299 | // - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version. | 
|  | 300 | // - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version. | 
|  | 301 | // See b/20667396 | 
| Jared Duke | 2246844 | 2024-08-20 20:45:35 +0000 | [diff] [blame] | 302 | // TODO(b/360905238): Remove SdkSystemServer exception after resolving missing class references. | 
|  | 303 | if !dexParams.sdkVersion.Stable() || dexParams.sdkVersion.Kind == android.SdkSystemServer { | 
|  | 304 | var proguardRaiseDeps classpath | 
|  | 305 | ctx.VisitDirectDepsWithTag(proguardRaiseTag, func(m android.Module) { | 
|  | 306 | if dep, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider); ok { | 
|  | 307 | proguardRaiseDeps = append(proguardRaiseDeps, dep.RepackagedHeaderJars...) | 
|  | 308 | } | 
|  | 309 | }) | 
|  | 310 | r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars")) | 
|  | 311 | r8Deps = append(r8Deps, proguardRaiseDeps...) | 
|  | 312 | } | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 313 |  | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 314 | r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars")) | 
| Colin Cross | 6dab9bd | 2018-09-28 08:06:24 -0700 | [diff] [blame] | 315 | r8Deps = append(r8Deps, flags.bootClasspath...) | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 316 | r8Flags = append(r8Flags, flags.dexClasspath.FormJavaClassPath("-libraryjars")) | 
| Colin Cross | 9bb9bfb | 2022-03-17 11:12:32 -0700 | [diff] [blame] | 317 | r8Deps = append(r8Deps, flags.dexClasspath...) | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 318 |  | 
|  | 319 | transitiveStaticLibsLookupMap := map[android.Path]bool{} | 
| Colin Cross | 9ffaf28 | 2024-08-12 13:50:09 -0700 | [diff] [blame] | 320 | if d.transitiveStaticLibsHeaderJarsForR8 != nil { | 
|  | 321 | for _, jar := range d.transitiveStaticLibsHeaderJarsForR8.ToList() { | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 322 | transitiveStaticLibsLookupMap[jar] = true | 
|  | 323 | } | 
|  | 324 | } | 
|  | 325 | transitiveHeaderJars := android.Paths{} | 
| Colin Cross | 9ffaf28 | 2024-08-12 13:50:09 -0700 | [diff] [blame] | 326 | if d.transitiveLibsHeaderJarsForR8 != nil { | 
|  | 327 | for _, jar := range d.transitiveLibsHeaderJarsForR8.ToList() { | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 328 | if _, ok := transitiveStaticLibsLookupMap[jar]; ok { | 
|  | 329 | // don't include a lib if it is already packaged in the current JAR as a static lib | 
|  | 330 | continue | 
|  | 331 | } | 
|  | 332 | transitiveHeaderJars = append(transitiveHeaderJars, jar) | 
|  | 333 | } | 
|  | 334 | } | 
|  | 335 | transitiveClasspath := classpath(transitiveHeaderJars) | 
|  | 336 | r8Flags = append(r8Flags, transitiveClasspath.FormJavaClassPath("-libraryjars")) | 
|  | 337 | r8Deps = append(r8Deps, transitiveClasspath...) | 
| Colin Cross | 6dab9bd | 2018-09-28 08:06:24 -0700 | [diff] [blame] | 338 |  | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 339 | flagFiles := android.Paths{ | 
|  | 340 | android.PathForSource(ctx, "build/make/core/proguard.flags"), | 
|  | 341 | } | 
|  | 342 |  | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 343 | flagFiles = append(flagFiles, d.extraProguardFlagsFiles...) | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 344 | // TODO(ccross): static android library proguard files | 
|  | 345 |  | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 346 | flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...) | 
| Colin Cross | bd1cef5 | 2018-08-13 10:28:18 -0700 | [diff] [blame] | 347 |  | 
| Sam Delmerico | c8e040c | 2023-10-31 17:27:02 +0000 | [diff] [blame] | 348 | flagFiles = android.FirstUniquePaths(flagFiles) | 
|  | 349 |  | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 350 | r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include ")) | 
|  | 351 | r8Deps = append(r8Deps, flagFiles...) | 
|  | 352 |  | 
|  | 353 | // TODO(b/70942988): This is included from build/make/core/proguard.flags | 
|  | 354 | r8Deps = append(r8Deps, android.PathForSource(ctx, | 
|  | 355 | "build/make/core/proguard_basic_keeps.flags")) | 
|  | 356 |  | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 357 | r8Flags = append(r8Flags, opt.Proguard_flags...) | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 358 |  | 
| Christoffer Quist Adamsen | f2d7b16 | 2020-08-24 15:56:16 +0200 | [diff] [blame] | 359 | if BoolDefault(opt.Proguard_compatibility, true) { | 
|  | 360 | r8Flags = append(r8Flags, "--force-proguard-compatibility") | 
| Jared Duke | b832fbb | 2023-09-15 17:16:36 +0000 | [diff] [blame] | 361 | } | 
|  | 362 |  | 
|  | 363 | if Bool(opt.Optimize) || Bool(opt.Obfuscate) { | 
| Ian Zerny | fc7df61 | 2021-11-02 15:37:06 +0100 | [diff] [blame] | 364 | // TODO(b/213833843): Allow configuration of the prefix via a build variable. | 
|  | 365 | var sourceFilePrefix = "go/retraceme " | 
|  | 366 | var sourceFileTemplate = "\"" + sourceFilePrefix + "%MAP_ID\"" | 
| Jared Duke | b832fbb | 2023-09-15 17:16:36 +0000 | [diff] [blame] | 367 | r8Flags = append(r8Flags, "--map-id-template", "%MAP_HASH") | 
|  | 368 | r8Flags = append(r8Flags, "--source-file-template", sourceFileTemplate) | 
| Christoffer Quist Adamsen | f2d7b16 | 2020-08-24 15:56:16 +0200 | [diff] [blame] | 369 | } | 
|  | 370 |  | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 371 | // TODO(ccross): Don't shrink app instrumentation tests by default. | 
|  | 372 | if !Bool(opt.Shrink) { | 
|  | 373 | r8Flags = append(r8Flags, "-dontshrink") | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | if !Bool(opt.Optimize) { | 
|  | 377 | r8Flags = append(r8Flags, "-dontoptimize") | 
|  | 378 | } | 
|  | 379 |  | 
|  | 380 | // TODO(ccross): error if obufscation + app instrumentation test. | 
|  | 381 | if !Bool(opt.Obfuscate) { | 
|  | 382 | r8Flags = append(r8Flags, "-dontobfuscate") | 
|  | 383 | } | 
| Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 384 | // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the | 
|  | 385 | // dictionary of the app and move the app from libraryjars to injars. | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 386 |  | 
| Jaewoong Jung | 1d6eb68 | 2018-11-29 15:08:44 -0800 | [diff] [blame] | 387 | // Don't strip out debug information for eng builds. | 
|  | 388 | if ctx.Config().Eng() { | 
|  | 389 | r8Flags = append(r8Flags, "--debug") | 
|  | 390 | } | 
|  | 391 |  | 
| Christoffer Quist Adamsen | e850737 | 2021-02-22 09:44:09 +0100 | [diff] [blame] | 392 | // TODO(b/180878971): missing classes should be added to the relevant builds. | 
| Ajinkya Chalke | ddad41b | 2023-02-09 14:09:58 +0000 | [diff] [blame] | 393 | // TODO(b/229727645): do not use true as default for Android platform builds. | 
|  | 394 | if proptools.BoolDefault(opt.Ignore_warnings, true) { | 
| Remi NGUYEN VAN | bdad314 | 2022-08-04 13:19:03 +0900 | [diff] [blame] | 395 | r8Flags = append(r8Flags, "-ignorewarnings") | 
|  | 396 | } | 
| Christoffer Quist Adamsen | e850737 | 2021-02-22 09:44:09 +0100 | [diff] [blame] | 397 |  | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 398 | // resourcesInput is empty when we don't use resource shrinking, if on, pass these to R8 | 
| Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 399 | if d.resourcesInput.Valid() { | 
|  | 400 | r8Flags = append(r8Flags, "--resource-input", d.resourcesInput.Path().String()) | 
|  | 401 | r8Deps = append(r8Deps, d.resourcesInput.Path()) | 
|  | 402 | r8Flags = append(r8Flags, "--resource-output", d.resourcesOutput.Path().String()) | 
| Rico Wind | a7b3859 | 2024-08-26 12:10:44 +0200 | [diff] [blame] | 403 | if d.dexProperties.optimizedResourceShrinkingEnabled(ctx) { | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 404 | r8Flags = append(r8Flags, "--optimized-resource-shrinking") | 
|  | 405 | } | 
| Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 406 | } | 
|  | 407 |  | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 408 | if flags, deps, profileOutput := d.addArtProfile(ctx, dexParams); profileOutput != nil { | 
|  | 409 | r8Flags = append(r8Flags, flags...) | 
|  | 410 | r8Deps = append(r8Deps, deps...) | 
|  | 411 | artProfileOutput = profileOutput | 
|  | 412 | } | 
|  | 413 |  | 
|  | 414 | return r8Flags, r8Deps, artProfileOutput | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 415 | } | 
|  | 416 |  | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 417 | type compileDexParams struct { | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 418 | flags           javaBuilderFlags | 
|  | 419 | sdkVersion      android.SdkSpec | 
|  | 420 | minSdkVersion   android.ApiLevel | 
|  | 421 | classesJar      android.Path | 
|  | 422 | jarName         string | 
|  | 423 | artProfileInput *string | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 424 | } | 
|  | 425 |  | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 426 | // Adds --art-profile to r8/d8 command. | 
|  | 427 | // r8/d8 will output a generated profile file to match the optimized dex code. | 
|  | 428 | func (d *dexer) addArtProfile(ctx android.ModuleContext, dexParams *compileDexParams) (flags []string, deps android.Paths, artProfileOutputPath *android.OutputPath) { | 
|  | 429 | if dexParams.artProfileInput != nil { | 
|  | 430 | artProfileInputPath := android.PathForModuleSrc(ctx, *dexParams.artProfileInput) | 
|  | 431 | artProfileOutputPathValue := android.PathForModuleOut(ctx, "profile.prof.txt").OutputPath | 
|  | 432 | artProfileOutputPath = &artProfileOutputPathValue | 
|  | 433 | flags = []string{ | 
|  | 434 | "--art-profile", | 
|  | 435 | artProfileInputPath.String(), | 
|  | 436 | artProfileOutputPath.String(), | 
|  | 437 | } | 
|  | 438 | deps = append(deps, artProfileInputPath) | 
|  | 439 | } | 
|  | 440 | return flags, deps, artProfileOutputPath | 
|  | 441 |  | 
|  | 442 | } | 
|  | 443 |  | 
|  | 444 | // Return the compiled dex jar and (optional) profile _after_ r8 optimization | 
| Colin Cross | 7707b24 | 2024-07-26 12:02:36 -0700 | [diff] [blame] | 445 | func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParams) (android.Path, android.Path) { | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 446 |  | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 447 | // Compile classes.jar into classes.dex and then javalib.jar | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 448 | javalibJar := android.PathForModuleOut(ctx, "dex", dexParams.jarName).OutputPath | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 449 | outDir := android.PathForModuleOut(ctx, "dex") | 
|  | 450 |  | 
| Sasha Smundak | d3cf4ee | 2019-02-15 10:14:23 -0800 | [diff] [blame] | 451 | zipFlags := "--ignore_missing_files" | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 452 | if proptools.Bool(d.dexProperties.Uncompress_dex) { | 
| Sasha Smundak | d3cf4ee | 2019-02-15 10:14:23 -0800 | [diff] [blame] | 453 | zipFlags += " -L 0" | 
| Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 454 | } | 
|  | 455 |  | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 456 | commonFlags, commonDeps := d.dexCommonFlags(ctx, dexParams) | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 457 |  | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 458 | // Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true. | 
|  | 459 | mergeZipsFlags := "" | 
|  | 460 | if proptools.BoolDefault(d.dexProperties.Exclude_kotlinc_generated_files, false) { | 
|  | 461 | mergeZipsFlags = "-stripFile META-INF/*.kotlin_module -stripFile **/*.kotlin_builtins" | 
|  | 462 | } | 
|  | 463 |  | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 464 | useR8 := d.effectiveOptimizeEnabled() | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 465 | var artProfileOutputPath *android.OutputPath | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 466 | if useR8 { | 
| Colin Cross | c0c664c | 2018-05-16 16:47:21 -0700 | [diff] [blame] | 467 | proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary") | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 468 | d.proguardDictionary = android.OptionalPathForPath(proguardDictionary) | 
| Ian Zerny | 82044f1 | 2023-01-25 12:11:27 +0100 | [diff] [blame] | 469 | proguardConfiguration := android.PathForModuleOut(ctx, "proguard_configuration") | 
|  | 470 | d.proguardConfiguration = android.OptionalPathForPath(proguardConfiguration) | 
| Colin Cross | cb6143a | 2020-08-14 17:39:29 -0700 | [diff] [blame] | 471 | proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage") | 
|  | 472 | proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path, | 
|  | 473 | android.ModuleNameWithPossibleOverride(ctx), "unused.txt") | 
|  | 474 | proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip") | 
|  | 475 | d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip) | 
| Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 476 | resourcesOutput := android.PathForModuleOut(ctx, "package-res-shrunken.apk") | 
|  | 477 | d.resourcesOutput = android.OptionalPathForPath(resourcesOutput) | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 478 | implicitOutputs := android.WritablePaths{ | 
|  | 479 | proguardDictionary, | 
|  | 480 | proguardUsageZip, | 
|  | 481 | proguardConfiguration, | 
|  | 482 | } | 
|  | 483 | r8Flags, r8Deps, r8ArtProfileOutputPath := d.r8Flags(ctx, dexParams) | 
| Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 484 | rule := r8 | 
|  | 485 | args := map[string]string{ | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 486 | "r8Flags":        strings.Join(append(commonFlags, r8Flags...), " "), | 
|  | 487 | "zipFlags":       zipFlags, | 
|  | 488 | "outDict":        proguardDictionary.String(), | 
| Ian Zerny | 82044f1 | 2023-01-25 12:11:27 +0100 | [diff] [blame] | 489 | "outConfig":      proguardConfiguration.String(), | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 490 | "outUsageDir":    proguardUsageDir.String(), | 
|  | 491 | "outUsage":       proguardUsage.String(), | 
|  | 492 | "outUsageZip":    proguardUsageZip.String(), | 
|  | 493 | "outDir":         outDir.String(), | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 494 | "mergeZipsFlags": mergeZipsFlags, | 
| Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 495 | } | 
| Spandan Das | d447bbb | 2024-06-24 17:13:30 +0000 | [diff] [blame] | 496 | if r8ArtProfileOutputPath != nil { | 
|  | 497 | artProfileOutputPath = r8ArtProfileOutputPath | 
|  | 498 | implicitOutputs = append( | 
|  | 499 | implicitOutputs, | 
|  | 500 | artProfileOutputPath, | 
|  | 501 | ) | 
|  | 502 | // Add the implicit r8 Art profile output to args so that r8RE knows | 
|  | 503 | // about this implicit output | 
|  | 504 | args["outR8ArtProfile"] = artProfileOutputPath.String() | 
|  | 505 | } | 
|  | 506 |  | 
| Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 507 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") { | 
| Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 508 | rule = r8RE | 
|  | 509 | args["implicits"] = strings.Join(r8Deps.Strings(), ",") | 
|  | 510 | } | 
| Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 511 | if d.resourcesInput.Valid() { | 
|  | 512 | implicitOutputs = append(implicitOutputs, resourcesOutput) | 
|  | 513 | args["resourcesOutput"] = resourcesOutput.String() | 
|  | 514 | } | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 515 | ctx.Build(pctx, android.BuildParams{ | 
| Rico Wind | 98e7fa8 | 2023-11-27 09:44:03 +0100 | [diff] [blame] | 516 | Rule:            rule, | 
|  | 517 | Description:     "r8", | 
|  | 518 | Output:          javalibJar, | 
|  | 519 | ImplicitOutputs: implicitOutputs, | 
|  | 520 | Input:           dexParams.classesJar, | 
|  | 521 | Implicits:       r8Deps, | 
|  | 522 | Args:            args, | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 523 | }) | 
|  | 524 | } else { | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 525 | implicitOutputs := android.WritablePaths{} | 
|  | 526 | d8Flags, d8Deps, d8ArtProfileOutputPath := d.d8Flags(ctx, dexParams) | 
|  | 527 | if d8ArtProfileOutputPath != nil { | 
|  | 528 | artProfileOutputPath = d8ArtProfileOutputPath | 
|  | 529 | implicitOutputs = append( | 
|  | 530 | implicitOutputs, | 
|  | 531 | artProfileOutputPath, | 
|  | 532 | ) | 
|  | 533 | } | 
| Colin Cross | 5ea963e | 2021-09-16 19:13:43 -0700 | [diff] [blame] | 534 | d8Deps = append(d8Deps, commonDeps...) | 
| Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 535 | rule := d8 | 
| Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 536 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") { | 
| Ramy Medhat | 1dcc27e | 2020-04-21 21:36:23 -0400 | [diff] [blame] | 537 | rule = d8RE | 
|  | 538 | } | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 539 | ctx.Build(pctx, android.BuildParams{ | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 540 | Rule:            rule, | 
|  | 541 | Description:     "d8", | 
|  | 542 | Output:          javalibJar, | 
|  | 543 | Input:           dexParams.classesJar, | 
|  | 544 | ImplicitOutputs: implicitOutputs, | 
|  | 545 | Implicits:       d8Deps, | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 546 | Args: map[string]string{ | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 547 | "d8Flags":        strings.Join(append(commonFlags, d8Flags...), " "), | 
|  | 548 | "zipFlags":       zipFlags, | 
|  | 549 | "outDir":         outDir.String(), | 
| Wei Li | 1e73c65 | 2021-12-06 13:35:11 -0800 | [diff] [blame] | 550 | "mergeZipsFlags": mergeZipsFlags, | 
| Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 551 | }, | 
|  | 552 | }) | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 553 | } | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 554 | if proptools.Bool(d.dexProperties.Uncompress_dex) { | 
| Spandan Das | c404cc7 | 2023-02-23 18:05:05 +0000 | [diff] [blame] | 555 | alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", dexParams.jarName).OutputPath | 
| Cole Faust | 51d7bfd | 2023-09-07 05:31:32 +0000 | [diff] [blame] | 556 | TransformZipAlign(ctx, alignedJavalibJar, javalibJar, nil) | 
| Nicolas Geoffray | 65fd8ba | 2019-01-21 23:20:23 +0000 | [diff] [blame] | 557 | javalibJar = alignedJavalibJar | 
|  | 558 | } | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 559 |  | 
| Spandan Das | 3dbda18 | 2024-05-20 22:23:10 +0000 | [diff] [blame] | 560 | return javalibJar, artProfileOutputPath | 
| Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 561 | } |