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 15package java 16 17import ( 18 "strconv" 19 "strings" 20 21 "github.com/google/blueprint" 22 "github.com/google/blueprint/proptools" 23 24 "android/soong/android" 25 "android/soong/remoteexec" 26) 27 28type 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 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 38 Optimize struct { 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. 41 Enabled *bool 42 // True if the module containing this has it set by default. 43 EnabledByDefault bool `blueprint:"mutated"` 44 45 // Whether to continue building even if warnings are emitted. Defaults to true. 46 Ignore_warnings *bool 47 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. 50 Proguard_compatibility *bool 51 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 66 // If true, optimize for size by removing unused resources. Defaults to false. 67 Shrink_resources *bool 68 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 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"` 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 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 91 92 // Exclude kotlinc generate files: *.kotlin_module, *.kotlin_builtins. Defaults to false. 93 Exclude_kotlinc_generated_files *bool 94} 95 96type dexer struct { 97 dexProperties DexProperties 98 99 // list of extra proguard flag files 100 extraProguardFlagsFiles android.Paths 101 proguardDictionary android.OptionalPath 102 proguardConfiguration android.OptionalPath 103 proguardUsageZip android.OptionalPath 104 resourcesInput android.OptionalPath 105 resourcesOutput android.OptionalPath 106 107 providesTransitiveHeaderJars 108} 109 110func (d *dexer) effectiveOptimizeEnabled() bool { 111 return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault) 112} 113 114func (d *DexProperties) resourceShrinkingEnabled(ctx android.ModuleContext) bool { 115 return !ctx.Config().Eng() && BoolDefault(d.Optimize.Optimized_shrink_resources, Bool(d.Optimize.Shrink_resources)) 116} 117 118func (d *DexProperties) optimizedResourceShrinkingEnabled(ctx android.ModuleContext) bool { 119 return d.resourceShrinkingEnabled(ctx) && Bool(d.Optimize.Optimized_shrink_resources) 120} 121 122func (d *dexer) optimizeOrObfuscateEnabled() bool { 123 return d.effectiveOptimizeEnabled() && (proptools.Bool(d.dexProperties.Optimize.Optimize) || proptools.Bool(d.dexProperties.Optimize.Obfuscate)) 124} 125 126var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", 127 blueprint.RuleParams{ 128 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + 129 `$d8Template${config.D8Cmd} ${config.D8Flags} $d8Flags --output $outDir --no-dex-input-jar $in && ` + 130 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` + 131 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` + 132 `rm -f "$outDir/classes*.dex" "$outDir/classes.dex.jar"`, 133 CommandDeps: []string{ 134 "${config.D8Cmd}", 135 "${config.SoongZipCmd}", 136 "${config.MergeZipsCmd}", 137 }, 138 }, map[string]*remoteexec.REParams{ 139 "$d8Template": &remoteexec.REParams{ 140 Labels: map[string]string{"type": "compile", "compiler": "d8"}, 141 Inputs: []string{"${config.D8Jar}"}, 142 ExecStrategy: "${config.RED8ExecStrategy}", 143 ToolchainInputs: []string{"${config.JavaCmd}"}, 144 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, 145 }, 146 "$zipTemplate": &remoteexec.REParams{ 147 Labels: map[string]string{"type": "tool", "name": "soong_zip"}, 148 Inputs: []string{"${config.SoongZipCmd}", "$outDir"}, 149 OutputFiles: []string{"$outDir/classes.dex.jar"}, 150 ExecStrategy: "${config.RED8ExecStrategy}", 151 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, 152 }, 153 }, []string{"outDir", "d8Flags", "zipFlags", "mergeZipsFlags"}, nil) 154 155var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", 156 blueprint.RuleParams{ 157 Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + 158 `rm -f "$outDict" && rm -f "$outConfig" && rm -rf "${outUsageDir}" && ` + 159 `mkdir -p $$(dirname ${outUsage}) && ` + 160 `$r8Template${config.R8Cmd} ${config.R8Flags} $r8Flags -injars $in --output $outDir ` + 161 `--no-data-resources ` + 162 `-printmapping ${outDict} ` + 163 `-printconfiguration ${outConfig} ` + 164 `-printusage ${outUsage} ` + 165 `--deps-file ${out}.d && ` + 166 `touch "${outDict}" "${outConfig}" "${outUsage}" && ` + 167 `${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` + 168 `rm -rf ${outUsageDir} && ` + 169 `$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` + 170 `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in && ` + 171 `rm -f "$outDir/classes*.dex" "$outDir/classes.dex.jar"`, 172 Depfile: "${out}.d", 173 Deps: blueprint.DepsGCC, 174 CommandDeps: []string{ 175 "${config.R8Cmd}", 176 "${config.SoongZipCmd}", 177 "${config.MergeZipsCmd}", 178 }, 179 }, map[string]*remoteexec.REParams{ 180 "$r8Template": &remoteexec.REParams{ 181 Labels: map[string]string{"type": "compile", "compiler": "r8"}, 182 Inputs: []string{"$implicits", "${config.R8Jar}"}, 183 OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}"}, 184 ExecStrategy: "${config.RER8ExecStrategy}", 185 ToolchainInputs: []string{"${config.JavaCmd}"}, 186 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, 187 }, 188 "$zipTemplate": &remoteexec.REParams{ 189 Labels: map[string]string{"type": "tool", "name": "soong_zip"}, 190 Inputs: []string{"${config.SoongZipCmd}", "$outDir"}, 191 OutputFiles: []string{"$outDir/classes.dex.jar"}, 192 ExecStrategy: "${config.RER8ExecStrategy}", 193 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, 194 }, 195 "$zipUsageTemplate": &remoteexec.REParams{ 196 Labels: map[string]string{"type": "tool", "name": "soong_zip"}, 197 Inputs: []string{"${config.SoongZipCmd}", "${outUsage}"}, 198 OutputFiles: []string{"${outUsageZip}"}, 199 ExecStrategy: "${config.RER8ExecStrategy}", 200 Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, 201 }, 202 }, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir", 203 "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput"}, []string{"implicits"}) 204 205func (d *dexer) dexCommonFlags(ctx android.ModuleContext, 206 dexParams *compileDexParams) (flags []string, deps android.Paths) { 207 208 flags = d.dexProperties.Dxflags 209 // Translate all the DX flags to D8 ones until all the build files have been migrated 210 // to D8 flags. See: b/69377755 211 flags = android.RemoveListFromList(flags, 212 []string{"--core-library", "--dex", "--multi-dex"}) 213 214 for _, f := range android.PathsForModuleSrc(ctx, d.dexProperties.Main_dex_rules) { 215 flags = append(flags, "--main-dex-rules", f.String()) 216 deps = append(deps, f) 217 } 218 219 if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" { 220 flags = append(flags, "--debug") 221 } 222 223 if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" { 224 flags = append(flags, 225 "--debug", 226 "--verbose") 227 } 228 229 // Supplying the platform build flag disables various features like API modeling and desugaring. 230 // For targets with a stable min SDK version (i.e., when the min SDK is both explicitly specified 231 // and managed+versioned), we suppress this flag to ensure portability. 232 // Note: Targets with a min SDK kind of core_platform (e.g., framework.jar) or unspecified (e.g., 233 // services.jar), are not classified as stable, which is WAI. 234 // TODO(b/232073181): Expand to additional min SDK cases after validation. 235 var addAndroidPlatformBuildFlag = false 236 if !dexParams.sdkVersion.Stable() { 237 addAndroidPlatformBuildFlag = true 238 } 239 240 effectiveVersion, err := dexParams.minSdkVersion.EffectiveVersion(ctx) 241 if err != nil { 242 ctx.PropertyErrorf("min_sdk_version", "%s", err) 243 } 244 245 // If the specified SDK level is 10000, then configure the compiler to use the 246 // current platform SDK level and to compile the build as a platform build. 247 var minApiFlagValue = effectiveVersion.FinalOrFutureInt() 248 if minApiFlagValue == 10000 { 249 minApiFlagValue = ctx.Config().PlatformSdkVersion().FinalInt() 250 addAndroidPlatformBuildFlag = true 251 } 252 flags = append(flags, "--min-api "+strconv.Itoa(minApiFlagValue)) 253 254 if addAndroidPlatformBuildFlag { 255 flags = append(flags, "--android-platform-build") 256 } 257 return flags, deps 258} 259 260func (d *dexer) d8Flags(ctx android.ModuleContext, dexParams *compileDexParams) (d8Flags []string, d8Deps android.Paths, artProfileOutput *android.OutputPath) { 261 flags := dexParams.flags 262 d8Flags = append(d8Flags, flags.bootClasspath.FormRepeatedClassPath("--lib ")...) 263 d8Flags = append(d8Flags, flags.dexClasspath.FormRepeatedClassPath("--lib ")...) 264 265 d8Deps = append(d8Deps, flags.bootClasspath...) 266 d8Deps = append(d8Deps, flags.dexClasspath...) 267 268 if flags, deps, profileOutput := d.addArtProfile(ctx, dexParams); profileOutput != nil { 269 d8Flags = append(d8Flags, flags...) 270 d8Deps = append(d8Deps, deps...) 271 artProfileOutput = profileOutput 272 } 273 274 return d8Flags, d8Deps, artProfileOutput 275} 276 277func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams) (r8Flags []string, r8Deps android.Paths, artProfileOutput *android.OutputPath) { 278 flags := dexParams.flags 279 opt := d.dexProperties.Optimize 280 281 // When an app contains references to APIs that are not in the SDK specified by 282 // its LOCAL_SDK_VERSION for example added by support library or by runtime 283 // classes added by desugaring, we artifically raise the "SDK version" "linked" by 284 // ProGuard, to 285 // - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version. 286 // - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version. 287 // See b/20667396 288 var proguardRaiseDeps classpath 289 ctx.VisitDirectDepsWithTag(proguardRaiseTag, func(m android.Module) { 290 dep, _ := android.OtherModuleProvider(ctx, m, JavaInfoProvider) 291 proguardRaiseDeps = append(proguardRaiseDeps, dep.RepackagedHeaderJars...) 292 }) 293 294 r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars")) 295 r8Deps = append(r8Deps, proguardRaiseDeps...) 296 r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars")) 297 r8Deps = append(r8Deps, flags.bootClasspath...) 298 r8Flags = append(r8Flags, flags.dexClasspath.FormJavaClassPath("-libraryjars")) 299 r8Deps = append(r8Deps, flags.dexClasspath...) 300 301 transitiveStaticLibsLookupMap := map[android.Path]bool{} 302 if d.transitiveStaticLibsHeaderJars != nil { 303 for _, jar := range d.transitiveStaticLibsHeaderJars.ToList() { 304 transitiveStaticLibsLookupMap[jar] = true 305 } 306 } 307 transitiveHeaderJars := android.Paths{} 308 if d.transitiveLibsHeaderJars != nil { 309 for _, jar := range d.transitiveLibsHeaderJars.ToList() { 310 if _, ok := transitiveStaticLibsLookupMap[jar]; ok { 311 // don't include a lib if it is already packaged in the current JAR as a static lib 312 continue 313 } 314 transitiveHeaderJars = append(transitiveHeaderJars, jar) 315 } 316 } 317 transitiveClasspath := classpath(transitiveHeaderJars) 318 r8Flags = append(r8Flags, transitiveClasspath.FormJavaClassPath("-libraryjars")) 319 r8Deps = append(r8Deps, transitiveClasspath...) 320 321 flagFiles := android.Paths{ 322 android.PathForSource(ctx, "build/make/core/proguard.flags"), 323 } 324 325 flagFiles = append(flagFiles, d.extraProguardFlagsFiles...) 326 // TODO(ccross): static android library proguard files 327 328 flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...) 329 330 flagFiles = android.FirstUniquePaths(flagFiles) 331 332 r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include ")) 333 r8Deps = append(r8Deps, flagFiles...) 334 335 // TODO(b/70942988): This is included from build/make/core/proguard.flags 336 r8Deps = append(r8Deps, android.PathForSource(ctx, 337 "build/make/core/proguard_basic_keeps.flags")) 338 339 r8Flags = append(r8Flags, opt.Proguard_flags...) 340 341 if BoolDefault(opt.Proguard_compatibility, true) { 342 r8Flags = append(r8Flags, "--force-proguard-compatibility") 343 } 344 345 if Bool(opt.Optimize) || Bool(opt.Obfuscate) { 346 // TODO(b/213833843): Allow configuration of the prefix via a build variable. 347 var sourceFilePrefix = "go/retraceme " 348 var sourceFileTemplate = "\"" + sourceFilePrefix + "%MAP_ID\"" 349 r8Flags = append(r8Flags, "--map-id-template", "%MAP_HASH") 350 r8Flags = append(r8Flags, "--source-file-template", sourceFileTemplate) 351 } 352 353 // TODO(ccross): Don't shrink app instrumentation tests by default. 354 if !Bool(opt.Shrink) { 355 r8Flags = append(r8Flags, "-dontshrink") 356 } 357 358 if !Bool(opt.Optimize) { 359 r8Flags = append(r8Flags, "-dontoptimize") 360 } 361 362 // TODO(ccross): error if obufscation + app instrumentation test. 363 if !Bool(opt.Obfuscate) { 364 r8Flags = append(r8Flags, "-dontobfuscate") 365 } 366 // TODO(ccross): if this is an instrumentation test of an obfuscated app, use the 367 // dictionary of the app and move the app from libraryjars to injars. 368 369 // Don't strip out debug information for eng builds. 370 if ctx.Config().Eng() { 371 r8Flags = append(r8Flags, "--debug") 372 } 373 374 // TODO(b/180878971): missing classes should be added to the relevant builds. 375 // TODO(b/229727645): do not use true as default for Android platform builds. 376 if proptools.BoolDefault(opt.Ignore_warnings, true) { 377 r8Flags = append(r8Flags, "-ignorewarnings") 378 } 379 380 // resourcesInput is empty when we don't use resource shrinking, if on, pass these to R8 381 if d.resourcesInput.Valid() { 382 r8Flags = append(r8Flags, "--resource-input", d.resourcesInput.Path().String()) 383 r8Deps = append(r8Deps, d.resourcesInput.Path()) 384 r8Flags = append(r8Flags, "--resource-output", d.resourcesOutput.Path().String()) 385 if Bool(opt.Optimized_shrink_resources) { 386 r8Flags = append(r8Flags, "--optimized-resource-shrinking") 387 } 388 } 389 390 if flags, deps, profileOutput := d.addArtProfile(ctx, dexParams); profileOutput != nil { 391 r8Flags = append(r8Flags, flags...) 392 r8Deps = append(r8Deps, deps...) 393 artProfileOutput = profileOutput 394 } 395 396 return r8Flags, r8Deps, artProfileOutput 397} 398 399type compileDexParams struct { 400 flags javaBuilderFlags 401 sdkVersion android.SdkSpec 402 minSdkVersion android.ApiLevel 403 classesJar android.Path 404 jarName string 405 artProfileInput *string 406} 407 408// Adds --art-profile to r8/d8 command. 409// r8/d8 will output a generated profile file to match the optimized dex code. 410func (d *dexer) addArtProfile(ctx android.ModuleContext, dexParams *compileDexParams) (flags []string, deps android.Paths, artProfileOutputPath *android.OutputPath) { 411 if dexParams.artProfileInput != nil { 412 artProfileInputPath := android.PathForModuleSrc(ctx, *dexParams.artProfileInput) 413 artProfileOutputPathValue := android.PathForModuleOut(ctx, "profile.prof.txt").OutputPath 414 artProfileOutputPath = &artProfileOutputPathValue 415 flags = []string{ 416 "--art-profile", 417 artProfileInputPath.String(), 418 artProfileOutputPath.String(), 419 } 420 deps = append(deps, artProfileInputPath) 421 } 422 return flags, deps, artProfileOutputPath 423 424} 425 426// Return the compiled dex jar and (optional) profile _after_ r8 optimization 427func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParams) (android.OutputPath, *android.OutputPath) { 428 429 // Compile classes.jar into classes.dex and then javalib.jar 430 javalibJar := android.PathForModuleOut(ctx, "dex", dexParams.jarName).OutputPath 431 outDir := android.PathForModuleOut(ctx, "dex") 432 433 zipFlags := "--ignore_missing_files" 434 if proptools.Bool(d.dexProperties.Uncompress_dex) { 435 zipFlags += " -L 0" 436 } 437 438 commonFlags, commonDeps := d.dexCommonFlags(ctx, dexParams) 439 440 // Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true. 441 mergeZipsFlags := "" 442 if proptools.BoolDefault(d.dexProperties.Exclude_kotlinc_generated_files, false) { 443 mergeZipsFlags = "-stripFile META-INF/*.kotlin_module -stripFile **/*.kotlin_builtins" 444 } 445 446 useR8 := d.effectiveOptimizeEnabled() 447 var artProfileOutputPath *android.OutputPath 448 if useR8 { 449 proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary") 450 d.proguardDictionary = android.OptionalPathForPath(proguardDictionary) 451 proguardConfiguration := android.PathForModuleOut(ctx, "proguard_configuration") 452 d.proguardConfiguration = android.OptionalPathForPath(proguardConfiguration) 453 proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage") 454 proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path, 455 android.ModuleNameWithPossibleOverride(ctx), "unused.txt") 456 proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip") 457 d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip) 458 resourcesOutput := android.PathForModuleOut(ctx, "package-res-shrunken.apk") 459 d.resourcesOutput = android.OptionalPathForPath(resourcesOutput) 460 implicitOutputs := android.WritablePaths{ 461 proguardDictionary, 462 proguardUsageZip, 463 proguardConfiguration, 464 } 465 r8Flags, r8Deps, r8ArtProfileOutputPath := d.r8Flags(ctx, dexParams) 466 if r8ArtProfileOutputPath != nil { 467 artProfileOutputPath = r8ArtProfileOutputPath 468 implicitOutputs = append( 469 implicitOutputs, 470 artProfileOutputPath, 471 ) 472 } 473 rule := r8 474 args := map[string]string{ 475 "r8Flags": strings.Join(append(commonFlags, r8Flags...), " "), 476 "zipFlags": zipFlags, 477 "outDict": proguardDictionary.String(), 478 "outConfig": proguardConfiguration.String(), 479 "outUsageDir": proguardUsageDir.String(), 480 "outUsage": proguardUsage.String(), 481 "outUsageZip": proguardUsageZip.String(), 482 "outDir": outDir.String(), 483 "mergeZipsFlags": mergeZipsFlags, 484 } 485 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_R8") { 486 rule = r8RE 487 args["implicits"] = strings.Join(r8Deps.Strings(), ",") 488 } 489 if d.resourcesInput.Valid() { 490 implicitOutputs = append(implicitOutputs, resourcesOutput) 491 args["resourcesOutput"] = resourcesOutput.String() 492 } 493 ctx.Build(pctx, android.BuildParams{ 494 Rule: rule, 495 Description: "r8", 496 Output: javalibJar, 497 ImplicitOutputs: implicitOutputs, 498 Input: dexParams.classesJar, 499 Implicits: r8Deps, 500 Args: args, 501 }) 502 } else { 503 implicitOutputs := android.WritablePaths{} 504 d8Flags, d8Deps, d8ArtProfileOutputPath := d.d8Flags(ctx, dexParams) 505 if d8ArtProfileOutputPath != nil { 506 artProfileOutputPath = d8ArtProfileOutputPath 507 implicitOutputs = append( 508 implicitOutputs, 509 artProfileOutputPath, 510 ) 511 } 512 d8Deps = append(d8Deps, commonDeps...) 513 rule := d8 514 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") { 515 rule = d8RE 516 } 517 ctx.Build(pctx, android.BuildParams{ 518 Rule: rule, 519 Description: "d8", 520 Output: javalibJar, 521 Input: dexParams.classesJar, 522 ImplicitOutputs: implicitOutputs, 523 Implicits: d8Deps, 524 Args: map[string]string{ 525 "d8Flags": strings.Join(append(commonFlags, d8Flags...), " "), 526 "zipFlags": zipFlags, 527 "outDir": outDir.String(), 528 "mergeZipsFlags": mergeZipsFlags, 529 }, 530 }) 531 } 532 if proptools.Bool(d.dexProperties.Uncompress_dex) { 533 alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", dexParams.jarName).OutputPath 534 TransformZipAlign(ctx, alignedJavalibJar, javalibJar, nil) 535 javalibJar = alignedJavalibJar 536 } 537 538 return javalibJar, artProfileOutputPath 539} 540