diff options
Diffstat (limited to 'java/dex.go')
-rw-r--r-- | java/dex.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/java/dex.go b/java/dex.go index ed2df2103..ed9c82ba2 100644 --- a/java/dex.go +++ b/java/dex.go @@ -103,6 +103,34 @@ type DexProperties struct { // If true, transitive reverse dependencies of this module will have this // module's proguard spec appended to their optimization action Export_proguard_flags_files *bool + + // Path to a file containing a list of class names that should not be compiled using R8. + // These classes will be compiled by D8 similar to when Optimize.Enabled is false. + // + // Example: + // + // r8.exclude: + // com.example.Foo + // com.example.Bar + // com.example.Bar$Baz + // + // By default all classes are compiled using R8 when Optimize.Enabled is set. + Exclude *string `android:"path"` + + // Optional list of downstream (Java) libraries from which to trace and preserve references + // when optimizing. Note that this requires that the source reference does *not* have + // a strict lib dependency on this target; dependencies should be on intermediate targets + // statically linked into this target, e.g., if A references B, and we want to trace and + // keep references from A when optimizing B, you would create an intermediate B.impl ( + // containing all static code), have A depend on `B.impl` via libs, and set + // `trace_references_from: ["A"]` on B. + // + // Also note that these are *not* inherited across targets, they must be specified at the + // top-level target that is optimized. + // + // TODO(b/212737576): Handle this implicitly using bottom-up deps mutation and implicit + // creation of a proxy `.impl` library. + Trace_references_from proptools.Configurable[[]string] `android:"arch_variant"` } // Keep the data uncompressed. We always need uncompressed dex for execution, @@ -445,6 +473,20 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams, flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...) + traceReferencesSources := android.Paths{} + ctx.VisitDirectDepsProxyWithTag(traceReferencesTag, func(m android.ModuleProxy) { + if dep, ok := android.OtherModuleProvider(ctx, m, JavaInfoProvider); ok { + traceReferencesSources = append(traceReferencesSources, dep.ImplementationJars...) + } + }) + if len(traceReferencesSources) > 0 { + traceTarget := dexParams.classesJar + traceLibs := android.FirstUniquePaths(append(flags.bootClasspath.Paths(), flags.dexClasspath.Paths()...)) + traceReferencesFlags := android.PathForModuleOut(ctx, "proguard", "trace_references.flags") + TraceReferences(ctx, traceReferencesSources, traceTarget, traceLibs, traceReferencesFlags) + flagFiles = append(flagFiles, traceReferencesFlags) + } + flagFiles = android.FirstUniquePaths(flagFiles) r8Flags = append(r8Flags, android.JoinWithPrefix(flagFiles.Strings(), "-include ")) @@ -528,6 +570,11 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams, r8Flags = append(r8Flags, "--store-store-fence-constructor-inlining") } + if opt.Exclude != nil { + r8Flags = append(r8Flags, "--exclude", *opt.Exclude) + r8Deps = append(r8Deps, android.PathForModuleSrc(ctx, *opt.Exclude)) + } + return r8Flags, r8Deps, artProfileOutput } |