diff options
author | 2024-08-15 17:11:18 -0700 | |
---|---|---|
committer | 2024-08-16 11:56:19 -0700 | |
commit | 53529a906113bc2df0e2436f98314b539f87db2d (patch) | |
tree | 88282da649cd99d97bc1379b2ec9d1b0d7f6d5e3 /java/java.go | |
parent | 77965d9bd4dbec3301cae9b7ce548cb7bc43ef6b (diff) |
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
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 28 |
1 files 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 |