2018-02-21 02:22:23 +01:00
|
|
|
// Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2019-02-20 01:59:53 +01:00
|
|
|
"fmt"
|
2019-06-18 02:40:56 +02:00
|
|
|
"path/filepath"
|
2018-03-28 23:58:31 +02:00
|
|
|
"strings"
|
2018-02-21 02:22:23 +01:00
|
|
|
|
2020-01-18 19:33:43 +01:00
|
|
|
"android/soong/android"
|
|
|
|
|
2018-02-21 02:22:23 +01:00
|
|
|
"github.com/google/blueprint"
|
2018-03-28 23:58:31 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2018-02-21 02:22:23 +01:00
|
|
|
)
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
type AndroidLibraryDependency interface {
|
|
|
|
Dependency
|
|
|
|
ExportPackage() android.Path
|
2018-05-01 00:55:11 +02:00
|
|
|
ExportedProguardFlagFiles() android.Paths
|
2019-03-18 16:53:16 +01:00
|
|
|
ExportedRRODirs() []rroDir
|
2018-05-02 21:58:28 +02:00
|
|
|
ExportedStaticPackages() android.Paths
|
2019-04-20 01:22:57 +02:00
|
|
|
ExportedManifests() android.Paths
|
2020-01-15 23:15:10 +01:00
|
|
|
ExportedAssets() android.OptionalPath
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
2018-02-21 02:22:23 +01:00
|
|
|
func init() {
|
2019-12-18 20:51:55 +01:00
|
|
|
RegisterAARBuildComponents(android.InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterAARBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("android_library_import", AARImportFactory)
|
|
|
|
ctx.RegisterModuleType("android_library", AndroidLibraryFactory)
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// AAR (android library)
|
|
|
|
//
|
|
|
|
|
|
|
|
type androidLibraryProperties struct {
|
|
|
|
BuildAAR bool `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type aaptProperties struct {
|
|
|
|
// flags passed to aapt when creating the apk
|
|
|
|
Aaptflags []string
|
|
|
|
|
2018-10-25 05:24:57 +02:00
|
|
|
// include all resource configurations, not just the product-configured
|
|
|
|
// ones.
|
|
|
|
Aapt_include_all_resources *bool
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
// list of directories relative to the Blueprints file containing assets.
|
2019-02-08 00:30:01 +01:00
|
|
|
// Defaults to ["assets"] if a directory called assets exists. Set to []
|
|
|
|
// to disable the default.
|
2018-03-28 23:58:31 +02:00
|
|
|
Asset_dirs []string
|
|
|
|
|
|
|
|
// list of directories relative to the Blueprints file containing
|
2019-02-08 00:30:01 +01:00
|
|
|
// Android resources. Defaults to ["res"] if a directory called res exists.
|
|
|
|
// Set to [] to disable the default.
|
2018-03-28 23:58:31 +02:00
|
|
|
Resource_dirs []string
|
|
|
|
|
2019-02-20 01:59:53 +01:00
|
|
|
// list of zip files containing Android resources.
|
2019-03-05 07:35:41 +01:00
|
|
|
Resource_zips []string `android:"path"`
|
2019-02-20 01:59:53 +01:00
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
// path to AndroidManifest.xml. If unset, defaults to "AndroidManifest.xml".
|
2019-03-05 07:35:41 +01:00
|
|
|
Manifest *string `android:"path"`
|
2019-08-08 11:37:17 +02:00
|
|
|
|
|
|
|
// paths to additional manifest files to merge with main manifest.
|
|
|
|
Additional_manifests []string `android:"path"`
|
2019-10-28 23:50:06 +01:00
|
|
|
|
|
|
|
// do not include AndroidManifest from dependent libraries
|
|
|
|
Dont_merge_manifests *bool
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type aapt struct {
|
2019-04-20 01:22:57 +02:00
|
|
|
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
|
2019-06-18 02:40:56 +02:00
|
|
|
noticeFile android.OptionalPath
|
2020-01-15 23:15:10 +01:00
|
|
|
assetPackage android.OptionalPath
|
2019-04-20 01:22:57 +02:00
|
|
|
isLibrary bool
|
2019-05-01 22:16:22 +02:00
|
|
|
useEmbeddedNativeLibs bool
|
2019-04-20 01:22:57 +02:00
|
|
|
useEmbeddedDex bool
|
|
|
|
usesNonSdkApis bool
|
2019-05-22 19:46:27 +02:00
|
|
|
sdkLibraries []string
|
2019-05-31 00:51:14 +02:00
|
|
|
hasNoCode bool
|
2020-02-12 02:27:19 +01:00
|
|
|
LoggingParent string
|
2018-03-28 23:58:31 +02:00
|
|
|
|
2019-03-20 00:03:11 +01:00
|
|
|
splitNames []string
|
|
|
|
splits []split
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
aaptProperties aaptProperties
|
|
|
|
}
|
|
|
|
|
2019-03-20 00:03:11 +01:00
|
|
|
type split struct {
|
|
|
|
name string
|
|
|
|
suffix string
|
|
|
|
path android.Path
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
func (a *aapt) ExportPackage() android.Path {
|
|
|
|
return a.exportPackage
|
|
|
|
}
|
|
|
|
|
2019-03-18 16:53:16 +01:00
|
|
|
func (a *aapt) ExportedRRODirs() []rroDir {
|
2019-01-31 20:42:41 +01:00
|
|
|
return a.rroDirs
|
|
|
|
}
|
|
|
|
|
2019-04-20 01:22:57 +02:00
|
|
|
func (a *aapt) ExportedManifests() android.Paths {
|
|
|
|
return a.transitiveManifestPaths
|
2019-01-31 20:42:41 +01:00
|
|
|
}
|
|
|
|
|
2020-01-15 23:15:10 +01:00
|
|
|
func (a *aapt) ExportedAssets() android.OptionalPath {
|
|
|
|
return a.assetPackage
|
|
|
|
}
|
|
|
|
|
2019-06-22 21:59:27 +02:00
|
|
|
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext,
|
|
|
|
manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths,
|
|
|
|
resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
hasVersionCode := false
|
|
|
|
hasVersionName := false
|
|
|
|
for _, f := range a.aaptProperties.Aaptflags {
|
|
|
|
if strings.HasPrefix(f, "--version-code") {
|
|
|
|
hasVersionCode = true
|
|
|
|
} else if strings.HasPrefix(f, "--version-name") {
|
|
|
|
hasVersionName = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flags specified in Android.bp
|
|
|
|
linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
|
|
|
|
|
|
|
|
linkFlags = append(linkFlags, "--no-static-lib-packages")
|
|
|
|
|
|
|
|
// Find implicit or explicit asset and resource dirs
|
|
|
|
assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets")
|
|
|
|
resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res")
|
2019-03-06 07:25:09 +01:00
|
|
|
resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips)
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
// Glob directories into lists of paths
|
|
|
|
for _, dir := range resourceDirs {
|
|
|
|
resDirs = append(resDirs, globbedResourceDir{
|
|
|
|
dir: dir,
|
|
|
|
files: androidResourceGlob(ctx, dir),
|
|
|
|
})
|
|
|
|
resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, dir)
|
|
|
|
overlayDirs = append(overlayDirs, resOverlayDirs...)
|
|
|
|
rroDirs = append(rroDirs, resRRODirs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
var assetFiles android.Paths
|
|
|
|
for _, dir := range assetDirs {
|
|
|
|
assetFiles = append(assetFiles, androidResourceGlob(ctx, dir)...)
|
|
|
|
}
|
|
|
|
|
2019-06-18 02:40:56 +02:00
|
|
|
assetDirStrings := assetDirs.Strings()
|
|
|
|
if a.noticeFile.Valid() {
|
|
|
|
assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String()))
|
|
|
|
assetFiles = append(assetFiles, a.noticeFile.Path())
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
linkFlags = append(linkFlags, "--manifest "+manifestPath.String())
|
|
|
|
linkDeps = append(linkDeps, manifestPath)
|
|
|
|
|
2019-06-18 02:40:56 +02:00
|
|
|
linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A "))
|
2018-03-28 23:58:31 +02:00
|
|
|
linkDeps = append(linkDeps, assetFiles...)
|
|
|
|
|
|
|
|
// SDK version flags
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
minSdkVersion, err := sdkContext.minSdkVersion().effectiveVersionString(ctx)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
|
|
|
|
}
|
2018-03-28 23:58:31 +02:00
|
|
|
|
2018-06-26 00:48:06 +02:00
|
|
|
linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion)
|
|
|
|
linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion)
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
// Version code
|
|
|
|
if !hasVersionCode {
|
|
|
|
linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !hasVersionName {
|
2018-04-25 23:54:06 +02:00
|
|
|
var versionName string
|
|
|
|
if ctx.ModuleName() == "framework-res" {
|
|
|
|
// Some builds set AppsDefaultVersionName() to include the build number ("O-123456"). aapt2 copies the
|
|
|
|
// version name of framework-res into app manifests as compileSdkVersionCodename, which confuses things
|
2018-05-09 20:11:35 +02:00
|
|
|
// if it contains the build number. Use the PlatformVersionName instead.
|
|
|
|
versionName = ctx.Config().PlatformVersionName()
|
2018-04-25 23:54:06 +02:00
|
|
|
} else {
|
|
|
|
versionName = ctx.Config().AppsDefaultVersionName()
|
|
|
|
}
|
2019-02-28 20:00:01 +01:00
|
|
|
versionName = proptools.NinjaEscape(versionName)
|
2018-03-28 23:58:31 +02:00
|
|
|
linkFlags = append(linkFlags, "--version-name ", versionName)
|
|
|
|
}
|
|
|
|
|
2019-06-22 21:59:27 +02:00
|
|
|
linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"})
|
|
|
|
|
|
|
|
// Always set --pseudo-localize, it will be stripped out later for release
|
|
|
|
// builds that don't want it.
|
|
|
|
compileFlags = append(compileFlags, "--pseudo-localize")
|
|
|
|
|
|
|
|
return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 11:44:37 +02:00
|
|
|
func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) {
|
2018-11-15 06:44:17 +01:00
|
|
|
if sdkDep.frameworkResModule != "" {
|
|
|
|
ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
2018-02-21 02:22:23 +01:00
|
|
|
}
|
|
|
|
|
2020-01-15 23:15:10 +01:00
|
|
|
var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`,
|
|
|
|
CommandDeps: []string{"${config.Zip2ZipCmd}"},
|
|
|
|
})
|
|
|
|
|
2018-06-26 00:48:06 +02:00
|
|
|
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
2019-05-22 19:46:27 +02:00
|
|
|
|
2020-01-15 23:15:10 +01:00
|
|
|
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags, sdkLibraries :=
|
2019-05-22 19:46:27 +02:00
|
|
|
aaptLibs(ctx, sdkContext)
|
2018-05-25 01:11:20 +02:00
|
|
|
|
|
|
|
// App manifest file
|
|
|
|
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
|
|
|
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
2018-03-28 23:58:31 +02:00
|
|
|
|
2019-05-22 19:46:27 +02:00
|
|
|
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries,
|
2020-02-12 02:27:19 +01:00
|
|
|
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode,
|
|
|
|
a.LoggingParent)
|
2019-04-20 01:22:57 +02:00
|
|
|
|
2019-09-10 22:13:31 +02:00
|
|
|
// Add additional manifest files to transitive manifests.
|
|
|
|
additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
|
|
|
|
a.transitiveManifestPaths = append(android.Paths{manifestPath}, additionalManifests...)
|
|
|
|
a.transitiveManifestPaths = append(a.transitiveManifestPaths, transitiveStaticLibManifests...)
|
2019-04-20 01:22:57 +02:00
|
|
|
|
2019-10-28 23:50:06 +01:00
|
|
|
if len(a.transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
|
2019-09-10 22:13:31 +02:00
|
|
|
a.mergedManifestFile = manifestMerger(ctx, a.transitiveManifestPaths[0], a.transitiveManifestPaths[1:], a.isLibrary)
|
2019-04-20 01:22:57 +02:00
|
|
|
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
|
|
|
|
}
|
2018-05-25 01:11:20 +02:00
|
|
|
|
2019-06-22 21:59:27 +02:00
|
|
|
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
2018-05-25 01:11:20 +02:00
|
|
|
|
2019-01-31 20:42:41 +01:00
|
|
|
rroDirs = append(rroDirs, staticRRODirs...)
|
2018-05-25 01:11:20 +02:00
|
|
|
linkFlags = append(linkFlags, libFlags...)
|
|
|
|
linkDeps = append(linkDeps, libDeps...)
|
2018-03-28 23:58:31 +02:00
|
|
|
linkFlags = append(linkFlags, extraLinkFlags...)
|
2018-07-24 23:51:30 +02:00
|
|
|
if a.isLibrary {
|
|
|
|
linkFlags = append(linkFlags, "--static-lib")
|
|
|
|
}
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
packageRes := android.PathForModuleOut(ctx, "package-res.apk")
|
2019-08-19 07:56:02 +02:00
|
|
|
// the subdir "android" is required to be filtered by package names
|
|
|
|
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
|
2018-03-28 23:58:31 +02:00
|
|
|
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
|
|
|
rTxt := android.PathForModuleOut(ctx, "R.txt")
|
2018-05-02 21:58:28 +02:00
|
|
|
// This file isn't used by Soong, but is generated for exporting
|
|
|
|
extraPackages := android.PathForModuleOut(ctx, "extra_packages")
|
2018-03-28 23:58:31 +02:00
|
|
|
|
2018-08-22 00:14:37 +02:00
|
|
|
var compiledResDirs []android.Paths
|
2018-03-28 23:58:31 +02:00
|
|
|
for _, dir := range resDirs {
|
2019-06-22 21:59:27 +02:00
|
|
|
compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths())
|
2018-08-22 00:14:37 +02:00
|
|
|
}
|
|
|
|
|
2019-02-20 01:59:53 +01:00
|
|
|
for i, zip := range resZips {
|
|
|
|
flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i))
|
2019-06-22 21:59:27 +02:00
|
|
|
aapt2CompileZip(ctx, flata, zip, "", compileFlags)
|
2019-02-20 01:59:53 +01:00
|
|
|
compiledResDirs = append(compiledResDirs, android.Paths{flata})
|
|
|
|
}
|
|
|
|
|
2018-08-22 00:14:37 +02:00
|
|
|
var compiledRes, compiledOverlay android.Paths
|
|
|
|
|
|
|
|
compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
|
|
|
|
|
2019-02-13 22:15:46 +01:00
|
|
|
if len(transitiveStaticLibs) > 0 {
|
2018-08-22 00:14:37 +02:00
|
|
|
// 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...)
|
|
|
|
}
|
2019-02-13 22:15:46 +01:00
|
|
|
} 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...)
|
|
|
|
}
|
2018-08-22 00:14:37 +02:00
|
|
|
} else if len(compiledResDirs) > 0 {
|
|
|
|
// Without static libraries, the first directory is our directory, which can then be
|
|
|
|
// overlaid by the rest.
|
|
|
|
compiledRes = append(compiledRes, compiledResDirs[0]...)
|
|
|
|
for _, compiledResDir := range compiledResDirs[1:] {
|
|
|
|
compiledOverlay = append(compiledOverlay, compiledResDir...)
|
|
|
|
}
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
2018-08-22 00:14:37 +02:00
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
for _, dir := range overlayDirs {
|
2019-06-22 21:59:27 +02:00
|
|
|
compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...)
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 00:03:11 +01:00
|
|
|
var splitPackages android.WritablePaths
|
|
|
|
var splits []split
|
|
|
|
|
|
|
|
for _, s := range a.splitNames {
|
|
|
|
suffix := strings.Replace(s, ",", "_", -1)
|
|
|
|
path := android.PathForModuleOut(ctx, "package_"+suffix+".apk")
|
|
|
|
linkFlags = append(linkFlags, "--split", path.String()+":"+s)
|
|
|
|
splitPackages = append(splitPackages, path)
|
|
|
|
splits = append(splits, split{
|
|
|
|
name: s,
|
|
|
|
suffix: suffix,
|
|
|
|
path: path,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
|
2020-01-15 23:15:10 +01:00
|
|
|
linkFlags, linkDeps, compiledRes, compiledOverlay, assetPackages, splitPackages)
|
|
|
|
|
|
|
|
// Extract assets from the resource package output so that they can be used later in aapt2link
|
|
|
|
// for modules that depend on this one.
|
|
|
|
if android.PrefixedStringInList(linkFlags, "-A ") || len(assetPackages) > 0 {
|
|
|
|
assets := android.PathForModuleOut(ctx, "assets.zip")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: extractAssetsRule,
|
|
|
|
Input: packageRes,
|
|
|
|
Output: assets,
|
|
|
|
Description: "extract assets from built resource file",
|
|
|
|
})
|
|
|
|
a.assetPackage = android.OptionalPathForPath(assets)
|
|
|
|
}
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
a.aaptSrcJar = srcJar
|
|
|
|
a.exportPackage = packageRes
|
|
|
|
a.manifestPath = manifestPath
|
|
|
|
a.proguardOptionsFile = proguardOptionsFile
|
|
|
|
a.rroDirs = rroDirs
|
2018-05-02 21:58:28 +02:00
|
|
|
a.extraAaptPackagesFile = extraPackages
|
2018-03-28 23:58:31 +02:00
|
|
|
a.rTxt = rTxt
|
2019-03-20 00:03:11 +01:00
|
|
|
a.splits = splits
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
2019-04-20 01:22:57 +02:00
|
|
|
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths,
|
2020-01-15 23:15:10 +01:00
|
|
|
staticRRODirs []rroDir, assets, deps android.Paths, flags []string, sdkLibraries []string) {
|
2018-05-02 21:58:28 +02:00
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
var sharedLibs android.Paths
|
|
|
|
|
2018-06-26 00:48:06 +02:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext)
|
2018-03-28 23:58:31 +02:00
|
|
|
if sdkDep.useFiles {
|
2018-05-29 23:44:55 +02:00
|
|
|
sharedLibs = append(sharedLibs, sdkDep.jars...)
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
|
|
|
var exportPackage android.Path
|
2018-05-02 21:58:28 +02:00
|
|
|
aarDep, _ := module.(AndroidLibraryDependency)
|
|
|
|
if aarDep != nil {
|
2018-03-28 23:58:31 +02:00
|
|
|
exportPackage = aarDep.ExportPackage()
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ctx.OtherModuleDependencyTag(module) {
|
2018-10-16 01:18:06 +02:00
|
|
|
case instrumentationForTag:
|
|
|
|
// Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
|
2019-05-22 19:46:27 +02:00
|
|
|
case libTag:
|
|
|
|
if exportPackage != nil {
|
|
|
|
sharedLibs = append(sharedLibs, exportPackage)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := module.(SdkLibraryDependency); ok {
|
|
|
|
sdkLibraries = append(sdkLibraries, ctx.OtherModuleName(module))
|
|
|
|
}
|
|
|
|
|
|
|
|
case frameworkResTag:
|
2018-03-28 23:58:31 +02:00
|
|
|
if exportPackage != nil {
|
|
|
|
sharedLibs = append(sharedLibs, exportPackage)
|
|
|
|
}
|
|
|
|
case staticLibTag:
|
|
|
|
if exportPackage != nil {
|
2018-05-02 21:58:28 +02:00
|
|
|
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
2019-02-13 22:15:46 +01:00
|
|
|
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
2019-04-20 01:22:57 +02:00
|
|
|
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
|
2019-05-22 19:46:27 +02:00
|
|
|
sdkLibraries = append(sdkLibraries, aarDep.ExportedSdkLibs()...)
|
2020-01-15 23:15:10 +01:00
|
|
|
if aarDep.ExportedAssets().Valid() {
|
|
|
|
assets = append(assets, aarDep.ExportedAssets().Path())
|
|
|
|
}
|
2019-03-18 16:53:16 +01:00
|
|
|
|
|
|
|
outer:
|
|
|
|
for _, d := range aarDep.ExportedRRODirs() {
|
|
|
|
for _, e := range staticRRODirs {
|
|
|
|
if d.path == e.path {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
staticRRODirs = append(staticRRODirs, d)
|
|
|
|
}
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
deps = append(deps, sharedLibs...)
|
2018-05-02 21:58:28 +02:00
|
|
|
deps = append(deps, transitiveStaticLibs...)
|
2018-03-28 23:58:31 +02:00
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
if len(transitiveStaticLibs) > 0 {
|
2018-03-28 23:58:31 +02:00
|
|
|
flags = append(flags, "--auto-add-overlay")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, sharedLib := range sharedLibs {
|
|
|
|
flags = append(flags, "-I "+sharedLib.String())
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
2019-04-20 01:22:57 +02:00
|
|
|
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
|
2019-05-22 19:46:27 +02:00
|
|
|
sdkLibraries = android.FirstUniqueStrings(sdkLibraries)
|
2018-05-02 21:58:28 +02:00
|
|
|
|
2020-01-15 23:15:10 +01:00
|
|
|
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags, sdkLibraries
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type AndroidLibrary struct {
|
|
|
|
Library
|
|
|
|
aapt
|
|
|
|
|
|
|
|
androidLibraryProperties androidLibraryProperties
|
|
|
|
|
|
|
|
aarFile android.WritablePath
|
2018-05-01 00:55:11 +02:00
|
|
|
|
|
|
|
exportedProguardFlagFiles android.Paths
|
2018-05-02 21:58:28 +02:00
|
|
|
exportedStaticPackages android.Paths
|
2018-05-01 00:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths {
|
|
|
|
return a.exportedProguardFlagFiles
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
func (a *AndroidLibrary) ExportedStaticPackages() android.Paths {
|
|
|
|
return a.exportedStaticPackages
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
|
|
|
|
|
|
|
|
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
a.Module.deps(ctx)
|
2019-06-07 11:44:37 +02:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext(a))
|
|
|
|
if sdkDep.hasFrameworkLibs() {
|
|
|
|
a.aapt.deps(ctx, sdkDep)
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-02-06 06:55:21 +01:00
|
|
|
a.aapt.isLibrary = true
|
2019-05-22 19:46:27 +02:00
|
|
|
a.aapt.sdkLibraries = a.exportedSdkLibs
|
2018-07-24 23:51:30 +02:00
|
|
|
a.aapt.buildActions(ctx, sdkContext(a))
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
ctx.CheckbuildFile(a.proguardOptionsFile)
|
|
|
|
ctx.CheckbuildFile(a.exportPackage)
|
|
|
|
ctx.CheckbuildFile(a.aaptSrcJar)
|
|
|
|
|
|
|
|
// apps manifests are handled by aapt, don't let Module see them
|
|
|
|
a.properties.Manifest = nil
|
|
|
|
|
|
|
|
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
|
|
|
|
a.proguardOptionsFile)
|
|
|
|
|
|
|
|
a.Module.compile(ctx, a.aaptSrcJar)
|
|
|
|
|
2019-01-25 22:20:38 +01:00
|
|
|
a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar")
|
2018-03-28 23:58:31 +02:00
|
|
|
var res android.Paths
|
|
|
|
if a.androidLibraryProperties.BuildAAR {
|
|
|
|
BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res)
|
|
|
|
ctx.CheckbuildFile(a.aarFile)
|
|
|
|
}
|
2018-05-01 00:55:11 +02:00
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(m android.Module) {
|
|
|
|
if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
|
|
|
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
|
2018-05-02 21:58:28 +02:00
|
|
|
a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportPackage())
|
|
|
|
a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportedStaticPackages()...)
|
2018-05-01 00:55:11 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
|
2018-05-02 21:58:28 +02:00
|
|
|
a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages)
|
2018-03-28 23:58:31 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// android_library builds and links sources into a `.jar` file for the device along with Android resources.
|
|
|
|
//
|
|
|
|
// An android_library has a single variant that produces a `.jar` file containing `.class` files that were
|
|
|
|
// compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled
|
|
|
|
// with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of
|
|
|
|
// an android_app module.
|
2018-03-28 23:58:31 +02:00
|
|
|
func AndroidLibraryFactory() android.Module {
|
|
|
|
module := &AndroidLibrary{}
|
|
|
|
|
|
|
|
module.AddProperties(
|
|
|
|
&module.Module.properties,
|
|
|
|
&module.Module.deviceProperties,
|
2018-11-12 19:13:39 +01:00
|
|
|
&module.Module.dexpreoptProperties,
|
2018-03-28 23:58:31 +02:00
|
|
|
&module.Module.protoProperties,
|
|
|
|
&module.aaptProperties,
|
|
|
|
&module.androidLibraryProperties)
|
|
|
|
|
|
|
|
module.androidLibraryProperties.BuildAAR = true
|
|
|
|
|
2018-10-02 22:53:33 +02:00
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
2018-03-28 23:58:31 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// AAR (android library) prebuilts
|
|
|
|
//
|
|
|
|
|
2018-02-21 02:22:23 +01:00
|
|
|
type AARImportProperties struct {
|
2019-03-05 07:35:41 +01:00
|
|
|
Aars []string `android:"path"`
|
2018-02-21 02:22:23 +01:00
|
|
|
|
2018-07-10 22:39:30 +02:00
|
|
|
Sdk_version *string
|
|
|
|
Min_sdk_version *string
|
2018-03-28 23:58:31 +02:00
|
|
|
|
|
|
|
Static_libs []string
|
|
|
|
Libs []string
|
2018-08-28 03:31:46 +02:00
|
|
|
|
|
|
|
// if set to true, run Jetifier against .aar file. Defaults to false.
|
2019-03-22 06:21:39 +01:00
|
|
|
Jetifier *bool
|
2018-02-21 02:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type AARImport struct {
|
|
|
|
android.ModuleBase
|
2018-10-02 22:53:33 +02:00
|
|
|
android.DefaultableModuleBase
|
2018-02-21 02:22:23 +01:00
|
|
|
prebuilt android.Prebuilt
|
|
|
|
|
|
|
|
properties AARImportProperties
|
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
classpathFile android.WritablePath
|
|
|
|
proguardFlags android.WritablePath
|
|
|
|
exportPackage android.WritablePath
|
|
|
|
extraAaptPackagesFile android.WritablePath
|
2018-05-23 19:59:28 +02:00
|
|
|
manifest android.WritablePath
|
2018-05-02 21:58:28 +02:00
|
|
|
|
|
|
|
exportedStaticPackages android.Paths
|
2018-02-21 02:22:23 +01:00
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (a *AARImport) sdkVersion() sdkSpec {
|
|
|
|
return sdkSpecFrom(String(a.properties.Sdk_version))
|
2018-06-26 00:48:06 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 14:50:28 +02:00
|
|
|
func (a *AARImport) systemModules() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (a *AARImport) minSdkVersion() sdkSpec {
|
2018-07-10 22:39:30 +02:00
|
|
|
if a.properties.Min_sdk_version != nil {
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
return sdkSpecFrom(*a.properties.Min_sdk_version)
|
2018-07-10 22:39:30 +02:00
|
|
|
}
|
2018-06-26 00:48:06 +02:00
|
|
|
return a.sdkVersion()
|
|
|
|
}
|
|
|
|
|
Abstract sdk_version string using sdkSpec type
The value format that sdk_version (and min_sdk_version, etc.) can have
has consistently evolved and is quite complicated. Furthermore, with the
Mainline module effort, we are expected to have more sdk_versions like
'module-app-current', 'module-lib-current', etc.
The goal of this change is to abstract the various sdk versions, which
are currently represented in string and is parsed in various places,
into a type called sdkSpec, so that adding new sdk veresions becomes
easier than before.
The sdk_version string is now parsed in only one place 'SdkSpecFrom', in
which it is converted into the sdkSpec struct. The struct type provides
several methods that again converts sdkSpec into context-specific
information such as the effective version number, etc.
Bug: 146757305
Bug: 147879031
Test: m
Change-Id: I252f3706544f00ea71c61c23460f07561dd28ab0
2020-01-20 18:03:43 +01:00
|
|
|
func (a *AARImport) targetSdkVersion() sdkSpec {
|
2018-10-31 23:28:47 +01:00
|
|
|
return a.sdkVersion()
|
|
|
|
}
|
2019-06-07 11:44:37 +02:00
|
|
|
|
2019-10-28 19:37:20 +01:00
|
|
|
func (a *AARImport) javaVersion() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
var _ AndroidLibraryDependency = (*AARImport)(nil)
|
|
|
|
|
|
|
|
func (a *AARImport) ExportPackage() android.Path {
|
|
|
|
return a.exportPackage
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:55:11 +02:00
|
|
|
func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
|
|
|
|
return android.Paths{a.proguardFlags}
|
|
|
|
}
|
|
|
|
|
2019-03-18 16:53:16 +01:00
|
|
|
func (a *AARImport) ExportedRRODirs() []rroDir {
|
2019-01-31 20:42:41 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
func (a *AARImport) ExportedStaticPackages() android.Paths {
|
|
|
|
return a.exportedStaticPackages
|
|
|
|
}
|
|
|
|
|
2019-04-20 01:22:57 +02:00
|
|
|
func (a *AARImport) ExportedManifests() android.Paths {
|
|
|
|
return android.Paths{a.manifest}
|
2018-05-25 01:11:20 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 23:15:10 +01:00
|
|
|
// TODO(jungjw): Decide whether we want to implement this.
|
|
|
|
func (a *AARImport) ExportedAssets() android.OptionalPath {
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
|
|
|
|
2018-02-21 02:22:23 +01:00
|
|
|
func (a *AARImport) Prebuilt() *android.Prebuilt {
|
|
|
|
return &a.prebuilt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AARImport) Name() string {
|
|
|
|
return a.prebuilt.Name(a.ModuleBase.Name())
|
|
|
|
}
|
|
|
|
|
2020-01-08 05:35:43 +01:00
|
|
|
func (a *AARImport) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-21 02:22:23 +01:00
|
|
|
func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2019-04-18 23:27:12 +02:00
|
|
|
if !ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
2018-06-26 00:48:06 +02:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext(a))
|
2018-03-28 23:58:31 +02:00
|
|
|
if sdkDep.useModule && sdkDep.frameworkResModule != "" {
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
|
2018-02-21 02:22:23 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-28 23:58:31 +02:00
|
|
|
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...)
|
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...)
|
2018-02-21 02:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unzip an AAR into its constituent files and directories. Any files in Outputs that don't exist in the AAR will be
|
2019-05-28 23:49:06 +02:00
|
|
|
// touched to create an empty file. The res directory is not extracted, as it will be extracted in its own rule.
|
2018-02-21 02:22:23 +01:00
|
|
|
var unzipAAR = pctx.AndroidStaticRule("unzipAAR",
|
|
|
|
blueprint.RuleParams{
|
2019-05-28 23:49:06 +02:00
|
|
|
Command: `rm -rf $outDir && mkdir -p $outDir && ` +
|
|
|
|
`unzip -qo -d $outDir $in && rm -rf $outDir/res && touch $out`,
|
2018-02-21 02:22:23 +01:00
|
|
|
},
|
2019-05-28 23:49:06 +02:00
|
|
|
"outDir")
|
2018-02-21 02:22:23 +01:00
|
|
|
|
|
|
|
func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
if len(a.properties.Aars) != 1 {
|
|
|
|
ctx.PropertyErrorf("aars", "exactly one aar is required")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-28 03:31:46 +02:00
|
|
|
aarName := ctx.ModuleName() + ".aar"
|
|
|
|
var aar android.Path
|
|
|
|
aar = android.PathForModuleSrc(ctx, a.properties.Aars[0])
|
2019-03-22 06:21:39 +01:00
|
|
|
if Bool(a.properties.Jetifier) {
|
2018-08-28 03:31:46 +02:00
|
|
|
inputFile := aar
|
|
|
|
aar = android.PathForModuleOut(ctx, "jetifier", aarName)
|
|
|
|
TransformJetifier(ctx, aar.(android.WritablePath), inputFile)
|
|
|
|
}
|
2018-02-21 02:22:23 +01:00
|
|
|
|
|
|
|
extractedAARDir := android.PathForModuleOut(ctx, "aar")
|
|
|
|
a.classpathFile = extractedAARDir.Join(ctx, "classes.jar")
|
|
|
|
a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt")
|
2018-05-23 19:59:28 +02:00
|
|
|
a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml")
|
2018-02-21 02:22:23 +01:00
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: unzipAAR,
|
|
|
|
Input: aar,
|
2018-05-23 19:59:28 +02:00
|
|
|
Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest},
|
2018-02-21 02:22:23 +01:00
|
|
|
Description: "unzip AAR",
|
|
|
|
Args: map[string]string{
|
2019-05-28 23:49:06 +02:00
|
|
|
"outDir": extractedAARDir.String(),
|
2018-02-21 02:22:23 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-06-22 21:59:27 +02:00
|
|
|
// Always set --pseudo-localize, it will be stripped out later for release
|
|
|
|
// builds that don't want it.
|
|
|
|
compileFlags := []string{"--pseudo-localize"}
|
2018-02-21 02:22:23 +01:00
|
|
|
compiledResDir := android.PathForModuleOut(ctx, "flat-res")
|
|
|
|
flata := compiledResDir.Join(ctx, "gen_res.flata")
|
2019-06-22 21:59:27 +02:00
|
|
|
aapt2CompileZip(ctx, flata, aar, "res", compileFlags)
|
2018-02-21 02:22:23 +01:00
|
|
|
|
|
|
|
a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
|
2019-08-19 07:56:02 +02:00
|
|
|
// the subdir "android" is required to be filtered by package names
|
|
|
|
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
|
2018-02-21 02:22:23 +01:00
|
|
|
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
2018-03-28 23:58:31 +02:00
|
|
|
rTxt := android.PathForModuleOut(ctx, "R.txt")
|
2018-05-02 21:58:28 +02:00
|
|
|
a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
|
2018-02-21 02:22:23 +01:00
|
|
|
|
|
|
|
var linkDeps android.Paths
|
|
|
|
|
|
|
|
linkFlags := []string{
|
|
|
|
"--static-lib",
|
|
|
|
"--no-static-lib-packages",
|
|
|
|
"--auto-add-overlay",
|
|
|
|
}
|
|
|
|
|
2018-05-23 19:59:28 +02:00
|
|
|
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
|
|
|
linkDeps = append(linkDeps, a.manifest)
|
2018-02-21 02:22:23 +01:00
|
|
|
|
2020-01-15 23:15:10 +01:00
|
|
|
transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags, sdkLibraries :=
|
2019-05-22 19:46:27 +02:00
|
|
|
aaptLibs(ctx, sdkContext(a))
|
2018-05-25 01:11:20 +02:00
|
|
|
|
|
|
|
_ = staticLibManifests
|
2019-01-31 20:42:41 +01:00
|
|
|
_ = staticRRODirs
|
2019-05-22 19:46:27 +02:00
|
|
|
_ = sdkLibraries
|
2018-02-21 02:22:23 +01:00
|
|
|
|
2018-03-28 23:58:31 +02:00
|
|
|
linkDeps = append(linkDeps, libDeps...)
|
|
|
|
linkFlags = append(linkFlags, libFlags...)
|
2018-02-21 02:22:23 +01:00
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
overlayRes := append(android.Paths{flata}, transitiveStaticLibs...)
|
2018-02-21 02:22:23 +01:00
|
|
|
|
2018-05-02 21:58:28 +02:00
|
|
|
aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
|
2020-01-15 23:15:10 +01:00
|
|
|
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
|
2018-02-21 02:22:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ Dependency = (*AARImport)(nil)
|
|
|
|
|
|
|
|
func (a *AARImport) HeaderJars() android.Paths {
|
|
|
|
return android.Paths{a.classpathFile}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AARImport) ImplementationJars() android.Paths {
|
|
|
|
return android.Paths{a.classpathFile}
|
|
|
|
}
|
|
|
|
|
2018-08-16 05:40:52 +02:00
|
|
|
func (a *AARImport) ResourceJars() android.Paths {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
|
|
|
|
return android.Paths{a.classpathFile}
|
|
|
|
}
|
|
|
|
|
2019-01-31 23:12:44 +01:00
|
|
|
func (a *AARImport) DexJar() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-21 02:22:23 +01:00
|
|
|
func (a *AARImport) AidlIncludeDirs() android.Paths {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-28 11:02:19 +02:00
|
|
|
func (a *AARImport) ExportedSdkLibs() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-26 19:08:34 +01:00
|
|
|
func (d *AARImport) ExportedPlugins() (android.Paths, []string) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:28:19 +02:00
|
|
|
func (a *AARImport) SrcJarArgs() ([]string, android.Paths) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-02-21 02:22:23 +01:00
|
|
|
var _ android.PrebuiltInterface = (*Import)(nil)
|
|
|
|
|
2019-02-12 23:41:32 +01:00
|
|
|
// android_library_import imports an `.aar` file into the build graph as if it was built with android_library.
|
|
|
|
//
|
|
|
|
// This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of
|
|
|
|
// an android_app module.
|
2018-02-21 02:22:23 +01:00
|
|
|
func AARImportFactory() android.Module {
|
|
|
|
module := &AARImport{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Aars)
|
2018-10-02 22:53:33 +02:00
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
2018-02-21 02:22:23 +01:00
|
|
|
return module
|
|
|
|
}
|