Merge changes Id93bcaea,Ia8f9f910
* changes: Pass --remove-tools-declarations to manifest merger Don't use merged manifest for android_library modules
This commit is contained in:
commit
02cbe8f1c6
3 changed files with 74 additions and 47 deletions
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, a.isLibrary)
|
||||
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 {
|
||||
|
|
|
@ -36,13 +36,14 @@ var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer",
|
|||
|
||||
var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
|
||||
blueprint.RuleParams{
|
||||
Command: `${config.ManifestMergerCmd} --main $in $libs --out $out`,
|
||||
Command: `${config.ManifestMergerCmd} $args --main $in $libs --out $out`,
|
||||
CommandDeps: []string{"${config.ManifestMergerCmd}"},
|
||||
},
|
||||
"libs")
|
||||
"args", "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,44 @@ 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 fixedManifest
|
||||
}
|
||||
|
||||
func manifestMerger(ctx android.ModuleContext, manifest android.Path, staticLibManifests android.Paths,
|
||||
isLibrary bool) android.Path {
|
||||
|
||||
var args string
|
||||
if !isLibrary {
|
||||
// Follow Gradle's behavior, only pass --remove-tools-declarations when merging app manifests.
|
||||
args = "--remove-tools-declarations"
|
||||
}
|
||||
|
||||
return manifest
|
||||
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 "),
|
||||
"args": args,
|
||||
},
|
||||
})
|
||||
|
||||
return mergedManifest
|
||||
}
|
||||
|
|
|
@ -390,7 +390,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 a new issue