Merge "Add <uses-library> tags for SDK libraries to AndroidManifest.xml"
am: f0cbace3b2
Change-Id: I06bcac637ed1a660150fe6d2818fd4982a5df6c4
This commit is contained in:
commit
a5a6493eaf
29
java/aar.go
29
java/aar.go
|
@ -84,6 +84,7 @@ type aapt struct {
|
|||
useEmbeddedNativeLibs bool
|
||||
useEmbeddedDex bool
|
||||
usesNonSdkApis bool
|
||||
sdkLibraries []string
|
||||
|
||||
splitNames []string
|
||||
splits []split
|
||||
|
@ -194,13 +195,15 @@ func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) {
|
|||
}
|
||||
|
||||
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
||||
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext)
|
||||
|
||||
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, libDeps, libFlags, sdkLibraries :=
|
||||
aaptLibs(ctx, sdkContext)
|
||||
|
||||
// App manifest file
|
||||
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
||||
|
||||
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext,
|
||||
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries,
|
||||
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex)
|
||||
|
||||
a.transitiveManifestPaths = append(android.Paths{manifestPath}, transitiveStaticLibManifests...)
|
||||
|
@ -303,7 +306,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, transitiveStaticLibManifests android.Paths,
|
||||
staticRRODirs []rroDir, deps android.Paths, flags []string) {
|
||||
staticRRODirs []rroDir, deps android.Paths, flags []string, sdkLibraries []string) {
|
||||
|
||||
var sharedLibs android.Paths
|
||||
|
||||
|
@ -322,7 +325,16 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||
switch ctx.OtherModuleDependencyTag(module) {
|
||||
case instrumentationForTag:
|
||||
// Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
|
||||
case libTag, frameworkResTag:
|
||||
case libTag:
|
||||
if exportPackage != nil {
|
||||
sharedLibs = append(sharedLibs, exportPackage)
|
||||
}
|
||||
|
||||
if _, ok := module.(SdkLibraryDependency); ok {
|
||||
sdkLibraries = append(sdkLibraries, ctx.OtherModuleName(module))
|
||||
}
|
||||
|
||||
case frameworkResTag:
|
||||
if exportPackage != nil {
|
||||
sharedLibs = append(sharedLibs, exportPackage)
|
||||
}
|
||||
|
@ -331,6 +343,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
|
||||
sdkLibraries = append(sdkLibraries, aarDep.ExportedSdkLibs()...)
|
||||
|
||||
outer:
|
||||
for _, d := range aarDep.ExportedRRODirs() {
|
||||
|
@ -358,8 +371,9 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
|||
|
||||
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
||||
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
|
||||
sdkLibraries = android.FirstUniqueStrings(sdkLibraries)
|
||||
|
||||
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, deps, flags
|
||||
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, deps, flags, sdkLibraries
|
||||
}
|
||||
|
||||
type AndroidLibrary struct {
|
||||
|
@ -393,6 +407,7 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||
|
||||
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.aapt.isLibrary = true
|
||||
a.aapt.sdkLibraries = a.exportedSdkLibs
|
||||
a.aapt.buildActions(ctx, sdkContext(a))
|
||||
|
||||
ctx.CheckbuildFile(a.proguardOptionsFile)
|
||||
|
@ -603,10 +618,12 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
||||
linkDeps = append(linkDeps, a.manifest)
|
||||
|
||||
transitiveStaticLibs, staticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext(a))
|
||||
transitiveStaticLibs, staticLibManifests, staticRRODirs, libDeps, libFlags, sdkLibraries :=
|
||||
aaptLibs(ctx, sdkContext(a))
|
||||
|
||||
_ = staticLibManifests
|
||||
_ = staticRRODirs
|
||||
_ = sdkLibraries
|
||||
|
||||
linkDeps = append(linkDeps, libDeps...)
|
||||
linkFlags = append(linkFlags, libFlags...)
|
||||
|
|
|
@ -41,8 +41,18 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
|
|||
},
|
||||
"args", "libs")
|
||||
|
||||
// These two libs are added as optional dependencies (<uses-library> with
|
||||
// android:required set to false). This is because they haven't existed in pre-P
|
||||
// devices, but classes in them were in bootclasspath jars, etc. So making them
|
||||
// hard dependencies (android:required=true) would prevent apps from being
|
||||
// installed to such legacy devices.
|
||||
var optionalUsesLibs = []string{
|
||||
"android.test.base",
|
||||
"android.test.mock",
|
||||
}
|
||||
|
||||
// Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
|
||||
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
|
||||
func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, sdkLibraries []string,
|
||||
isLibrary, useEmbeddedNativeLibs, usesNonSdkApis, useEmbeddedDex bool) android.Path {
|
||||
|
||||
var args []string
|
||||
|
@ -69,6 +79,14 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
|
|||
args = append(args, "--use-embedded-dex")
|
||||
}
|
||||
|
||||
for _, usesLib := range sdkLibraries {
|
||||
if inList(usesLib, optionalUsesLibs) {
|
||||
args = append(args, "--optional-uses-library", usesLib)
|
||||
} else {
|
||||
args = append(args, "--uses-library", usesLib)
|
||||
}
|
||||
}
|
||||
|
||||
var deps android.Paths
|
||||
targetSdkVersion := sdkVersionOrDefault(ctx, sdkContext.targetSdkVersion())
|
||||
if targetSdkVersion == ctx.Config().PlatformSdkCodename() &&
|
||||
|
|
Loading…
Reference in New Issue