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:
61
java/aar.go
61
java/aar.go
@@ -29,7 +29,7 @@ type AndroidLibraryDependency interface {
|
|||||||
ExportedProguardFlagFiles() android.Paths
|
ExportedProguardFlagFiles() android.Paths
|
||||||
ExportedRRODirs() []rroDir
|
ExportedRRODirs() []rroDir
|
||||||
ExportedStaticPackages() android.Paths
|
ExportedStaticPackages() android.Paths
|
||||||
ExportedManifest() android.Path
|
ExportedManifests() android.Paths
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -71,17 +71,19 @@ type aaptProperties struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type aapt struct {
|
type aapt struct {
|
||||||
aaptSrcJar android.Path
|
aaptSrcJar android.Path
|
||||||
exportPackage android.Path
|
exportPackage android.Path
|
||||||
manifestPath android.Path
|
manifestPath android.Path
|
||||||
proguardOptionsFile android.Path
|
transitiveManifestPaths android.Paths
|
||||||
rroDirs []rroDir
|
proguardOptionsFile android.Path
|
||||||
rTxt android.Path
|
rroDirs []rroDir
|
||||||
extraAaptPackagesFile android.Path
|
rTxt android.Path
|
||||||
isLibrary bool
|
extraAaptPackagesFile android.Path
|
||||||
uncompressedJNI bool
|
mergedManifestFile android.Path
|
||||||
useEmbeddedDex bool
|
isLibrary bool
|
||||||
usesNonSdkApis bool
|
uncompressedJNI bool
|
||||||
|
useEmbeddedDex bool
|
||||||
|
usesNonSdkApis bool
|
||||||
|
|
||||||
splitNames []string
|
splitNames []string
|
||||||
splits []split
|
splits []split
|
||||||
@@ -103,8 +105,8 @@ func (a *aapt) ExportedRRODirs() []rroDir {
|
|||||||
return a.rroDirs
|
return a.rroDirs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) ExportedManifest() android.Path {
|
func (a *aapt) ExportedManifests() android.Paths {
|
||||||
return a.manifestPath
|
return a.transitiveManifestPaths
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string,
|
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) {
|
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
|
// App manifest file
|
||||||
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||||
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
||||||
|
|
||||||
manifestPath := manifestMerger(ctx, manifestSrcPath, sdkContext, staticLibManifests, a.isLibrary,
|
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext,
|
||||||
a.uncompressedJNI, a.useEmbeddedDex, a.usesNonSdkApis)
|
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)
|
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
|
// 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) {
|
staticRRODirs []rroDir, deps android.Paths, flags []string) {
|
||||||
|
|
||||||
var sharedLibs android.Paths
|
var sharedLibs android.Paths
|
||||||
@@ -314,7 +330,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||||||
if exportPackage != nil {
|
if exportPackage != nil {
|
||||||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
||||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||||
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest())
|
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for _, d := range aarDep.ExportedRRODirs() {
|
for _, d := range aarDep.ExportedRRODirs() {
|
||||||
@@ -341,8 +357,9 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||||||
}
|
}
|
||||||
|
|
||||||
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
||||||
|
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
|
||||||
|
|
||||||
return transitiveStaticLibs, staticLibManifests, staticRRODirs, deps, flags
|
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, deps, flags
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidLibrary struct {
|
type AndroidLibrary struct {
|
||||||
@@ -498,8 +515,8 @@ func (a *AARImport) ExportedStaticPackages() android.Paths {
|
|||||||
return a.exportedStaticPackages
|
return a.exportedStaticPackages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) ExportedManifest() android.Path {
|
func (a *AARImport) ExportedManifests() android.Paths {
|
||||||
return a.manifest
|
return android.Paths{a.manifest}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) Prebuilt() *android.Prebuilt {
|
func (a *AARImport) Prebuilt() *android.Prebuilt {
|
||||||
|
@@ -41,8 +41,9 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
|
|||||||
},
|
},
|
||||||
"libs")
|
"libs")
|
||||||
|
|
||||||
func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
|
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
|
||||||
staticLibManifests android.Paths, isLibrary, uncompressedJNI, useEmbeddedDex, usesNonSdkApis bool) android.Path {
|
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
|
||||||
|
isLibrary, uncompressedJNI, usesNonSdkApis, useEmbeddedDex bool) android.Path {
|
||||||
|
|
||||||
var args []string
|
var args []string
|
||||||
if isLibrary {
|
if isLibrary {
|
||||||
@@ -79,35 +80,35 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext
|
|||||||
deps = append(deps, apiFingerprint)
|
deps = append(deps, apiFingerprint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject minSdkVersion into the manifest
|
|
||||||
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
|
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: manifestFixerRule,
|
Rule: manifestFixerRule,
|
||||||
Input: manifest,
|
Description: "fix manifest",
|
||||||
Implicits: deps,
|
Input: manifest,
|
||||||
Output: fixedManifest,
|
Implicits: deps,
|
||||||
|
Output: fixedManifest,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
|
"minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
|
||||||
"targetSdkVersion": targetSdkVersion,
|
"targetSdkVersion": targetSdkVersion,
|
||||||
"args": strings.Join(args, " "),
|
"args": strings.Join(args, " "),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
manifest = fixedManifest
|
|
||||||
|
|
||||||
// Merge static aar dependency manifests if necessary
|
return fixedManifest
|
||||||
if len(staticLibManifests) > 0 {
|
}
|
||||||
mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
func manifestMerger(ctx android.ModuleContext, manifest android.Path, staticLibManifests android.Paths) android.Path {
|
||||||
Rule: manifestMergerRule,
|
mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
|
||||||
Input: manifest,
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Implicits: staticLibManifests,
|
Rule: manifestMergerRule,
|
||||||
Output: mergedManifest,
|
Description: "merge manifest",
|
||||||
Args: map[string]string{
|
Input: manifest,
|
||||||
"libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "),
|
Implicits: staticLibManifests,
|
||||||
},
|
Output: mergedManifest,
|
||||||
})
|
Args: map[string]string{
|
||||||
manifest = mergedManifest
|
"libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "),
|
||||||
}
|
},
|
||||||
|
})
|
||||||
return manifest
|
|
||||||
|
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_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
|
||||||
fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.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 :=",
|
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
|
||||||
strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
|
strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
|
||||||
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
|
||||||
|
Reference in New Issue
Block a user