R8/D8 should use sdk_version prop to determine API surface stability.
`min_sdk_version` is used to represent the api_level of the device and its type will eventually become android.ApiLevel. OTOH, `sdk_version` property represents the API surface a module builds against _and_ the version of that API surface. For R8/D8, the additional `--android-platform-build` should be determined using the sdk_version of the soong module and not min_sdk_version, since min_sdk_version will not contain information about the api surface used for compilation. The unit test for `core_platform_app` in TestR8 were passing since min_sdk_version was not set, and therefore it implicitly defaulted to sdk_version. Also created a custom struct to propagate params to the helper dex functions Test: In build/soong, go test ./java Test: TH Bug: 208456999 Change-Id: I08ac6f496444d603557e498c8a1794af665abc7a
This commit is contained in:
@@ -1488,7 +1488,14 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
}
|
||||
// Dex compilation
|
||||
var dexOutputFile android.OutputPath
|
||||
dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), implementationAndResourcesJar, jarName)
|
||||
params := &compileDexParams{
|
||||
flags: flags,
|
||||
sdkVersion: j.SdkVersion(ctx),
|
||||
minSdkVersion: j.MinSdkVersion(ctx),
|
||||
classesJar: implementationAndResourcesJar,
|
||||
jarName: jarName,
|
||||
}
|
||||
dexOutputFile = j.dexer.compileDex(ctx, params)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
|
33
java/dex.go
33
java/dex.go
@@ -180,7 +180,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
|
||||
"r8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, []string{"implicits"})
|
||||
|
||||
func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
|
||||
minSdkVersion android.SdkSpec) (flags []string, deps android.Paths) {
|
||||
dexParams *compileDexParams) (flags []string, deps android.Paths) {
|
||||
|
||||
flags = d.dexProperties.Dxflags
|
||||
// Translate all the DX flags to D8 ones until all the build files have been migrated
|
||||
@@ -209,11 +209,11 @@ func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
|
||||
// Note: Targets with a min SDK kind of core_platform (e.g., framework.jar) or unspecified (e.g.,
|
||||
// services.jar), are not classified as stable, which is WAI.
|
||||
// TODO(b/232073181): Expand to additional min SDK cases after validation.
|
||||
if !minSdkVersion.Stable() {
|
||||
if !dexParams.sdkVersion.Stable() {
|
||||
flags = append(flags, "--android-platform-build")
|
||||
}
|
||||
|
||||
effectiveVersion, err := minSdkVersion.EffectiveVersion(ctx)
|
||||
effectiveVersion, err := dexParams.minSdkVersion.EffectiveVersion(ctx)
|
||||
if err != nil {
|
||||
ctx.PropertyErrorf("min_sdk_version", "%s", err)
|
||||
}
|
||||
@@ -317,20 +317,27 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl
|
||||
return r8Flags, r8Deps
|
||||
}
|
||||
|
||||
func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion android.SdkSpec,
|
||||
classesJar android.Path, jarName string) android.OutputPath {
|
||||
type compileDexParams struct {
|
||||
flags javaBuilderFlags
|
||||
sdkVersion android.SdkSpec
|
||||
minSdkVersion android.SdkSpec
|
||||
classesJar android.Path
|
||||
jarName string
|
||||
}
|
||||
|
||||
func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParams) android.OutputPath {
|
||||
|
||||
// Compile classes.jar into classes.dex and then javalib.jar
|
||||
javalibJar := android.PathForModuleOut(ctx, "dex", jarName).OutputPath
|
||||
javalibJar := android.PathForModuleOut(ctx, "dex", dexParams.jarName).OutputPath
|
||||
outDir := android.PathForModuleOut(ctx, "dex")
|
||||
tmpJar := android.PathForModuleOut(ctx, "withres-withoutdex", jarName)
|
||||
tmpJar := android.PathForModuleOut(ctx, "withres-withoutdex", dexParams.jarName)
|
||||
|
||||
zipFlags := "--ignore_missing_files"
|
||||
if proptools.Bool(d.dexProperties.Uncompress_dex) {
|
||||
zipFlags += " -L 0"
|
||||
}
|
||||
|
||||
commonFlags, commonDeps := d.dexCommonFlags(ctx, minSdkVersion)
|
||||
commonFlags, commonDeps := d.dexCommonFlags(ctx, dexParams)
|
||||
|
||||
// Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true.
|
||||
mergeZipsFlags := ""
|
||||
@@ -347,7 +354,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
||||
android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
|
||||
proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
|
||||
d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
|
||||
r8Flags, r8Deps := d.r8Flags(ctx, flags)
|
||||
r8Flags, r8Deps := d.r8Flags(ctx, dexParams.flags)
|
||||
r8Deps = append(r8Deps, commonDeps...)
|
||||
rule := r8
|
||||
args := map[string]string{
|
||||
@@ -370,12 +377,12 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
||||
Description: "r8",
|
||||
Output: javalibJar,
|
||||
ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip},
|
||||
Input: classesJar,
|
||||
Input: dexParams.classesJar,
|
||||
Implicits: r8Deps,
|
||||
Args: args,
|
||||
})
|
||||
} else {
|
||||
d8Flags, d8Deps := d8Flags(flags)
|
||||
d8Flags, d8Deps := d8Flags(dexParams.flags)
|
||||
d8Deps = append(d8Deps, commonDeps...)
|
||||
rule := d8
|
||||
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") {
|
||||
@@ -385,7 +392,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
||||
Rule: rule,
|
||||
Description: "d8",
|
||||
Output: javalibJar,
|
||||
Input: classesJar,
|
||||
Input: dexParams.classesJar,
|
||||
Implicits: d8Deps,
|
||||
Args: map[string]string{
|
||||
"d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
|
||||
@@ -397,7 +404,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
||||
})
|
||||
}
|
||||
if proptools.Bool(d.dexProperties.Uncompress_dex) {
|
||||
alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath
|
||||
alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", dexParams.jarName).OutputPath
|
||||
TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
|
||||
javalibJar = alignedJavalibJar
|
||||
}
|
||||
|
@@ -41,6 +41,7 @@ func TestR8(t *testing.T) {
|
||||
name: "core_platform_app",
|
||||
srcs: ["foo.java"],
|
||||
sdk_version: "core_platform",
|
||||
min_sdk_version: "31",
|
||||
}
|
||||
|
||||
java_library {
|
||||
|
10
java/java.go
10
java/java.go
@@ -1981,7 +1981,15 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
||||
|
||||
var dexOutputFile android.OutputPath
|
||||
dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
|
||||
dexParams := &compileDexParams{
|
||||
flags: flags,
|
||||
sdkVersion: j.SdkVersion(ctx),
|
||||
minSdkVersion: j.MinSdkVersion(ctx),
|
||||
classesJar: outputFile,
|
||||
jarName: jarName,
|
||||
}
|
||||
|
||||
dexOutputFile = j.dexer.compileDex(ctx, dexParams)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user