Fix resource overlay order for static libraries

If a static library has static library dependencies then all resources
need to be moved to an overlay to maintain the correct ordering so
that a static library resource overlays the same resource in a
dependency.

Also fix the ordering of transitive static dependencies, a direct
dependency should override a transitive dependency.

Expand TestEnforceRRO to include a transitive static library and
verify both the direct resources and overlays, and rename it to
TestAndroidResources.

Bug: 124108931
Test: TestAndroidResources
Change-Id: I355f835a2ffb728af28aa208d951794c609e7409
This commit is contained in:
Colin Cross
2019-02-13 13:15:46 -08:00
parent dfa4a486eb
commit bec8530972
2 changed files with 102 additions and 45 deletions

View File

@@ -215,17 +215,17 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
if a.isLibrary {
// For a static library we treat all the resources equally with no overlay.
for _, compiledResDir := range compiledResDirs {
compiledRes = append(compiledRes, compiledResDir...)
}
} else if len(transitiveStaticLibs) > 0 {
if len(transitiveStaticLibs) > 0 {
// If we are using static android libraries, every source file becomes an overlay.
// This is to emulate old AAPT behavior which simulated library support.
for _, compiledResDir := range compiledResDirs {
compiledOverlay = append(compiledOverlay, compiledResDir...)
}
} else if a.isLibrary {
// Otherwise, for a static library we treat all the resources equally with no overlay.
for _, compiledResDir := range compiledResDirs {
compiledRes = append(compiledRes, compiledResDir...)
}
} else if len(compiledResDirs) > 0 {
// Without static libraries, the first directory is our directory, which can then be
// overlaid by the rest.
@@ -278,8 +278,8 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
}
case staticLibTag:
if exportPackage != nil {
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
staticRRODirs = append(staticRRODirs, aarDep.ExportedRRODirs()...)
}