From 53529a906113bc2df0e2436f98314b539f87db2d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 15 Aug 2024 17:11:18 -0700 Subject: [PATCH] Track resources separately in java_import java_import currently collects the "implementation and resource jar" from each of its dependencies. This results in different resource conflict resolution than other java modules, which collect implementation jars and resource jars separately. Modify java_import to match the other module types. Flag: EXEMPT refactor Test: all soong tests pass Change-Id: I06134e2621582799b3a525d2c12b900b8d86d171 --- java/java.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/java/java.go b/java/java.go index 85bc70c54..258ebba0c 100644 --- a/java/java.go +++ b/java/java.go @@ -2634,6 +2634,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.collectTransitiveHeaderJars(ctx) var staticJars android.Paths + var staticResourceJars android.Paths var staticHeaderJars android.Paths ctx.VisitDirectDeps(func(module android.Module) { tag := ctx.OtherModuleDependencyTag(module) @@ -2644,7 +2645,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { flags.dexClasspath = append(flags.dexClasspath, dep.HeaderJars...) case staticLibTag: flags.classpath = append(flags.classpath, dep.HeaderJars...) - staticJars = append(staticJars, dep.ImplementationAndResourcesJars...) + staticJars = append(staticJars, dep.ImplementationJars...) + staticResourceJars = append(staticResourceJars, dep.ResourceJars...) staticHeaderJars = append(staticHeaderJars, dep.HeaderJars...) case bootClasspathTag: flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...) @@ -2675,6 +2677,16 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { // header jar for this module. reuseImplementationJarAsHeaderJar := slices.Equal(staticJars, staticHeaderJars) + var resourceJarFile android.Path + if len(staticResourceJars) > 1 { + combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) + TransformJarsToJar(ctx, combinedJar, "for resources", staticResourceJars, android.OptionalPath{}, + false, nil, nil) + resourceJarFile = combinedJar + } else if len(staticResourceJars) == 1 { + resourceJarFile = staticResourceJars[0] + } + var headerJar android.Path if reuseImplementationJarAsHeaderJar { headerJar = outputFile @@ -2700,6 +2712,17 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } + implementationJarFile := outputFile + + // merge implementation jar with resources if necessary + if resourceJarFile != nil { + jars := android.Paths{resourceJarFile, outputFile} + combinedJar := android.PathForModuleOut(ctx, "withres", jarName) + TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{}, + false, nil, nil) + outputFile = combinedJar + } + // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource. // Also strip the relative path from the header output file so that the reuseImplementationJarAsHeaderJar check // in a module that depends on this module considers them equal. @@ -2793,7 +2816,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedImplementationFile), - ImplementationJars: android.PathsIfNonNil(j.combinedImplementationFile), + ImplementationJars: android.PathsIfNonNil(implementationJarFile.WithoutRel()), + ResourceJars: android.PathsIfNonNil(resourceJarFile), AidlIncludeDirs: j.exportAidlIncludeDirs, StubsLinkType: j.stubsLinkType, // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts