2018-02-21 09:22:23 +08: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 08:59:53 +08:00
|
|
|
"fmt"
|
2019-06-18 08:40:56 +08:00
|
|
|
"path/filepath"
|
2018-03-29 05:58:31 +08:00
|
|
|
"strings"
|
2018-02-21 09:22:23 +08:00
|
|
|
|
2020-01-19 02:33:43 +08:00
|
|
|
"android/soong/android"
|
|
|
|
|
2018-02-21 09:22:23 +08:00
|
|
|
"github.com/google/blueprint"
|
2018-03-29 05:58:31 +08:00
|
|
|
"github.com/google/blueprint/proptools"
|
2018-02-21 09:22:23 +08:00
|
|
|
)
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
type AndroidLibraryDependency interface {
|
|
|
|
Dependency
|
|
|
|
ExportPackage() android.Path
|
2018-05-01 06:55:11 +08:00
|
|
|
ExportedProguardFlagFiles() android.Paths
|
2019-03-18 23:53:16 +08:00
|
|
|
ExportedRRODirs() []rroDir
|
2018-05-03 03:58:28 +08:00
|
|
|
ExportedStaticPackages() android.Paths
|
2019-04-20 07:22:57 +08:00
|
|
|
ExportedManifests() android.Paths
|
2020-01-16 06:15:10 +08:00
|
|
|
ExportedAssets() android.OptionalPath
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
2018-02-21 09:22:23 +08:00
|
|
|
func init() {
|
2019-12-19 03:51:55 +08:00
|
|
|
RegisterAARBuildComponents(android.InitRegistrationContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterAARBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("android_library_import", AARImportFactory)
|
|
|
|
ctx.RegisterModuleType("android_library", AndroidLibraryFactory)
|
2018-03-29 05:58:31 +08: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 11:24:57 +08:00
|
|
|
// include all resource configurations, not just the product-configured
|
|
|
|
// ones.
|
|
|
|
Aapt_include_all_resources *bool
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
// list of directories relative to the Blueprints file containing assets.
|
2019-02-08 07:30:01 +08:00
|
|
|
// Defaults to ["assets"] if a directory called assets exists. Set to []
|
|
|
|
// to disable the default.
|
2018-03-29 05:58:31 +08:00
|
|
|
Asset_dirs []string
|
|
|
|
|
|
|
|
// list of directories relative to the Blueprints file containing
|
2019-02-08 07:30:01 +08:00
|
|
|
// Android resources. Defaults to ["res"] if a directory called res exists.
|
|
|
|
// Set to [] to disable the default.
|
2018-03-29 05:58:31 +08:00
|
|
|
Resource_dirs []string
|
|
|
|
|
2019-02-20 08:59:53 +08:00
|
|
|
// list of zip files containing Android resources.
|
2019-03-05 14:35:41 +08:00
|
|
|
Resource_zips []string `android:"path"`
|
2019-02-20 08:59:53 +08:00
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
// path to AndroidManifest.xml. If unset, defaults to "AndroidManifest.xml".
|
2019-03-05 14:35:41 +08:00
|
|
|
Manifest *string `android:"path"`
|
2019-08-08 17:37:17 +08:00
|
|
|
|
|
|
|
// paths to additional manifest files to merge with main manifest.
|
|
|
|
Additional_manifests []string `android:"path"`
|
2019-10-29 06:50:06 +08:00
|
|
|
|
|
|
|
// do not include AndroidManifest from dependent libraries
|
|
|
|
Dont_merge_manifests *bool
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type aapt struct {
|
2019-04-20 07:22:57 +08: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 08:40:56 +08:00
|
|
|
noticeFile android.OptionalPath
|
2020-01-16 06:15:10 +08:00
|
|
|
assetPackage android.OptionalPath
|
2019-04-20 07:22:57 +08:00
|
|
|
isLibrary bool
|
2019-05-02 04:16:22 +08:00
|
|
|
useEmbeddedNativeLibs bool
|
2019-04-20 07:22:57 +08:00
|
|
|
useEmbeddedDex bool
|
|
|
|
usesNonSdkApis bool
|
2019-05-23 01:46:27 +08:00
|
|
|
sdkLibraries []string
|
2019-05-31 06:51:14 +08:00
|
|
|
hasNoCode bool
|
2020-02-12 09:27:19 +08:00
|
|
|
LoggingParent string
|
2020-06-03 11:09:13 +08:00
|
|
|
resourceFiles android.Paths
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2019-03-20 07:03:11 +08:00
|
|
|
splitNames []string
|
|
|
|
splits []split
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
aaptProperties aaptProperties
|
|
|
|
}
|
|
|
|
|
2019-03-20 07:03:11 +08:00
|
|
|
type split struct {
|
|
|
|
name string
|
|
|
|
suffix string
|
|
|
|
path android.Path
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
func (a *aapt) ExportPackage() android.Path {
|
|
|
|
return a.exportPackage
|
|
|
|
}
|
|
|
|
|
2019-03-18 23:53:16 +08:00
|
|
|
func (a *aapt) ExportedRRODirs() []rroDir {
|
2019-02-01 03:42:41 +08:00
|
|
|
return a.rroDirs
|
|
|
|
}
|
|
|
|
|
2019-04-20 07:22:57 +08:00
|
|
|
func (a *aapt) ExportedManifests() android.Paths {
|
|
|
|
return a.transitiveManifestPaths
|
2019-02-01 03:42:41 +08:00
|
|
|
}
|
|
|
|
|
2020-01-16 06:15:10 +08:00
|
|
|
func (a *aapt) ExportedAssets() android.OptionalPath {
|
|
|
|
return a.assetPackage
|
|
|
|
}
|
|
|
|
|
2019-06-23 03:59:27 +08: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-29 05:58:31 +08:00
|
|
|
|
2020-02-11 23:54:35 +08:00
|
|
|
hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code")
|
|
|
|
hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name")
|
2018-03-29 05:58:31 +08:00
|
|
|
|
|
|
|
// 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 14:25:09 +08:00
|
|
|
resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips)
|
2018-03-29 05:58:31 +08: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 08:40:56 +08: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-29 05:58:31 +08:00
|
|
|
linkFlags = append(linkFlags, "--manifest "+manifestPath.String())
|
|
|
|
linkDeps = append(linkDeps, manifestPath)
|
|
|
|
|
2019-06-18 08:40:56 +08:00
|
|
|
linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A "))
|
2018-03-29 05:58:31 +08: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-21 01:03:43 +08:00
|
|
|
minSdkVersion, err := sdkContext.minSdkVersion().effectiveVersionString(ctx)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
|
|
|
|
}
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2018-06-26 06:48:06 +08:00
|
|
|
linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion)
|
|
|
|
linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion)
|
2018-03-29 05:58:31 +08:00
|
|
|
|
|
|
|
// Version code
|
|
|
|
if !hasVersionCode {
|
|
|
|
linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !hasVersionName {
|
2018-04-26 05:54:06 +08: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-10 02:11:35 +08:00
|
|
|
// if it contains the build number. Use the PlatformVersionName instead.
|
|
|
|
versionName = ctx.Config().PlatformVersionName()
|
2018-04-26 05:54:06 +08:00
|
|
|
} else {
|
|
|
|
versionName = ctx.Config().AppsDefaultVersionName()
|
|
|
|
}
|
2019-03-01 03:00:01 +08:00
|
|
|
versionName = proptools.NinjaEscape(versionName)
|
2018-03-29 05:58:31 +08:00
|
|
|
linkFlags = append(linkFlags, "--version-name ", versionName)
|
|
|
|
}
|
|
|
|
|
2019-06-23 03:59:27 +08: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-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
2019-06-07 17:44:37 +08:00
|
|
|
func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) {
|
2018-11-15 13:44:17 +08:00
|
|
|
if sdkDep.frameworkResModule != "" {
|
|
|
|
ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
2018-02-21 09:22:23 +08:00
|
|
|
}
|
|
|
|
|
2020-01-16 06:15:10 +08:00
|
|
|
var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`,
|
|
|
|
CommandDeps: []string{"${config.Zip2ZipCmd}"},
|
|
|
|
})
|
|
|
|
|
2018-06-26 06:48:06 +08:00
|
|
|
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
2019-05-23 01:46:27 +08:00
|
|
|
|
2020-01-16 06:15:10 +08:00
|
|
|
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags, sdkLibraries :=
|
2019-05-23 01:46:27 +08:00
|
|
|
aaptLibs(ctx, sdkContext)
|
2018-05-25 07:11:20 +08:00
|
|
|
|
|
|
|
// App manifest file
|
|
|
|
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
|
|
|
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2019-05-23 01:46:27 +08:00
|
|
|
manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries,
|
2020-02-12 09:27:19 +08:00
|
|
|
a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode,
|
|
|
|
a.LoggingParent)
|
2019-04-20 07:22:57 +08:00
|
|
|
|
2019-09-11 04:13:31 +08: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 07:22:57 +08:00
|
|
|
|
2019-10-29 06:50:06 +08:00
|
|
|
if len(a.transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
|
2019-09-11 04:13:31 +08:00
|
|
|
a.mergedManifestFile = manifestMerger(ctx, a.transitiveManifestPaths[0], a.transitiveManifestPaths[1:], a.isLibrary)
|
2019-04-20 07:22:57 +08: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 07:11:20 +08:00
|
|
|
|
2019-06-23 03:59:27 +08:00
|
|
|
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
2018-05-25 07:11:20 +08:00
|
|
|
|
2019-02-01 03:42:41 +08:00
|
|
|
rroDirs = append(rroDirs, staticRRODirs...)
|
2018-05-25 07:11:20 +08:00
|
|
|
linkFlags = append(linkFlags, libFlags...)
|
|
|
|
linkDeps = append(linkDeps, libDeps...)
|
2018-03-29 05:58:31 +08:00
|
|
|
linkFlags = append(linkFlags, extraLinkFlags...)
|
2018-07-25 05:51:30 +08:00
|
|
|
if a.isLibrary {
|
|
|
|
linkFlags = append(linkFlags, "--static-lib")
|
|
|
|
}
|
2018-03-29 05:58:31 +08:00
|
|
|
|
|
|
|
packageRes := android.PathForModuleOut(ctx, "package-res.apk")
|
2019-08-19 13:56:02 +08:00
|
|
|
// the subdir "android" is required to be filtered by package names
|
|
|
|
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
|
2018-03-29 05:58:31 +08:00
|
|
|
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
|
|
|
rTxt := android.PathForModuleOut(ctx, "R.txt")
|
2018-05-03 03:58:28 +08:00
|
|
|
// This file isn't used by Soong, but is generated for exporting
|
|
|
|
extraPackages := android.PathForModuleOut(ctx, "extra_packages")
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2018-08-22 06:14:37 +08:00
|
|
|
var compiledResDirs []android.Paths
|
2018-03-29 05:58:31 +08:00
|
|
|
for _, dir := range resDirs {
|
2020-06-03 11:09:13 +08:00
|
|
|
a.resourceFiles = append(a.resourceFiles, dir.files...)
|
2019-06-23 03:59:27 +08:00
|
|
|
compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths())
|
2018-08-22 06:14:37 +08:00
|
|
|
}
|
|
|
|
|
2019-02-20 08:59:53 +08:00
|
|
|
for i, zip := range resZips {
|
|
|
|
flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i))
|
2019-06-23 03:59:27 +08:00
|
|
|
aapt2CompileZip(ctx, flata, zip, "", compileFlags)
|
2019-02-20 08:59:53 +08:00
|
|
|
compiledResDirs = append(compiledResDirs, android.Paths{flata})
|
|
|
|
}
|
|
|
|
|
2018-08-22 06:14:37 +08:00
|
|
|
var compiledRes, compiledOverlay android.Paths
|
|
|
|
|
|
|
|
compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
|
|
|
|
|
2019-02-14 05:15:46 +08:00
|
|
|
if len(transitiveStaticLibs) > 0 {
|
2018-08-22 06:14:37 +08: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-14 05:15:46 +08: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 06:14:37 +08: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-29 05:58:31 +08:00
|
|
|
}
|
2018-08-22 06:14:37 +08:00
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
for _, dir := range overlayDirs {
|
2019-06-23 03:59:27 +08:00
|
|
|
compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...)
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
2019-03-20 07:03:11 +08: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-03 03:58:28 +08:00
|
|
|
aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
|
2020-01-16 06:15:10 +08: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.
|
2020-02-11 23:54:35 +08:00
|
|
|
if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 {
|
2020-01-16 06:15:10 +08:00
|
|
|
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-29 05:58:31 +08:00
|
|
|
|
|
|
|
a.aaptSrcJar = srcJar
|
|
|
|
a.exportPackage = packageRes
|
|
|
|
a.manifestPath = manifestPath
|
|
|
|
a.proguardOptionsFile = proguardOptionsFile
|
|
|
|
a.rroDirs = rroDirs
|
2018-05-03 03:58:28 +08:00
|
|
|
a.extraAaptPackagesFile = extraPackages
|
2018-03-29 05:58:31 +08:00
|
|
|
a.rTxt = rTxt
|
2019-03-20 07:03:11 +08:00
|
|
|
a.splits = splits
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
2019-04-20 07:22:57 +08:00
|
|
|
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths,
|
2020-01-16 06:15:10 +08:00
|
|
|
staticRRODirs []rroDir, assets, deps android.Paths, flags []string, sdkLibraries []string) {
|
2018-05-03 03:58:28 +08:00
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
var sharedLibs android.Paths
|
|
|
|
|
2018-06-26 06:48:06 +08:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext)
|
2018-03-29 05:58:31 +08:00
|
|
|
if sdkDep.useFiles {
|
2018-05-30 05:44:55 +08:00
|
|
|
sharedLibs = append(sharedLibs, sdkDep.jars...)
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(module android.Module) {
|
|
|
|
var exportPackage android.Path
|
2018-05-03 03:58:28 +08:00
|
|
|
aarDep, _ := module.(AndroidLibraryDependency)
|
|
|
|
if aarDep != nil {
|
2018-03-29 05:58:31 +08:00
|
|
|
exportPackage = aarDep.ExportPackage()
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ctx.OtherModuleDependencyTag(module) {
|
2018-10-16 07:18:06 +08:00
|
|
|
case instrumentationForTag:
|
|
|
|
// Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
|
2019-05-23 01:46:27 +08:00
|
|
|
case libTag:
|
|
|
|
if exportPackage != nil {
|
|
|
|
sharedLibs = append(sharedLibs, exportPackage)
|
|
|
|
}
|
|
|
|
|
2020-05-15 17:20:31 +08:00
|
|
|
// If the module is (or possibly could be) a component of a java_sdk_library
|
|
|
|
// (including the java_sdk_library) itself then append any implicit sdk library
|
|
|
|
// names to the list of sdk libraries to be added to the manifest.
|
|
|
|
if component, ok := module.(SdkLibraryComponentDependency); ok {
|
|
|
|
sdkLibraries = append(sdkLibraries, component.OptionalImplicitSdkLibrary()...)
|
2019-05-23 01:46:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case frameworkResTag:
|
2018-03-29 05:58:31 +08:00
|
|
|
if exportPackage != nil {
|
|
|
|
sharedLibs = append(sharedLibs, exportPackage)
|
|
|
|
}
|
|
|
|
case staticLibTag:
|
|
|
|
if exportPackage != nil {
|
2018-05-03 03:58:28 +08:00
|
|
|
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
2019-02-14 05:15:46 +08:00
|
|
|
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
2019-04-20 07:22:57 +08:00
|
|
|
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
|
2019-05-23 01:46:27 +08:00
|
|
|
sdkLibraries = append(sdkLibraries, aarDep.ExportedSdkLibs()...)
|
2020-01-16 06:15:10 +08:00
|
|
|
if aarDep.ExportedAssets().Valid() {
|
|
|
|
assets = append(assets, aarDep.ExportedAssets().Path())
|
|
|
|
}
|
2019-03-18 23:53:16 +08:00
|
|
|
|
|
|
|
outer:
|
|
|
|
for _, d := range aarDep.ExportedRRODirs() {
|
|
|
|
for _, e := range staticRRODirs {
|
|
|
|
if d.path == e.path {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
staticRRODirs = append(staticRRODirs, d)
|
|
|
|
}
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
deps = append(deps, sharedLibs...)
|
2018-05-03 03:58:28 +08:00
|
|
|
deps = append(deps, transitiveStaticLibs...)
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2018-05-03 03:58:28 +08:00
|
|
|
if len(transitiveStaticLibs) > 0 {
|
2018-03-29 05:58:31 +08:00
|
|
|
flags = append(flags, "--auto-add-overlay")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, sharedLib := range sharedLibs {
|
|
|
|
flags = append(flags, "-I "+sharedLib.String())
|
|
|
|
}
|
|
|
|
|
2018-05-03 03:58:28 +08:00
|
|
|
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
2019-04-20 07:22:57 +08:00
|
|
|
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
|
2019-05-23 01:46:27 +08:00
|
|
|
sdkLibraries = android.FirstUniqueStrings(sdkLibraries)
|
2018-05-03 03:58:28 +08:00
|
|
|
|
2020-01-16 06:15:10 +08:00
|
|
|
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags, sdkLibraries
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type AndroidLibrary struct {
|
|
|
|
Library
|
|
|
|
aapt
|
|
|
|
|
|
|
|
androidLibraryProperties androidLibraryProperties
|
|
|
|
|
|
|
|
aarFile android.WritablePath
|
2018-05-01 06:55:11 +08:00
|
|
|
|
|
|
|
exportedProguardFlagFiles android.Paths
|
2018-05-03 03:58:28 +08:00
|
|
|
exportedStaticPackages android.Paths
|
2018-05-01 06:55:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths {
|
|
|
|
return a.exportedProguardFlagFiles
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
2018-05-03 03:58:28 +08:00
|
|
|
func (a *AndroidLibrary) ExportedStaticPackages() android.Paths {
|
|
|
|
return a.exportedStaticPackages
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
|
|
|
|
|
|
|
|
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
a.Module.deps(ctx)
|
2019-06-07 17:44:37 +08:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext(a))
|
|
|
|
if sdkDep.hasFrameworkLibs() {
|
|
|
|
a.aapt.deps(ctx, sdkDep)
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-02-06 13:55:21 +08:00
|
|
|
a.aapt.isLibrary = true
|
2019-05-23 01:46:27 +08:00
|
|
|
a.aapt.sdkLibraries = a.exportedSdkLibs
|
2018-07-25 05:51:30 +08:00
|
|
|
a.aapt.buildActions(ctx, sdkContext(a))
|
2018-03-29 05:58:31 +08: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
|
|
|
|
|
2020-06-03 11:09:13 +08:00
|
|
|
a.linter.mergedManifest = a.aapt.mergedManifestFile
|
|
|
|
a.linter.manifest = a.aapt.manifestPath
|
|
|
|
a.linter.resources = a.aapt.resourceFiles
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
|
|
|
|
a.proguardOptionsFile)
|
|
|
|
|
|
|
|
a.Module.compile(ctx, a.aaptSrcJar)
|
|
|
|
|
2019-01-26 05:20:38 +08:00
|
|
|
a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar")
|
2018-03-29 05:58:31 +08: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 06:55:11 +08: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-03 03:58:28 +08:00
|
|
|
a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportPackage())
|
|
|
|
a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportedStaticPackages()...)
|
2018-05-01 06:55:11 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
|
2018-05-03 03:58:28 +08:00
|
|
|
a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages)
|
2018-03-29 05:58:31 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 06:41:32 +08: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-29 05:58:31 +08:00
|
|
|
func AndroidLibraryFactory() android.Module {
|
|
|
|
module := &AndroidLibrary{}
|
|
|
|
|
2020-06-16 07:09:53 +08:00
|
|
|
module.Module.addHostAndDeviceProperties()
|
2018-03-29 05:58:31 +08:00
|
|
|
module.AddProperties(
|
|
|
|
&module.aaptProperties,
|
|
|
|
&module.androidLibraryProperties)
|
|
|
|
|
|
|
|
module.androidLibraryProperties.BuildAAR = true
|
2020-06-03 11:09:13 +08:00
|
|
|
module.Module.linter.library = true
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2020-05-20 08:06:00 +08:00
|
|
|
android.InitApexModule(module)
|
2018-10-03 04:53:33 +08:00
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
2018-03-29 05:58:31 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// AAR (android library) prebuilts
|
|
|
|
//
|
|
|
|
|
2018-02-21 09:22:23 +08:00
|
|
|
type AARImportProperties struct {
|
2019-03-05 14:35:41 +08:00
|
|
|
Aars []string `android:"path"`
|
2018-02-21 09:22:23 +08:00
|
|
|
|
2018-07-11 04:39:30 +08:00
|
|
|
Sdk_version *string
|
|
|
|
Min_sdk_version *string
|
2018-03-29 05:58:31 +08:00
|
|
|
|
|
|
|
Static_libs []string
|
|
|
|
Libs []string
|
2018-08-28 09:31:46 +08:00
|
|
|
|
|
|
|
// if set to true, run Jetifier against .aar file. Defaults to false.
|
2019-03-22 13:21:39 +08:00
|
|
|
Jetifier *bool
|
2018-02-21 09:22:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type AARImport struct {
|
|
|
|
android.ModuleBase
|
2018-10-03 04:53:33 +08:00
|
|
|
android.DefaultableModuleBase
|
2020-05-20 08:06:00 +08:00
|
|
|
android.ApexModuleBase
|
2018-02-21 09:22:23 +08:00
|
|
|
prebuilt android.Prebuilt
|
|
|
|
|
2020-05-20 08:06:00 +08:00
|
|
|
// Functionality common to Module and Import.
|
|
|
|
embeddableInModuleAndImport
|
|
|
|
|
2018-02-21 09:22:23 +08:00
|
|
|
properties AARImportProperties
|
|
|
|
|
2018-05-03 03:58:28 +08:00
|
|
|
classpathFile android.WritablePath
|
|
|
|
proguardFlags android.WritablePath
|
|
|
|
exportPackage android.WritablePath
|
|
|
|
extraAaptPackagesFile android.WritablePath
|
2018-05-24 01:59:28 +08:00
|
|
|
manifest android.WritablePath
|
2018-05-03 03:58:28 +08:00
|
|
|
|
|
|
|
exportedStaticPackages android.Paths
|
2018-02-21 09:22:23 +08: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-21 01:03:43 +08:00
|
|
|
func (a *AARImport) sdkVersion() sdkSpec {
|
|
|
|
return sdkSpecFrom(String(a.properties.Sdk_version))
|
2018-06-26 06:48:06 +08:00
|
|
|
}
|
|
|
|
|
2019-10-11 20:50:28 +08: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-21 01:03:43 +08:00
|
|
|
func (a *AARImport) minSdkVersion() sdkSpec {
|
2018-07-11 04:39:30 +08: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-21 01:03:43 +08:00
|
|
|
return sdkSpecFrom(*a.properties.Min_sdk_version)
|
2018-07-11 04:39:30 +08:00
|
|
|
}
|
2018-06-26 06:48:06 +08: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-21 01:03:43 +08:00
|
|
|
func (a *AARImport) targetSdkVersion() sdkSpec {
|
2018-11-01 06:28:47 +08:00
|
|
|
return a.sdkVersion()
|
|
|
|
}
|
2019-06-07 17:44:37 +08:00
|
|
|
|
2019-10-29 02:37:20 +08:00
|
|
|
func (a *AARImport) javaVersion() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
var _ AndroidLibraryDependency = (*AARImport)(nil)
|
|
|
|
|
|
|
|
func (a *AARImport) ExportPackage() android.Path {
|
|
|
|
return a.exportPackage
|
|
|
|
}
|
|
|
|
|
2018-05-01 06:55:11 +08:00
|
|
|
func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
|
|
|
|
return android.Paths{a.proguardFlags}
|
|
|
|
}
|
|
|
|
|
2019-03-18 23:53:16 +08:00
|
|
|
func (a *AARImport) ExportedRRODirs() []rroDir {
|
2019-02-01 03:42:41 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-03 03:58:28 +08:00
|
|
|
func (a *AARImport) ExportedStaticPackages() android.Paths {
|
|
|
|
return a.exportedStaticPackages
|
|
|
|
}
|
|
|
|
|
2019-04-20 07:22:57 +08:00
|
|
|
func (a *AARImport) ExportedManifests() android.Paths {
|
|
|
|
return android.Paths{a.manifest}
|
2018-05-25 07:11:20 +08:00
|
|
|
}
|
|
|
|
|
2020-01-16 06:15:10 +08:00
|
|
|
// TODO(jungjw): Decide whether we want to implement this.
|
|
|
|
func (a *AARImport) ExportedAssets() android.OptionalPath {
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:22:23 +08: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 12:35:43 +08:00
|
|
|
func (a *AARImport) JacocoReportClassesFile() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:22:23 +08:00
|
|
|
func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2020-07-08 00:09:23 +08:00
|
|
|
if !ctx.Config().AlwaysUsePrebuiltSdks() {
|
2018-06-26 06:48:06 +08:00
|
|
|
sdkDep := decodeSdkDep(ctx, sdkContext(a))
|
2018-03-29 05:58:31 +08:00
|
|
|
if sdkDep.useModule && sdkDep.frameworkResModule != "" {
|
2018-08-30 05:10:52 +08:00
|
|
|
ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
|
2018-02-21 09:22:23 +08:00
|
|
|
}
|
|
|
|
}
|
2018-03-29 05:58:31 +08:00
|
|
|
|
2018-08-30 05:10:52 +08:00
|
|
|
ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...)
|
|
|
|
ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...)
|
2018-02-21 09:22:23 +08: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-29 05:49:06 +08: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 09:22:23 +08:00
|
|
|
var unzipAAR = pctx.AndroidStaticRule("unzipAAR",
|
|
|
|
blueprint.RuleParams{
|
2019-05-29 05:49:06 +08:00
|
|
|
Command: `rm -rf $outDir && mkdir -p $outDir && ` +
|
2020-08-07 04:20:17 +08:00
|
|
|
`unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` +
|
|
|
|
`${config.MergeZipsCmd} $combinedClassesJar $$(ls $outDir/classes.jar 2> /dev/null) $$(ls $outDir/libs/*.jar 2> /dev/null)`,
|
|
|
|
CommandDeps: []string{"${config.MergeZipsCmd}"},
|
2018-02-21 09:22:23 +08:00
|
|
|
},
|
2020-08-07 04:20:17 +08:00
|
|
|
"outDir", "combinedClassesJar")
|
2018-02-21 09:22:23 +08: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 09:31:46 +08:00
|
|
|
aarName := ctx.ModuleName() + ".aar"
|
|
|
|
var aar android.Path
|
|
|
|
aar = android.PathForModuleSrc(ctx, a.properties.Aars[0])
|
2019-03-22 13:21:39 +08:00
|
|
|
if Bool(a.properties.Jetifier) {
|
2018-08-28 09:31:46 +08:00
|
|
|
inputFile := aar
|
|
|
|
aar = android.PathForModuleOut(ctx, "jetifier", aarName)
|
|
|
|
TransformJetifier(ctx, aar.(android.WritablePath), inputFile)
|
|
|
|
}
|
2018-02-21 09:22:23 +08:00
|
|
|
|
|
|
|
extractedAARDir := android.PathForModuleOut(ctx, "aar")
|
2020-08-07 04:20:17 +08:00
|
|
|
a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar")
|
2018-02-21 09:22:23 +08:00
|
|
|
a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt")
|
2018-05-24 01:59:28 +08:00
|
|
|
a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml")
|
2018-02-21 09:22:23 +08:00
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: unzipAAR,
|
|
|
|
Input: aar,
|
2018-05-24 01:59:28 +08:00
|
|
|
Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest},
|
2018-02-21 09:22:23 +08:00
|
|
|
Description: "unzip AAR",
|
|
|
|
Args: map[string]string{
|
2020-08-07 04:20:17 +08:00
|
|
|
"outDir": extractedAARDir.String(),
|
|
|
|
"combinedClassesJar": a.classpathFile.String(),
|
2018-02-21 09:22:23 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-06-23 03:59:27 +08: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 09:22:23 +08:00
|
|
|
compiledResDir := android.PathForModuleOut(ctx, "flat-res")
|
|
|
|
flata := compiledResDir.Join(ctx, "gen_res.flata")
|
2019-06-23 03:59:27 +08:00
|
|
|
aapt2CompileZip(ctx, flata, aar, "res", compileFlags)
|
2018-02-21 09:22:23 +08:00
|
|
|
|
|
|
|
a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
|
2019-08-19 13:56:02 +08:00
|
|
|
// the subdir "android" is required to be filtered by package names
|
|
|
|
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
|
2018-02-21 09:22:23 +08:00
|
|
|
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
2018-03-29 05:58:31 +08:00
|
|
|
rTxt := android.PathForModuleOut(ctx, "R.txt")
|
2018-05-03 03:58:28 +08:00
|
|
|
a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
|
2018-02-21 09:22:23 +08:00
|
|
|
|
|
|
|
var linkDeps android.Paths
|
|
|
|
|
|
|
|
linkFlags := []string{
|
|
|
|
"--static-lib",
|
|
|
|
"--no-static-lib-packages",
|
|
|
|
"--auto-add-overlay",
|
|
|
|
}
|
|
|
|
|
2018-05-24 01:59:28 +08:00
|
|
|
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
|
|
|
linkDeps = append(linkDeps, a.manifest)
|
2018-02-21 09:22:23 +08:00
|
|
|
|
2020-01-16 06:15:10 +08:00
|
|
|
transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags, sdkLibraries :=
|
2019-05-23 01:46:27 +08:00
|
|
|
aaptLibs(ctx, sdkContext(a))
|
2018-05-25 07:11:20 +08:00
|
|
|
|
|
|
|
_ = staticLibManifests
|
2019-02-01 03:42:41 +08:00
|
|
|
_ = staticRRODirs
|
2019-05-23 01:46:27 +08:00
|
|
|
_ = sdkLibraries
|
2018-02-21 09:22:23 +08:00
|
|
|
|
2018-03-29 05:58:31 +08:00
|
|
|
linkDeps = append(linkDeps, libDeps...)
|
|
|
|
linkFlags = append(linkFlags, libFlags...)
|
2018-02-21 09:22:23 +08:00
|
|
|
|
2018-05-03 03:58:28 +08:00
|
|
|
overlayRes := append(android.Paths{flata}, transitiveStaticLibs...)
|
2018-02-21 09:22:23 +08:00
|
|
|
|
2018-05-03 03:58:28 +08:00
|
|
|
aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
|
2020-01-16 06:15:10 +08:00
|
|
|
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
|
2018-02-21 09:22:23 +08: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 11:40:52 +08:00
|
|
|
func (a *AARImport) ResourceJars() android.Paths {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
|
|
|
|
return android.Paths{a.classpathFile}
|
|
|
|
}
|
|
|
|
|
2020-06-04 22:08:17 +08:00
|
|
|
func (a *AARImport) DexJarBuildPath() android.Path {
|
2020-06-09 21:31:19 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AARImport) DexJarInstallPath() android.Path {
|
2019-02-01 06:12:44 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:22:23 +08:00
|
|
|
func (a *AARImport) AidlIncludeDirs() android.Paths {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-28 17:02:19 +08:00
|
|
|
func (a *AARImport) ExportedSdkLibs() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-27 02:08:34 +08:00
|
|
|
func (d *AARImport) ExportedPlugins() (android.Paths, []string) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2019-05-04 06:28:19 +08:00
|
|
|
func (a *AARImport) SrcJarArgs() ([]string, android.Paths) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-05-20 08:06:00 +08:00
|
|
|
func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
|
|
|
|
return a.depIsInSameApex(ctx, dep)
|
|
|
|
}
|
|
|
|
|
2020-04-15 10:03:39 +08:00
|
|
|
func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:22:23 +08:00
|
|
|
var _ android.PrebuiltInterface = (*Import)(nil)
|
|
|
|
|
2019-02-13 06:41:32 +08: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 09:22:23 +08:00
|
|
|
func AARImportFactory() android.Module {
|
|
|
|
module := &AARImport{}
|
|
|
|
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
|
|
|
|
android.InitPrebuiltModule(module, &module.properties.Aars)
|
2020-05-20 08:06:00 +08:00
|
|
|
android.InitApexModule(module)
|
2018-10-03 04:53:33 +08:00
|
|
|
InitJavaModule(module, android.DeviceSupported)
|
2018-02-21 09:22:23 +08:00
|
|
|
return module
|
|
|
|
}
|