Loading java/base.go +5 −0 Original line number Diff line number Diff line Loading @@ -1650,6 +1650,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath classesJar: implementationAndResourcesJar, jarName: jarName, } if j.GetProfileGuided() && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting() { ctx.PropertyErrorf("enable_profile_rewriting", "Enable_profile_rewriting must be true when profile_guided dexpreopt and R8 optimization/obfuscation is turned on. The attached profile should be sourced from an unoptimized/unobfuscated APK.", ) } if j.EnableProfileRewriting() { profile := j.GetProfile() if profile == "" || !j.GetProfileGuided() { Loading java/dex.go +4 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,10 @@ func (d *DexProperties) optimizedResourceShrinkingEnabled(ctx android.ModuleCont return d.resourceShrinkingEnabled(ctx) && Bool(d.Optimize.Optimized_shrink_resources) } func (d *dexer) optimizeOrObfuscateEnabled() bool { return d.effectiveOptimizeEnabled() && (proptools.Bool(d.dexProperties.Optimize.Optimize) || proptools.Bool(d.dexProperties.Optimize.Obfuscate)) } var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", blueprint.RuleParams{ Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + Loading java/dex_test.go +24 −0 Original line number Diff line number Diff line Loading @@ -689,3 +689,27 @@ func TestR8FlagsArtProfile(t *testing.T) { "--create-profile-from=out/soong/.intermediates/app/android_common/profile.prof.txt --output-profile-type=app", ) } // This test checks that users explicitly set `enable_profile_rewriting` to true when the following are true // 1. optimize or obfuscate is enabled AND // 2. dex_preopt.profile_guided is enabled // // The rewritten profile should be used since the dex signatures in the checked-in profile will not match the optimized binary. func TestEnableProfileRewritingIsRequiredForOptimizedApps(t *testing.T) { testJavaError(t, "Enable_profile_rewriting must be true when profile_guided dexpreopt and R8 optimization/obfuscation is turned on", ` android_app { name: "app", srcs: ["foo.java"], platform_apis: true, dex_preopt: { profile_guided: true, profile: "profile.txt.prof", // enable_profile_rewriting is not set, this is an error }, optimize: { optimize: true, } }`) } Loading
java/base.go +5 −0 Original line number Diff line number Diff line Loading @@ -1650,6 +1650,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath classesJar: implementationAndResourcesJar, jarName: jarName, } if j.GetProfileGuided() && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting() { ctx.PropertyErrorf("enable_profile_rewriting", "Enable_profile_rewriting must be true when profile_guided dexpreopt and R8 optimization/obfuscation is turned on. The attached profile should be sourced from an unoptimized/unobfuscated APK.", ) } if j.EnableProfileRewriting() { profile := j.GetProfile() if profile == "" || !j.GetProfileGuided() { Loading
java/dex.go +4 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,10 @@ func (d *DexProperties) optimizedResourceShrinkingEnabled(ctx android.ModuleCont return d.resourceShrinkingEnabled(ctx) && Bool(d.Optimize.Optimized_shrink_resources) } func (d *dexer) optimizeOrObfuscateEnabled() bool { return d.effectiveOptimizeEnabled() && (proptools.Bool(d.dexProperties.Optimize.Optimize) || proptools.Bool(d.dexProperties.Optimize.Obfuscate)) } var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", blueprint.RuleParams{ Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + Loading
java/dex_test.go +24 −0 Original line number Diff line number Diff line Loading @@ -689,3 +689,27 @@ func TestR8FlagsArtProfile(t *testing.T) { "--create-profile-from=out/soong/.intermediates/app/android_common/profile.prof.txt --output-profile-type=app", ) } // This test checks that users explicitly set `enable_profile_rewriting` to true when the following are true // 1. optimize or obfuscate is enabled AND // 2. dex_preopt.profile_guided is enabled // // The rewritten profile should be used since the dex signatures in the checked-in profile will not match the optimized binary. func TestEnableProfileRewritingIsRequiredForOptimizedApps(t *testing.T) { testJavaError(t, "Enable_profile_rewriting must be true when profile_guided dexpreopt and R8 optimization/obfuscation is turned on", ` android_app { name: "app", srcs: ["foo.java"], platform_apis: true, dex_preopt: { profile_guided: true, profile: "profile.txt.prof", // enable_profile_rewriting is not set, this is an error }, optimize: { optimize: true, } }`) }