Don't use merged manifest for android_library modules
Don't use the merged manifest for android_library modules. We still have to run manifest merger for android_library modules because Make can't handle transitive dependencies, so it will continue to merge the manifests at each library, and then merge the manifests of direct dependencies into the final application. Bug: 113294940 Test: m checkbuild Change-Id: Ia8f9f910bd0a134730ddf2d542460eeddbc0a075
This commit is contained in:
parent
28c3eb6829
commit
90c25c6893
61
java/aar.go
61
java/aar.go
|
@ -29,7 +29,7 @@ type AndroidLibraryDependency interface {
|
|||
ExportedProguardFlagFiles() android.Paths
|
||||
ExportedRRODirs() []rroDir
|
||||
ExportedStaticPackages() android.Paths
|
||||
ExportedManifest() android.Path
|
||||
ExportedManifests() android.Paths
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -71,17 +71,19 @@ type aaptProperties struct {
|
|||
}
|
||||
|
||||
type aapt struct {
|
||||
aaptSrcJar android.Path
|
||||
exportPackage android.Path
|
||||
manifestPath android.Path
|
||||
proguardOptionsFile android.Path
|
||||
rroDirs []rroDir
|
||||
rTxt android.Path
|
||||
extraAaptPackagesFile android.Path
|
||||
isLibrary bool
|
||||
uncompressedJNI bool
|
||||
useEmbeddedDex bool
|
||||
usesNonSdkApis bool
|
||||
aaptSrcJar android.Path
|
||||
exportPackage android.Path
|
||||
manifestPath android.Path
|
||||
transitiveManifestPaths android.Paths
|
||||
proguardOptionsFile android.Path
|
||||
rroDirs []rroDir
|
||||
rTxt android.Path
|
||||
extraAaptPackagesFile android.Path
|
||||
mergedManifestFile android.Path
|
||||
isLibrary bool
|
||||
uncompressedJNI bool
|
||||
useEmbeddedDex bool
|
||||
usesNonSdkApis bool
|
||||
|
||||
splitNames []string
|
||||
splits []split
|
||||
|
@ -103,8 +105,8 @@ func (a *aapt) ExportedRRODirs() []rroDir {
|
|||
return a.rroDirs
|
||||
}
|
||||
|
||||
func (a *aapt) ExportedManifest() android.Path {
|
||||
return a.manifestPath
|
||||
func (a *aapt) ExportedManifests() android.Paths {
|
||||
return a.transitiveManifestPaths
|
||||
}
|
||||
|
||||
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string,
|
||||
|
@ -192,14 +194,28 @@ func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) {
|
|||
}
|
||||
|
||||
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
||||
transitiveStaticLibs, staticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext)
|
||||
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext)
|
||||
|
||||
// App manifest file
|
||||
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
||||
|
||||
manifestPath := manifestMerger(ctx, manifestSrcPath, sdkContext, staticLibManifests, a.isLibrary,
|
||||
a.uncompressedJNI, a.useEmbeddedDex, a.usesNonSdkApis)
|
||||
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext,
|
||||
a.isLibrary, a.uncompressedJNI, a.usesNonSdkApis, a.useEmbeddedDex)
|
||||
|
||||
a.transitiveManifestPaths = append(android.Paths{manifestPath}, transitiveStaticLibManifests...)
|
||||
|
||||
if len(transitiveStaticLibManifests) > 0 {
|
||||
a.mergedManifestFile = manifestMerger(ctx, manifestPath, transitiveStaticLibManifests)
|
||||
if !a.isLibrary {
|
||||
// Only use the merged manifest for applications. For libraries, the transitive closure of manifests
|
||||
// will be propagated to the final application and merged there. The merged manifest for libraries is
|
||||
// only passed to Make, which can't handle transitive dependencies.
|
||||
manifestPath = a.mergedManifestFile
|
||||
}
|
||||
} else {
|
||||
a.mergedManifestFile = manifestPath
|
||||
}
|
||||
|
||||
linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
||||
|
||||
|
@ -286,7 +302,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
|||
}
|
||||
|
||||
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
||||
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, staticLibManifests android.Paths,
|
||||
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths,
|
||||
staticRRODirs []rroDir, deps android.Paths, flags []string) {
|
||||
|
||||
var sharedLibs android.Paths
|
||||
|
@ -314,7 +330,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||
if exportPackage != nil {
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
|
||||
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
|
||||
|
||||
outer:
|
||||
for _, d := range aarDep.ExportedRRODirs() {
|
||||
|
@ -341,8 +357,9 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||
}
|
||||
|
||||
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
||||
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
|
||||
|
||||
return transitiveStaticLibs, staticLibManifests, staticRRODirs, deps, flags
|
||||
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, deps, flags
|
||||
}
|
||||
|
||||
type AndroidLibrary struct {
|
||||
|
@ -498,8 +515,8 @@ func (a *AARImport) ExportedStaticPackages() android.Paths {
|
|||
return a.exportedStaticPackages
|
||||
}
|
||||
|
||||
func (a *AARImport) ExportedManifest() android.Path {
|
||||
return a.manifest
|
||||
func (a *AARImport) ExportedManifests() android.Paths {
|
||||
return android.Paths{a.manifest}
|
||||
}
|
||||
|
||||
func (a *AARImport) Prebuilt() *android.Prebuilt {
|
||||
|
|
|
@ -41,8 +41,9 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
|
|||
},
|
||||
"libs")
|
||||
|
||||
func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
|
||||
staticLibManifests android.Paths, isLibrary, uncompressedJNI, useEmbeddedDex, usesNonSdkApis bool) android.Path {
|
||||
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
|
||||
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
|
||||
isLibrary, uncompressedJNI, usesNonSdkApis, useEmbeddedDex bool) android.Path {
|
||||
|
||||
var args []string
|
||||
if isLibrary {
|
||||
|
@ -79,35 +80,35 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext
|
|||
deps = append(deps, apiFingerprint)
|
||||
}
|
||||
|
||||
// Inject minSdkVersion into the manifest
|
||||
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: manifestFixerRule,
|
||||
Input: manifest,
|
||||
Implicits: deps,
|
||||
Output: fixedManifest,
|
||||
Rule: manifestFixerRule,
|
||||
Description: "fix manifest",
|
||||
Input: manifest,
|
||||
Implicits: deps,
|
||||
Output: fixedManifest,
|
||||
Args: map[string]string{
|
||||
"minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
|
||||
"targetSdkVersion": targetSdkVersion,
|
||||
"args": strings.Join(args, " "),
|
||||
},
|
||||
})
|
||||
manifest = fixedManifest
|
||||
|
||||
// Merge static aar dependency manifests if necessary
|
||||
if len(staticLibManifests) > 0 {
|
||||
mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: manifestMergerRule,
|
||||
Input: manifest,
|
||||
Implicits: staticLibManifests,
|
||||
Output: mergedManifest,
|
||||
Args: map[string]string{
|
||||
"libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "),
|
||||
},
|
||||
})
|
||||
manifest = mergedManifest
|
||||
}
|
||||
|
||||
return manifest
|
||||
return fixedManifest
|
||||
}
|
||||
|
||||
func manifestMerger(ctx android.ModuleContext, manifest android.Path, staticLibManifests android.Paths) android.Path {
|
||||
mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: manifestMergerRule,
|
||||
Description: "merge manifest",
|
||||
Input: manifest,
|
||||
Implicits: staticLibManifests,
|
||||
Output: mergedManifest,
|
||||
Args: map[string]string{
|
||||
"libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "),
|
||||
},
|
||||
})
|
||||
|
||||
return mergedManifest
|
||||
}
|
||||
|
|
|
@ -386,7 +386,7 @@ func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
|
|||
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
|
||||
fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
|
||||
fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.mergedManifestFile.String())
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
|
||||
strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
|
||||
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
||||
|
|
Loading…
Reference in New Issue