blob: c31fc9530e24d514a421713cceaf56dd8bc5b7f1 [file] [log] [blame]
Colin Crossfabb6082018-02-20 17:22:23 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Colin Crossa592e3e2019-02-19 16:59:53 -080018 "fmt"
Jaewoong Jung5b425e22019-06-17 17:40:56 -070019 "path/filepath"
Colin Crossa97c5d32018-03-28 14:58:31 -070020 "strings"
Colin Crossfabb6082018-02-20 17:22:23 -080021
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080022 "android/soong/android"
Ulya Trafimovich31e444e2020-08-14 17:32:16 +010023 "android/soong/dexpreopt"
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080024
Colin Crossfabb6082018-02-20 17:22:23 -080025 "github.com/google/blueprint"
Colin Crossa97c5d32018-03-28 14:58:31 -070026 "github.com/google/blueprint/proptools"
Colin Crossfabb6082018-02-20 17:22:23 -080027)
28
Colin Crossa97c5d32018-03-28 14:58:31 -070029type AndroidLibraryDependency interface {
30 Dependency
31 ExportPackage() android.Path
Colin Cross89c31582018-04-30 15:55:11 -070032 ExportedProguardFlagFiles() android.Paths
Anton Hansson53c88442019-03-18 15:53:16 +000033 ExportedRRODirs() []rroDir
Colin Cross66f78822018-05-02 12:58:28 -070034 ExportedStaticPackages() android.Paths
Colin Cross90c25c62019-04-19 16:22:57 -070035 ExportedManifests() android.Paths
Jaewoong Jung6431ca72020-01-15 14:15:10 -080036 ExportedAssets() android.OptionalPath
Jaewoong Jungc779cd42020-10-06 18:56:10 -070037 SetRROEnforcedForDependent(enforce bool)
38 IsRROEnforced(ctx android.BaseModuleContext) bool
Colin Crossa97c5d32018-03-28 14:58:31 -070039}
40
41func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000042 RegisterAARBuildComponents(android.InitRegistrationContext)
Jaewoong Jungc779cd42020-10-06 18:56:10 -070043
44 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
45 ctx.TopDown("propagate_rro_enforcement", propagateRROEnforcementMutator).Parallel()
46 })
Paul Duffinf9b1da02019-12-18 19:51:55 +000047}
48
49func RegisterAARBuildComponents(ctx android.RegistrationContext) {
50 ctx.RegisterModuleType("android_library_import", AARImportFactory)
51 ctx.RegisterModuleType("android_library", AndroidLibraryFactory)
Colin Crossa97c5d32018-03-28 14:58:31 -070052}
53
54//
55// AAR (android library)
56//
57
58type androidLibraryProperties struct {
59 BuildAAR bool `blueprint:"mutated"`
60}
61
62type aaptProperties struct {
63 // flags passed to aapt when creating the apk
64 Aaptflags []string
65
Dan Willemsen72be5902018-10-24 20:24:57 -070066 // include all resource configurations, not just the product-configured
67 // ones.
68 Aapt_include_all_resources *bool
69
Colin Crossa97c5d32018-03-28 14:58:31 -070070 // list of directories relative to the Blueprints file containing assets.
Colin Cross0ddae7f2019-02-07 15:30:01 -080071 // Defaults to ["assets"] if a directory called assets exists. Set to []
72 // to disable the default.
Colin Crossa97c5d32018-03-28 14:58:31 -070073 Asset_dirs []string
74
75 // list of directories relative to the Blueprints file containing
Colin Cross0ddae7f2019-02-07 15:30:01 -080076 // Android resources. Defaults to ["res"] if a directory called res exists.
77 // Set to [] to disable the default.
Colin Crossa97c5d32018-03-28 14:58:31 -070078 Resource_dirs []string
79
Colin Crossa592e3e2019-02-19 16:59:53 -080080 // list of zip files containing Android resources.
Colin Cross27b922f2019-03-04 22:35:41 -080081 Resource_zips []string `android:"path"`
Colin Crossa592e3e2019-02-19 16:59:53 -080082
Colin Crossa97c5d32018-03-28 14:58:31 -070083 // path to AndroidManifest.xml. If unset, defaults to "AndroidManifest.xml".
Colin Cross27b922f2019-03-04 22:35:41 -080084 Manifest *string `android:"path"`
changho.shinb5432b72019-08-08 18:37:17 +090085
86 // paths to additional manifest files to merge with main manifest.
87 Additional_manifests []string `android:"path"`
Sasha Smundak541056c2019-10-28 15:50:06 -070088
89 // do not include AndroidManifest from dependent libraries
90 Dont_merge_manifests *bool
Jaewoong Jungc779cd42020-10-06 18:56:10 -070091
92 // true if RRO is enforced for any of the dependent modules
93 RROEnforcedForDependent bool `blueprint:"mutated"`
Colin Crossa97c5d32018-03-28 14:58:31 -070094}
95
96type aapt struct {
Colin Cross90c25c62019-04-19 16:22:57 -070097 aaptSrcJar android.Path
98 exportPackage android.Path
99 manifestPath android.Path
100 transitiveManifestPaths android.Paths
101 proguardOptionsFile android.Path
102 rroDirs []rroDir
103 rTxt android.Path
104 extraAaptPackagesFile android.Path
105 mergedManifestFile android.Path
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700106 noticeFile android.OptionalPath
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800107 assetPackage android.OptionalPath
Colin Cross90c25c62019-04-19 16:22:57 -0700108 isLibrary bool
Sasha Smundak6ad77252019-05-01 13:16:22 -0700109 useEmbeddedNativeLibs bool
Colin Cross90c25c62019-04-19 16:22:57 -0700110 useEmbeddedDex bool
111 usesNonSdkApis bool
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100112 sdkLibraries dexpreopt.LibraryPaths
Jaewoong Jungc27ab662019-05-30 15:51:14 -0700113 hasNoCode bool
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800114 LoggingParent string
Colin Cross014489c2020-06-02 20:09:13 -0700115 resourceFiles android.Paths
Colin Crossa97c5d32018-03-28 14:58:31 -0700116
Colin Crosse560c4a2019-03-19 16:03:11 -0700117 splitNames []string
118 splits []split
119
Colin Crossa97c5d32018-03-28 14:58:31 -0700120 aaptProperties aaptProperties
121}
122
Colin Crosse560c4a2019-03-19 16:03:11 -0700123type split struct {
124 name string
125 suffix string
126 path android.Path
127}
128
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700129// Propagate RRO enforcement flag to static lib dependencies transitively.
130func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) {
131 m := ctx.Module()
132 if d, ok := m.(AndroidLibraryDependency); ok && d.IsRROEnforced(ctx) {
133 ctx.VisitDirectDepsWithTag(staticLibTag, func(d android.Module) {
134 if a, ok := d.(AndroidLibraryDependency); ok {
135 a.SetRROEnforcedForDependent(true)
136 }
137 })
138 }
139}
140
Colin Crossa97c5d32018-03-28 14:58:31 -0700141func (a *aapt) ExportPackage() android.Path {
142 return a.exportPackage
143}
144
Anton Hansson53c88442019-03-18 15:53:16 +0000145func (a *aapt) ExportedRRODirs() []rroDir {
Colin Crossc1c37552019-01-31 11:42:41 -0800146 return a.rroDirs
147}
148
Colin Cross90c25c62019-04-19 16:22:57 -0700149func (a *aapt) ExportedManifests() android.Paths {
150 return a.transitiveManifestPaths
Colin Crossc1c37552019-01-31 11:42:41 -0800151}
152
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800153func (a *aapt) ExportedAssets() android.OptionalPath {
154 return a.assetPackage
155}
156
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700157func (a *aapt) SetRROEnforcedForDependent(enforce bool) {
158 a.aaptProperties.RROEnforcedForDependent = enforce
159}
160
161func (a *aapt) IsRROEnforced(ctx android.BaseModuleContext) bool {
162 // True if RRO is enforced for this module or...
163 return ctx.Config().EnforceRROForModule(ctx.ModuleName()) ||
164 // if RRO is enforced for any of its dependents, and this module is not exempted.
165 (a.aaptProperties.RROEnforcedForDependent && !ctx.Config().EnforceRROExemptedForModule(ctx.ModuleName()))
166}
167
Colin Crossa0ba2f52019-06-22 12:59:27 -0700168func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext,
169 manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths,
170 resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) {
Colin Crossa97c5d32018-03-28 14:58:31 -0700171
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800172 hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code")
173 hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name")
Colin Crossa97c5d32018-03-28 14:58:31 -0700174
Colin Crossa97c5d32018-03-28 14:58:31 -0700175 // Flags specified in Android.bp
176 linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...)
177
178 linkFlags = append(linkFlags, "--no-static-lib-packages")
179
180 // Find implicit or explicit asset and resource dirs
181 assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets")
182 resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res")
Colin Cross8a497952019-03-05 22:25:09 -0800183 resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips)
Colin Crossa97c5d32018-03-28 14:58:31 -0700184
Colin Crossa97c5d32018-03-28 14:58:31 -0700185 // Glob directories into lists of paths
186 for _, dir := range resourceDirs {
187 resDirs = append(resDirs, globbedResourceDir{
188 dir: dir,
189 files: androidResourceGlob(ctx, dir),
190 })
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700191 resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, a, dir)
Colin Crossa97c5d32018-03-28 14:58:31 -0700192 overlayDirs = append(overlayDirs, resOverlayDirs...)
193 rroDirs = append(rroDirs, resRRODirs...)
194 }
195
196 var assetFiles android.Paths
197 for _, dir := range assetDirs {
198 assetFiles = append(assetFiles, androidResourceGlob(ctx, dir)...)
199 }
200
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700201 assetDirStrings := assetDirs.Strings()
202 if a.noticeFile.Valid() {
203 assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String()))
204 assetFiles = append(assetFiles, a.noticeFile.Path())
205 }
206
Colin Crossa97c5d32018-03-28 14:58:31 -0700207 linkFlags = append(linkFlags, "--manifest "+manifestPath.String())
208 linkDeps = append(linkDeps, manifestPath)
209
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700210 linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A "))
Colin Crossa97c5d32018-03-28 14:58:31 -0700211 linkDeps = append(linkDeps, assetFiles...)
212
Colin Crossa97c5d32018-03-28 14:58:31 -0700213 // SDK version flags
Jiyong Park6a927c42020-01-21 02:03:43 +0900214 minSdkVersion, err := sdkContext.minSdkVersion().effectiveVersionString(ctx)
215 if err != nil {
216 ctx.ModuleErrorf("invalid minSdkVersion: %s", err)
217 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700218
Colin Cross83bb3162018-06-25 15:48:06 -0700219 linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion)
220 linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion)
Colin Crossa97c5d32018-03-28 14:58:31 -0700221
Colin Crossa97c5d32018-03-28 14:58:31 -0700222 // Version code
223 if !hasVersionCode {
Dan Albert4f378d72020-07-23 17:32:15 -0700224 linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String())
Colin Crossa97c5d32018-03-28 14:58:31 -0700225 }
226
227 if !hasVersionName {
Colin Cross402d5e02018-04-25 14:54:06 -0700228 var versionName string
229 if ctx.ModuleName() == "framework-res" {
230 // Some builds set AppsDefaultVersionName() to include the build number ("O-123456"). aapt2 copies the
231 // version name of framework-res into app manifests as compileSdkVersionCodename, which confuses things
Colin Crossbfd347d2018-05-09 11:11:35 -0700232 // if it contains the build number. Use the PlatformVersionName instead.
233 versionName = ctx.Config().PlatformVersionName()
Colin Cross402d5e02018-04-25 14:54:06 -0700234 } else {
235 versionName = ctx.Config().AppsDefaultVersionName()
236 }
Colin Cross0b9f31f2019-02-28 11:00:01 -0800237 versionName = proptools.NinjaEscape(versionName)
Colin Crossa97c5d32018-03-28 14:58:31 -0700238 linkFlags = append(linkFlags, "--version-name ", versionName)
239 }
240
Colin Crossa0ba2f52019-06-22 12:59:27 -0700241 linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"})
242
243 // Always set --pseudo-localize, it will be stripped out later for release
244 // builds that don't want it.
245 compileFlags = append(compileFlags, "--pseudo-localize")
246
247 return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips
Colin Crossa97c5d32018-03-28 14:58:31 -0700248}
249
Paul Duffin250e6192019-06-07 10:44:37 +0100250func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) {
Colin Cross42308aa2018-11-14 21:44:17 -0800251 if sdkDep.frameworkResModule != "" {
252 ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
Colin Crossa97c5d32018-03-28 14:58:31 -0700253 }
254}
255
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800256var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
257 blueprint.RuleParams{
258 Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`,
259 CommandDeps: []string{"${config.Zip2ZipCmd}"},
260 })
261
Colin Cross83bb3162018-06-25 15:48:06 -0700262func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
Colin Cross5446e882019-05-22 10:46:27 -0700263
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800264 transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags, sdkLibraries :=
Colin Cross5446e882019-05-22 10:46:27 -0700265 aaptLibs(ctx, sdkContext)
Colin Crossa97c5d32018-03-28 14:58:31 -0700266
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100267 a.sdkLibraries = sdkLibraries
268
Colin Cross31656952018-05-24 16:11:20 -0700269 // App manifest file
270 manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
271 manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
272
Colin Cross5446e882019-05-22 10:46:27 -0700273 manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, sdkLibraries,
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800274 a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode,
275 a.LoggingParent)
Colin Cross90c25c62019-04-19 16:22:57 -0700276
Luca Stefanifd898822019-09-10 22:13:31 +0200277 // Add additional manifest files to transitive manifests.
278 additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
279 a.transitiveManifestPaths = append(android.Paths{manifestPath}, additionalManifests...)
280 a.transitiveManifestPaths = append(a.transitiveManifestPaths, transitiveStaticLibManifests...)
Colin Cross90c25c62019-04-19 16:22:57 -0700281
Sasha Smundak541056c2019-10-28 15:50:06 -0700282 if len(a.transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
Luca Stefanifd898822019-09-10 22:13:31 +0200283 a.mergedManifestFile = manifestMerger(ctx, a.transitiveManifestPaths[0], a.transitiveManifestPaths[1:], a.isLibrary)
Colin Cross90c25c62019-04-19 16:22:57 -0700284 if !a.isLibrary {
285 // Only use the merged manifest for applications. For libraries, the transitive closure of manifests
286 // will be propagated to the final application and merged there. The merged manifest for libraries is
287 // only passed to Make, which can't handle transitive dependencies.
288 manifestPath = a.mergedManifestFile
289 }
290 } else {
291 a.mergedManifestFile = manifestPath
292 }
Colin Cross31656952018-05-24 16:11:20 -0700293
Colin Crossa0ba2f52019-06-22 12:59:27 -0700294 compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
Colin Cross31656952018-05-24 16:11:20 -0700295
Colin Crossc1c37552019-01-31 11:42:41 -0800296 rroDirs = append(rroDirs, staticRRODirs...)
Colin Cross31656952018-05-24 16:11:20 -0700297 linkFlags = append(linkFlags, libFlags...)
298 linkDeps = append(linkDeps, libDeps...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700299 linkFlags = append(linkFlags, extraLinkFlags...)
Colin Cross1b6a3cf2018-07-24 14:51:30 -0700300 if a.isLibrary {
301 linkFlags = append(linkFlags, "--static-lib")
302 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700303
304 packageRes := android.PathForModuleOut(ctx, "package-res.apk")
Jiyong Parkb7c639e2019-08-19 14:56:02 +0900305 // the subdir "android" is required to be filtered by package names
306 srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
Colin Crossa97c5d32018-03-28 14:58:31 -0700307 proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
308 rTxt := android.PathForModuleOut(ctx, "R.txt")
Colin Cross66f78822018-05-02 12:58:28 -0700309 // This file isn't used by Soong, but is generated for exporting
310 extraPackages := android.PathForModuleOut(ctx, "extra_packages")
Colin Crossa97c5d32018-03-28 14:58:31 -0700311
Colin Cross4aaa84a2018-08-21 15:14:37 -0700312 var compiledResDirs []android.Paths
Colin Crossa97c5d32018-03-28 14:58:31 -0700313 for _, dir := range resDirs {
Colin Cross014489c2020-06-02 20:09:13 -0700314 a.resourceFiles = append(a.resourceFiles, dir.files...)
Colin Crossa0ba2f52019-06-22 12:59:27 -0700315 compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths())
Colin Crossa97c5d32018-03-28 14:58:31 -0700316 }
Colin Cross4aaa84a2018-08-21 15:14:37 -0700317
Colin Crossa592e3e2019-02-19 16:59:53 -0800318 for i, zip := range resZips {
319 flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i))
Colin Crossa0ba2f52019-06-22 12:59:27 -0700320 aapt2CompileZip(ctx, flata, zip, "", compileFlags)
Colin Crossa592e3e2019-02-19 16:59:53 -0800321 compiledResDirs = append(compiledResDirs, android.Paths{flata})
322 }
323
Colin Cross4aaa84a2018-08-21 15:14:37 -0700324 var compiledRes, compiledOverlay android.Paths
325
326 compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
327
Colin Crossbec85302019-02-13 13:15:46 -0800328 if len(transitiveStaticLibs) > 0 {
Colin Cross4aaa84a2018-08-21 15:14:37 -0700329 // If we are using static android libraries, every source file becomes an overlay.
330 // This is to emulate old AAPT behavior which simulated library support.
331 for _, compiledResDir := range compiledResDirs {
332 compiledOverlay = append(compiledOverlay, compiledResDir...)
333 }
Colin Crossbec85302019-02-13 13:15:46 -0800334 } else if a.isLibrary {
335 // Otherwise, for a static library we treat all the resources equally with no overlay.
336 for _, compiledResDir := range compiledResDirs {
337 compiledRes = append(compiledRes, compiledResDir...)
338 }
Colin Cross4aaa84a2018-08-21 15:14:37 -0700339 } else if len(compiledResDirs) > 0 {
340 // Without static libraries, the first directory is our directory, which can then be
341 // overlaid by the rest.
342 compiledRes = append(compiledRes, compiledResDirs[0]...)
343 for _, compiledResDir := range compiledResDirs[1:] {
344 compiledOverlay = append(compiledOverlay, compiledResDir...)
345 }
346 }
347
Colin Crossa97c5d32018-03-28 14:58:31 -0700348 for _, dir := range overlayDirs {
Colin Crossa0ba2f52019-06-22 12:59:27 -0700349 compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700350 }
351
Colin Crosse560c4a2019-03-19 16:03:11 -0700352 var splitPackages android.WritablePaths
353 var splits []split
354
355 for _, s := range a.splitNames {
356 suffix := strings.Replace(s, ",", "_", -1)
357 path := android.PathForModuleOut(ctx, "package_"+suffix+".apk")
358 linkFlags = append(linkFlags, "--split", path.String()+":"+s)
359 splitPackages = append(splitPackages, path)
360 splits = append(splits, split{
361 name: s,
362 suffix: suffix,
363 path: path,
364 })
365 }
366
Colin Cross66f78822018-05-02 12:58:28 -0700367 aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800368 linkFlags, linkDeps, compiledRes, compiledOverlay, assetPackages, splitPackages)
369
370 // Extract assets from the resource package output so that they can be used later in aapt2link
371 // for modules that depend on this one.
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800372 if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 {
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800373 assets := android.PathForModuleOut(ctx, "assets.zip")
374 ctx.Build(pctx, android.BuildParams{
375 Rule: extractAssetsRule,
376 Input: packageRes,
377 Output: assets,
378 Description: "extract assets from built resource file",
379 })
380 a.assetPackage = android.OptionalPathForPath(assets)
381 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700382
383 a.aaptSrcJar = srcJar
384 a.exportPackage = packageRes
385 a.manifestPath = manifestPath
386 a.proguardOptionsFile = proguardOptionsFile
387 a.rroDirs = rroDirs
Colin Cross66f78822018-05-02 12:58:28 -0700388 a.extraAaptPackagesFile = extraPackages
Colin Crossa97c5d32018-03-28 14:58:31 -0700389 a.rTxt = rTxt
Colin Crosse560c4a2019-03-19 16:03:11 -0700390 a.splits = splits
Colin Crossa97c5d32018-03-28 14:58:31 -0700391}
392
393// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
Colin Cross90c25c62019-04-19 16:22:57 -0700394func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths,
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100395 staticRRODirs []rroDir, assets, deps android.Paths, flags []string, sdkLibraries dexpreopt.LibraryPaths) {
Colin Cross66f78822018-05-02 12:58:28 -0700396
Colin Crossa97c5d32018-03-28 14:58:31 -0700397 var sharedLibs android.Paths
398
Colin Cross83bb3162018-06-25 15:48:06 -0700399 sdkDep := decodeSdkDep(ctx, sdkContext)
Colin Crossa97c5d32018-03-28 14:58:31 -0700400 if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700401 sharedLibs = append(sharedLibs, sdkDep.jars...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700402 }
403
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100404 sdkLibraries = make(dexpreopt.LibraryPaths)
405
Colin Crossa97c5d32018-03-28 14:58:31 -0700406 ctx.VisitDirectDeps(func(module android.Module) {
407 var exportPackage android.Path
Colin Cross66f78822018-05-02 12:58:28 -0700408 aarDep, _ := module.(AndroidLibraryDependency)
409 if aarDep != nil {
Colin Crossa97c5d32018-03-28 14:58:31 -0700410 exportPackage = aarDep.ExportPackage()
411 }
412
Ulya Trafimovich21a73752020-09-01 17:33:48 +0100413 if dep, ok := module.(Dependency); ok {
414 sdkLibraries.AddLibraryPaths(dep.ExportedSdkLibs())
415 }
416
Colin Crossa97c5d32018-03-28 14:58:31 -0700417 switch ctx.OtherModuleDependencyTag(module) {
Colin Cross4b964c02018-10-15 16:18:06 -0700418 case instrumentationForTag:
419 // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
Colin Cross5446e882019-05-22 10:46:27 -0700420 case libTag:
421 if exportPackage != nil {
422 sharedLibs = append(sharedLibs, exportPackage)
423 }
424
Paul Duffin859fe962020-05-15 10:20:31 +0100425 // If the module is (or possibly could be) a component of a java_sdk_library
426 // (including the java_sdk_library) itself then append any implicit sdk library
427 // names to the list of sdk libraries to be added to the manifest.
428 if component, ok := module.(SdkLibraryComponentDependency); ok {
Ulya Trafimovichfc24ad32020-08-19 16:32:54 +0100429 sdkLibraries.MaybeAddLibraryPath(ctx, component.OptionalImplicitSdkLibrary(),
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100430 component.DexJarBuildPath(), component.DexJarInstallPath())
Colin Cross5446e882019-05-22 10:46:27 -0700431 }
432
433 case frameworkResTag:
Colin Crossa97c5d32018-03-28 14:58:31 -0700434 if exportPackage != nil {
435 sharedLibs = append(sharedLibs, exportPackage)
436 }
437 case staticLibTag:
438 if exportPackage != nil {
Colin Cross66f78822018-05-02 12:58:28 -0700439 transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
Colin Crossbec85302019-02-13 13:15:46 -0800440 transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
Colin Cross90c25c62019-04-19 16:22:57 -0700441 transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100442 sdkLibraries.AddLibraryPaths(aarDep.ExportedSdkLibs())
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800443 if aarDep.ExportedAssets().Valid() {
444 assets = append(assets, aarDep.ExportedAssets().Path())
445 }
Anton Hansson53c88442019-03-18 15:53:16 +0000446
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700447 if !ctx.Config().EnforceRROExemptedForModule(ctx.ModuleName()) {
448 outer:
449 for _, d := range aarDep.ExportedRRODirs() {
450 for _, e := range staticRRODirs {
451 if d.path == e.path {
452 continue outer
453 }
Anton Hansson53c88442019-03-18 15:53:16 +0000454 }
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700455 staticRRODirs = append(staticRRODirs, d)
Anton Hansson53c88442019-03-18 15:53:16 +0000456 }
Anton Hansson53c88442019-03-18 15:53:16 +0000457 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700458 }
459 }
460 })
461
462 deps = append(deps, sharedLibs...)
Colin Cross66f78822018-05-02 12:58:28 -0700463 deps = append(deps, transitiveStaticLibs...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700464
Colin Cross66f78822018-05-02 12:58:28 -0700465 if len(transitiveStaticLibs) > 0 {
Colin Crossa97c5d32018-03-28 14:58:31 -0700466 flags = append(flags, "--auto-add-overlay")
467 }
468
469 for _, sharedLib := range sharedLibs {
470 flags = append(flags, "-I "+sharedLib.String())
471 }
472
Colin Cross66f78822018-05-02 12:58:28 -0700473 transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
Colin Cross90c25c62019-04-19 16:22:57 -0700474 transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
Colin Cross66f78822018-05-02 12:58:28 -0700475
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800476 return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags, sdkLibraries
Colin Crossa97c5d32018-03-28 14:58:31 -0700477}
478
479type AndroidLibrary struct {
480 Library
481 aapt
482
483 androidLibraryProperties androidLibraryProperties
484
485 aarFile android.WritablePath
Colin Cross89c31582018-04-30 15:55:11 -0700486
487 exportedProguardFlagFiles android.Paths
Colin Cross66f78822018-05-02 12:58:28 -0700488 exportedStaticPackages android.Paths
Colin Cross89c31582018-04-30 15:55:11 -0700489}
490
491func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths {
492 return a.exportedProguardFlagFiles
Colin Crossa97c5d32018-03-28 14:58:31 -0700493}
494
Colin Cross66f78822018-05-02 12:58:28 -0700495func (a *AndroidLibrary) ExportedStaticPackages() android.Paths {
496 return a.exportedStaticPackages
497}
498
Colin Crossa97c5d32018-03-28 14:58:31 -0700499var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
500
501func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
502 a.Module.deps(ctx)
Paul Duffin250e6192019-06-07 10:44:37 +0100503 sdkDep := decodeSdkDep(ctx, sdkContext(a))
504 if sdkDep.hasFrameworkLibs() {
505 a.aapt.deps(ctx, sdkDep)
Colin Crossa97c5d32018-03-28 14:58:31 -0700506 }
507}
508
509func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosse4246ab2019-02-05 21:55:21 -0800510 a.aapt.isLibrary = true
Colin Cross1b6a3cf2018-07-24 14:51:30 -0700511 a.aapt.buildActions(ctx, sdkContext(a))
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100512 a.exportedSdkLibs = a.aapt.sdkLibraries
Colin Crossa97c5d32018-03-28 14:58:31 -0700513
514 ctx.CheckbuildFile(a.proguardOptionsFile)
515 ctx.CheckbuildFile(a.exportPackage)
516 ctx.CheckbuildFile(a.aaptSrcJar)
517
518 // apps manifests are handled by aapt, don't let Module see them
519 a.properties.Manifest = nil
520
Colin Cross014489c2020-06-02 20:09:13 -0700521 a.linter.mergedManifest = a.aapt.mergedManifestFile
522 a.linter.manifest = a.aapt.manifestPath
523 a.linter.resources = a.aapt.resourceFiles
524
Colin Crossa97c5d32018-03-28 14:58:31 -0700525 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
526 a.proguardOptionsFile)
527
528 a.Module.compile(ctx, a.aaptSrcJar)
529
Colin Crossf57c5782019-01-25 13:20:38 -0800530 a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar")
Colin Crossa97c5d32018-03-28 14:58:31 -0700531 var res android.Paths
532 if a.androidLibraryProperties.BuildAAR {
533 BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res)
534 ctx.CheckbuildFile(a.aarFile)
535 }
Colin Cross89c31582018-04-30 15:55:11 -0700536
537 ctx.VisitDirectDeps(func(m android.Module) {
538 if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
539 a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
Colin Cross66f78822018-05-02 12:58:28 -0700540 a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportPackage())
541 a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportedStaticPackages()...)
Colin Cross89c31582018-04-30 15:55:11 -0700542 }
543 })
544
545 a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
Colin Cross66f78822018-05-02 12:58:28 -0700546 a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages)
Colin Crossa97c5d32018-03-28 14:58:31 -0700547}
548
Colin Cross1b16b0e2019-02-12 14:41:32 -0800549// android_library builds and links sources into a `.jar` file for the device along with Android resources.
550//
551// An android_library has a single variant that produces a `.jar` file containing `.class` files that were
552// compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled
553// with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of
554// an android_app module.
Colin Crossa97c5d32018-03-28 14:58:31 -0700555func AndroidLibraryFactory() android.Module {
556 module := &AndroidLibrary{}
557
Colin Crossce6734e2020-06-15 16:09:53 -0700558 module.Module.addHostAndDeviceProperties()
Colin Crossa97c5d32018-03-28 14:58:31 -0700559 module.AddProperties(
Colin Crossa97c5d32018-03-28 14:58:31 -0700560 &module.aaptProperties,
561 &module.androidLibraryProperties)
562
563 module.androidLibraryProperties.BuildAAR = true
Colin Cross014489c2020-06-02 20:09:13 -0700564 module.Module.linter.library = true
Colin Crossa97c5d32018-03-28 14:58:31 -0700565
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900566 android.InitApexModule(module)
Colin Cross48de9a42018-10-02 13:53:33 -0700567 InitJavaModule(module, android.DeviceSupported)
Colin Crossa97c5d32018-03-28 14:58:31 -0700568 return module
569}
570
Colin Crossfabb6082018-02-20 17:22:23 -0800571//
572// AAR (android library) prebuilts
573//
Colin Crossfabb6082018-02-20 17:22:23 -0800574
575type AARImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -0800576 Aars []string `android:"path"`
Colin Crossfabb6082018-02-20 17:22:23 -0800577
Colin Cross479884c2018-07-10 13:39:30 -0700578 Sdk_version *string
579 Min_sdk_version *string
Colin Crossa97c5d32018-03-28 14:58:31 -0700580
581 Static_libs []string
582 Libs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -0700583
584 // if set to true, run Jetifier against .aar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -0700585 Jetifier *bool
Colin Crossfabb6082018-02-20 17:22:23 -0800586}
587
588type AARImport struct {
589 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -0700590 android.DefaultableModuleBase
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900591 android.ApexModuleBase
Colin Crossfabb6082018-02-20 17:22:23 -0800592 prebuilt android.Prebuilt
593
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900594 // Functionality common to Module and Import.
595 embeddableInModuleAndImport
596
Colin Crossfabb6082018-02-20 17:22:23 -0800597 properties AARImportProperties
598
Colin Cross66f78822018-05-02 12:58:28 -0700599 classpathFile android.WritablePath
600 proguardFlags android.WritablePath
601 exportPackage android.WritablePath
602 extraAaptPackagesFile android.WritablePath
Colin Cross10f7c4a2018-05-23 10:59:28 -0700603 manifest android.WritablePath
Colin Cross66f78822018-05-02 12:58:28 -0700604
605 exportedStaticPackages android.Paths
Colin Crossfabb6082018-02-20 17:22:23 -0800606}
607
Jiyong Park6a927c42020-01-21 02:03:43 +0900608func (a *AARImport) sdkVersion() sdkSpec {
609 return sdkSpecFrom(String(a.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700610}
611
Paul Duffine25c6442019-10-11 13:50:28 +0100612func (a *AARImport) systemModules() string {
613 return ""
614}
615
Jiyong Park6a927c42020-01-21 02:03:43 +0900616func (a *AARImport) minSdkVersion() sdkSpec {
Colin Cross479884c2018-07-10 13:39:30 -0700617 if a.properties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900618 return sdkSpecFrom(*a.properties.Min_sdk_version)
Colin Cross479884c2018-07-10 13:39:30 -0700619 }
Colin Cross83bb3162018-06-25 15:48:06 -0700620 return a.sdkVersion()
621}
622
Jiyong Park6a927c42020-01-21 02:03:43 +0900623func (a *AARImport) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700624 return a.sdkVersion()
625}
626
Colin Cross1e743852019-10-28 11:37:20 -0700627func (a *AARImport) javaVersion() string {
628 return ""
629}
630
Colin Crossa97c5d32018-03-28 14:58:31 -0700631var _ AndroidLibraryDependency = (*AARImport)(nil)
632
633func (a *AARImport) ExportPackage() android.Path {
634 return a.exportPackage
635}
636
Colin Cross89c31582018-04-30 15:55:11 -0700637func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
638 return android.Paths{a.proguardFlags}
639}
640
Anton Hansson53c88442019-03-18 15:53:16 +0000641func (a *AARImport) ExportedRRODirs() []rroDir {
Colin Crossc1c37552019-01-31 11:42:41 -0800642 return nil
643}
644
Colin Cross66f78822018-05-02 12:58:28 -0700645func (a *AARImport) ExportedStaticPackages() android.Paths {
646 return a.exportedStaticPackages
647}
648
Colin Cross90c25c62019-04-19 16:22:57 -0700649func (a *AARImport) ExportedManifests() android.Paths {
650 return android.Paths{a.manifest}
Colin Cross31656952018-05-24 16:11:20 -0700651}
652
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800653// TODO(jungjw): Decide whether we want to implement this.
654func (a *AARImport) ExportedAssets() android.OptionalPath {
655 return android.OptionalPath{}
656}
657
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700658// RRO enforcement is not available on aar_import since its RRO dirs are not
659// exported.
660func (a *AARImport) SetRROEnforcedForDependent(enforce bool) {
661}
662
663// RRO enforcement is not available on aar_import since its RRO dirs are not
664// exported.
665func (a *AARImport) IsRROEnforced(ctx android.BaseModuleContext) bool {
666 return false
667}
668
Colin Crossfabb6082018-02-20 17:22:23 -0800669func (a *AARImport) Prebuilt() *android.Prebuilt {
670 return &a.prebuilt
671}
672
673func (a *AARImport) Name() string {
674 return a.prebuilt.Name(a.ModuleBase.Name())
675}
676
Jiyong Park618922e2020-01-08 13:35:43 +0900677func (a *AARImport) JacocoReportClassesFile() android.Path {
678 return nil
679}
680
Colin Crossfabb6082018-02-20 17:22:23 -0800681func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
Jeongik Cha816a23a2020-07-08 01:09:23 +0900682 if !ctx.Config().AlwaysUsePrebuiltSdks() {
Colin Cross83bb3162018-06-25 15:48:06 -0700683 sdkDep := decodeSdkDep(ctx, sdkContext(a))
Colin Crossa97c5d32018-03-28 14:58:31 -0700684 if sdkDep.useModule && sdkDep.frameworkResModule != "" {
Colin Cross42d48b72018-08-29 14:10:52 -0700685 ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
Colin Crossfabb6082018-02-20 17:22:23 -0800686 }
687 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700688
Colin Cross42d48b72018-08-29 14:10:52 -0700689 ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...)
690 ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...)
Colin Crossfabb6082018-02-20 17:22:23 -0800691}
692
693// Unzip an AAR into its constituent files and directories. Any files in Outputs that don't exist in the AAR will be
Dan Willemsen304cfec2019-05-28 14:49:06 -0700694// touched to create an empty file. The res directory is not extracted, as it will be extracted in its own rule.
Colin Crossfabb6082018-02-20 17:22:23 -0800695var unzipAAR = pctx.AndroidStaticRule("unzipAAR",
696 blueprint.RuleParams{
Dan Willemsen304cfec2019-05-28 14:49:06 -0700697 Command: `rm -rf $outDir && mkdir -p $outDir && ` +
Colin Cross205e9112020-08-06 13:20:17 -0700698 `unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` +
699 `${config.MergeZipsCmd} $combinedClassesJar $$(ls $outDir/classes.jar 2> /dev/null) $$(ls $outDir/libs/*.jar 2> /dev/null)`,
700 CommandDeps: []string{"${config.MergeZipsCmd}"},
Colin Crossfabb6082018-02-20 17:22:23 -0800701 },
Colin Cross205e9112020-08-06 13:20:17 -0700702 "outDir", "combinedClassesJar")
Colin Crossfabb6082018-02-20 17:22:23 -0800703
704func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
705 if len(a.properties.Aars) != 1 {
706 ctx.PropertyErrorf("aars", "exactly one aar is required")
707 return
708 }
709
Nan Zhang4c819fb2018-08-27 18:31:46 -0700710 aarName := ctx.ModuleName() + ".aar"
711 var aar android.Path
712 aar = android.PathForModuleSrc(ctx, a.properties.Aars[0])
Colin Cross1001a792019-03-21 22:21:39 -0700713 if Bool(a.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -0700714 inputFile := aar
715 aar = android.PathForModuleOut(ctx, "jetifier", aarName)
716 TransformJetifier(ctx, aar.(android.WritablePath), inputFile)
717 }
Colin Crossfabb6082018-02-20 17:22:23 -0800718
719 extractedAARDir := android.PathForModuleOut(ctx, "aar")
Colin Cross205e9112020-08-06 13:20:17 -0700720 a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar")
Colin Crossfabb6082018-02-20 17:22:23 -0800721 a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt")
Colin Cross10f7c4a2018-05-23 10:59:28 -0700722 a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml")
Colin Crossfabb6082018-02-20 17:22:23 -0800723
724 ctx.Build(pctx, android.BuildParams{
725 Rule: unzipAAR,
726 Input: aar,
Colin Cross10f7c4a2018-05-23 10:59:28 -0700727 Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest},
Colin Crossfabb6082018-02-20 17:22:23 -0800728 Description: "unzip AAR",
729 Args: map[string]string{
Colin Cross205e9112020-08-06 13:20:17 -0700730 "outDir": extractedAARDir.String(),
731 "combinedClassesJar": a.classpathFile.String(),
Colin Crossfabb6082018-02-20 17:22:23 -0800732 },
733 })
734
Colin Crossa0ba2f52019-06-22 12:59:27 -0700735 // Always set --pseudo-localize, it will be stripped out later for release
736 // builds that don't want it.
737 compileFlags := []string{"--pseudo-localize"}
Colin Crossfabb6082018-02-20 17:22:23 -0800738 compiledResDir := android.PathForModuleOut(ctx, "flat-res")
Colin Crossfabb6082018-02-20 17:22:23 -0800739 flata := compiledResDir.Join(ctx, "gen_res.flata")
Colin Crossa0ba2f52019-06-22 12:59:27 -0700740 aapt2CompileZip(ctx, flata, aar, "res", compileFlags)
Colin Crossfabb6082018-02-20 17:22:23 -0800741
742 a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
Jiyong Parkb7c639e2019-08-19 14:56:02 +0900743 // the subdir "android" is required to be filtered by package names
744 srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
Colin Crossfabb6082018-02-20 17:22:23 -0800745 proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
Colin Crossa97c5d32018-03-28 14:58:31 -0700746 rTxt := android.PathForModuleOut(ctx, "R.txt")
Colin Cross66f78822018-05-02 12:58:28 -0700747 a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
Colin Crossfabb6082018-02-20 17:22:23 -0800748
749 var linkDeps android.Paths
750
751 linkFlags := []string{
752 "--static-lib",
753 "--no-static-lib-packages",
754 "--auto-add-overlay",
755 }
756
Colin Cross10f7c4a2018-05-23 10:59:28 -0700757 linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
758 linkDeps = append(linkDeps, a.manifest)
Colin Crossfabb6082018-02-20 17:22:23 -0800759
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800760 transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags, sdkLibraries :=
Colin Cross5446e882019-05-22 10:46:27 -0700761 aaptLibs(ctx, sdkContext(a))
Colin Cross31656952018-05-24 16:11:20 -0700762
763 _ = staticLibManifests
Colin Crossc1c37552019-01-31 11:42:41 -0800764 _ = staticRRODirs
Colin Cross5446e882019-05-22 10:46:27 -0700765 _ = sdkLibraries
Colin Crossfabb6082018-02-20 17:22:23 -0800766
Colin Crossa97c5d32018-03-28 14:58:31 -0700767 linkDeps = append(linkDeps, libDeps...)
768 linkFlags = append(linkFlags, libFlags...)
Colin Crossfabb6082018-02-20 17:22:23 -0800769
Colin Cross66f78822018-05-02 12:58:28 -0700770 overlayRes := append(android.Paths{flata}, transitiveStaticLibs...)
Colin Crossfabb6082018-02-20 17:22:23 -0800771
Colin Cross66f78822018-05-02 12:58:28 -0700772 aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800773 linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
Colin Crossfabb6082018-02-20 17:22:23 -0800774}
775
776var _ Dependency = (*AARImport)(nil)
777
778func (a *AARImport) HeaderJars() android.Paths {
779 return android.Paths{a.classpathFile}
780}
781
782func (a *AARImport) ImplementationJars() android.Paths {
783 return android.Paths{a.classpathFile}
784}
785
Colin Cross331a1212018-08-15 20:40:52 -0700786func (a *AARImport) ResourceJars() android.Paths {
787 return nil
788}
789
790func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
791 return android.Paths{a.classpathFile}
792}
793
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000794func (a *AARImport) DexJarBuildPath() android.Path {
Colin Crossf24a22a2019-01-31 14:12:44 -0800795 return nil
796}
797
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +0100798func (a *AARImport) DexJarInstallPath() android.Path {
799 return nil
800}
801
Colin Crossfabb6082018-02-20 17:22:23 -0800802func (a *AARImport) AidlIncludeDirs() android.Paths {
803 return nil
804}
805
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100806func (a *AARImport) ExportedSdkLibs() dexpreopt.LibraryPaths {
Jiyong Park1be96912018-05-28 18:02:19 +0900807 return nil
808}
809
Artur Satayev9cf46692019-11-26 18:08:34 +0000810func (d *AARImport) ExportedPlugins() (android.Paths, []string) {
811 return nil, nil
812}
813
Colin Cross0c4ce212019-05-03 15:28:19 -0700814func (a *AARImport) SrcJarArgs() ([]string, android.Paths) {
815 return nil, nil
816}
817
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900818func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
819 return a.depIsInSameApex(ctx, dep)
820}
821
Dan Albertc8060532020-07-22 22:32:17 -0700822func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
823 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900824 return nil
825}
826
Colin Crossfabb6082018-02-20 17:22:23 -0800827var _ android.PrebuiltInterface = (*Import)(nil)
828
Colin Cross1b16b0e2019-02-12 14:41:32 -0800829// android_library_import imports an `.aar` file into the build graph as if it was built with android_library.
830//
831// This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of
832// an android_app module.
Colin Crossfabb6082018-02-20 17:22:23 -0800833func AARImportFactory() android.Module {
834 module := &AARImport{}
835
836 module.AddProperties(&module.properties)
837
838 android.InitPrebuiltModule(module, &module.properties.Aars)
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900839 android.InitApexModule(module)
Colin Cross48de9a42018-10-02 13:53:33 -0700840 InitJavaModule(module, android.DeviceSupported)
Colin Crossfabb6082018-02-20 17:22:23 -0800841 return module
842}