blob: 4fdcb80b8bde7f067a4f6d9b896572001eef0245 [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 Crossc20dc852020-11-10 12:27:45 -080020 "strconv"
Colin Crossa97c5d32018-03-28 14:58:31 -070021 "strings"
Colin Crossfabb6082018-02-20 17:22:23 -080022
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080023 "android/soong/android"
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -050024 "android/soong/bazel"
Ulya Trafimovich31e444e2020-08-14 17:32:16 +010025 "android/soong/dexpreopt"
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080026
Colin Crossfabb6082018-02-20 17:22:23 -080027 "github.com/google/blueprint"
Colin Crossa97c5d32018-03-28 14:58:31 -070028 "github.com/google/blueprint/proptools"
Colin Crossfabb6082018-02-20 17:22:23 -080029)
30
Colin Crossa97c5d32018-03-28 14:58:31 -070031type AndroidLibraryDependency interface {
Jared Duke5979b302022-12-19 21:08:39 +000032 LibraryDependency
Colin Crossa97c5d32018-03-28 14:58:31 -070033 ExportPackage() android.Path
Anton Hansson53c88442019-03-18 15:53:16 +000034 ExportedRRODirs() []rroDir
Colin Cross66f78822018-05-02 12:58:28 -070035 ExportedStaticPackages() android.Paths
Colin Cross90c25c62019-04-19 16:22:57 -070036 ExportedManifests() android.Paths
Jaewoong Jung6431ca72020-01-15 14:15:10 -080037 ExportedAssets() android.OptionalPath
Jaewoong Jungc779cd42020-10-06 18:56:10 -070038 SetRROEnforcedForDependent(enforce bool)
39 IsRROEnforced(ctx android.BaseModuleContext) bool
Colin Crossa97c5d32018-03-28 14:58:31 -070040}
41
42func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000043 RegisterAARBuildComponents(android.InitRegistrationContext)
44}
45
46func RegisterAARBuildComponents(ctx android.RegistrationContext) {
47 ctx.RegisterModuleType("android_library_import", AARImportFactory)
48 ctx.RegisterModuleType("android_library", AndroidLibraryFactory)
Paul Duffin04ba70d2021-03-22 13:56:43 +000049 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("propagate_rro_enforcement", propagateRROEnforcementMutator).Parallel()
51 })
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
Alexei Nicoara69cf0f32022-07-27 14:59:18 +0100109 defaultManifestVersion string
Sasha Smundak6ad77252019-05-01 13:16:22 -0700110 useEmbeddedNativeLibs bool
Colin Cross90c25c62019-04-19 16:22:57 -0700111 useEmbeddedDex bool
112 usesNonSdkApis bool
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()) ||
Jeongik Chacee5ba92021-02-19 12:11:51 +0900164 // if RRO is enforced for any of its dependents.
165 a.aaptProperties.RROEnforcedForDependent
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700166}
167
Jiyong Parkf1691d22021-03-29 20:11:58 +0900168func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkContext,
Colin Crossa0ba2f52019-06-22 12:59:27 -0700169 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")
Eric Miao40eab202023-03-30 16:57:17 +0000179 linkFlags = append(linkFlags, "--enable-compact-entries")
Colin Crossa97c5d32018-03-28 14:58:31 -0700180
181 // Find implicit or explicit asset and resource dirs
182 assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets")
183 resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res")
Colin Cross8a497952019-03-05 22:25:09 -0800184 resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips)
Colin Crossa97c5d32018-03-28 14:58:31 -0700185
Colin Crossa97c5d32018-03-28 14:58:31 -0700186 // Glob directories into lists of paths
187 for _, dir := range resourceDirs {
188 resDirs = append(resDirs, globbedResourceDir{
189 dir: dir,
190 files: androidResourceGlob(ctx, dir),
191 })
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700192 resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, a, dir)
Colin Crossa97c5d32018-03-28 14:58:31 -0700193 overlayDirs = append(overlayDirs, resOverlayDirs...)
194 rroDirs = append(rroDirs, resRRODirs...)
195 }
196
Colin Crossc20dc852020-11-10 12:27:45 -0800197 var assetDeps android.Paths
198 for i, dir := range assetDirs {
199 // Add a dependency on every file in the asset directory. This ensures the aapt2
200 // rule will be rerun if one of the files in the asset directory is modified.
201 assetDeps = append(assetDeps, androidResourceGlob(ctx, dir)...)
202
203 // Add a dependency on a file that contains a list of all the files in the asset directory.
204 // This ensures the aapt2 rule will be run if a file is removed from the asset directory,
205 // or a file is added whose timestamp is older than the output of aapt2.
206 assetFileListFile := android.PathForModuleOut(ctx, "asset_dir_globs", strconv.Itoa(i)+".glob")
207 androidResourceGlobList(ctx, dir, assetFileListFile)
208 assetDeps = append(assetDeps, assetFileListFile)
Colin Crossa97c5d32018-03-28 14:58:31 -0700209 }
210
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700211 assetDirStrings := assetDirs.Strings()
212 if a.noticeFile.Valid() {
213 assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String()))
Colin Crossc20dc852020-11-10 12:27:45 -0800214 assetDeps = append(assetDeps, a.noticeFile.Path())
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700215 }
216
Colin Crossa97c5d32018-03-28 14:58:31 -0700217 linkFlags = append(linkFlags, "--manifest "+manifestPath.String())
218 linkDeps = append(linkDeps, manifestPath)
219
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700220 linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A "))
Colin Crossc20dc852020-11-10 12:27:45 -0800221 linkDeps = append(linkDeps, assetDeps...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700222
Spandan Das50885c02023-02-23 21:31:33 +0000223 // Returns the effective version for {min|target}_sdk_version
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000224 effectiveVersionString := func(sdkVersion android.SdkSpec, minSdkVersion android.ApiLevel) string {
Spandan Das50885c02023-02-23 21:31:33 +0000225 // If {min|target}_sdk_version is current, use sdk_version to determine the effective level
226 // This is necessary for vendor modules.
227 // The effective version does not _only_ depend on {min|target}_sdk_version(level),
228 // but also on the sdk_version (kind+level)
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000229 if minSdkVersion.IsCurrent() {
Spandan Das50885c02023-02-23 21:31:33 +0000230 ret, err := sdkVersion.EffectiveVersionString(ctx)
231 if err != nil {
232 ctx.ModuleErrorf("invalid sdk_version: %s", err)
233 }
234 return ret
235 }
236 ret, err := minSdkVersion.EffectiveVersionString(ctx)
237 if err != nil {
238 ctx.ModuleErrorf("invalid min_sdk_version: %s", err)
239 }
240 return ret
Jiyong Park6a927c42020-01-21 02:03:43 +0900241 }
Spandan Das50885c02023-02-23 21:31:33 +0000242 // SDK version flags
243 sdkVersion := sdkContext.SdkVersion(ctx)
244 minSdkVersion := effectiveVersionString(sdkVersion, sdkContext.MinSdkVersion(ctx))
Colin Crossa97c5d32018-03-28 14:58:31 -0700245
Colin Cross83bb3162018-06-25 15:48:06 -0700246 linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion)
Spandan Das6450b552023-02-23 19:27:07 +0000247 // Use minSdkVersion for target-sdk-version, even if `target_sdk_version` is set
248 // This behavior has been copied from Make.
Colin Cross83bb3162018-06-25 15:48:06 -0700249 linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion)
Colin Crossa97c5d32018-03-28 14:58:31 -0700250
Colin Crossa97c5d32018-03-28 14:58:31 -0700251 // Version code
252 if !hasVersionCode {
Dan Albert4f378d72020-07-23 17:32:15 -0700253 linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String())
Colin Crossa97c5d32018-03-28 14:58:31 -0700254 }
255
256 if !hasVersionName {
Colin Cross402d5e02018-04-25 14:54:06 -0700257 var versionName string
258 if ctx.ModuleName() == "framework-res" {
259 // Some builds set AppsDefaultVersionName() to include the build number ("O-123456"). aapt2 copies the
260 // version name of framework-res into app manifests as compileSdkVersionCodename, which confuses things
Colin Crossbfd347d2018-05-09 11:11:35 -0700261 // if it contains the build number. Use the PlatformVersionName instead.
262 versionName = ctx.Config().PlatformVersionName()
Colin Cross402d5e02018-04-25 14:54:06 -0700263 } else {
264 versionName = ctx.Config().AppsDefaultVersionName()
265 }
Colin Cross0b9f31f2019-02-28 11:00:01 -0800266 versionName = proptools.NinjaEscape(versionName)
Colin Crossa97c5d32018-03-28 14:58:31 -0700267 linkFlags = append(linkFlags, "--version-name ", versionName)
268 }
269
Colin Crossa0ba2f52019-06-22 12:59:27 -0700270 linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"})
271
272 // Always set --pseudo-localize, it will be stripped out later for release
273 // builds that don't want it.
274 compileFlags = append(compileFlags, "--pseudo-localize")
275
276 return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips
Colin Crossa97c5d32018-03-28 14:58:31 -0700277}
278
Paul Duffin250e6192019-06-07 10:44:37 +0100279func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) {
Colin Cross42308aa2018-11-14 21:44:17 -0800280 if sdkDep.frameworkResModule != "" {
281 ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
Colin Crossa97c5d32018-03-28 14:58:31 -0700282 }
283}
284
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800285var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
286 blueprint.RuleParams{
287 Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`,
288 CommandDeps: []string{"${config.Zip2ZipCmd}"},
289 })
290
Jiyong Parkf1691d22021-03-29 20:11:58 +0900291func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkContext,
Paul Duffin06530572022-02-03 17:54:15 +0000292 classLoaderContexts dexpreopt.ClassLoaderContextMap, excludedLibs []string,
Harshit Mahajan5b8b7302022-06-10 11:24:05 +0000293 enforceDefaultTargetSdkVersion bool, extraLinkFlags ...string) {
Colin Cross5446e882019-05-22 10:46:27 -0700294
Ulya Trafimovich18554242020-11-03 15:55:11 +0000295 transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags :=
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +0100296 aaptLibs(ctx, sdkContext, classLoaderContexts)
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100297
Paul Duffin06530572022-02-03 17:54:15 +0000298 // Exclude any libraries from the supplied list.
299 classLoaderContexts = classLoaderContexts.ExcludeLibs(excludedLibs)
300
Colin Cross31656952018-05-24 16:11:20 -0700301 // App manifest file
302 manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
303 manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
304
Gurpreet Singh7deabfa2022-02-10 13:28:35 +0000305 manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{
Harshit Mahajan5b8b7302022-06-10 11:24:05 +0000306 SdkContext: sdkContext,
307 ClassLoaderContexts: classLoaderContexts,
308 IsLibrary: a.isLibrary,
309 DefaultManifestVersion: a.defaultManifestVersion,
310 UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs,
311 UsesNonSdkApis: a.usesNonSdkApis,
312 UseEmbeddedDex: a.useEmbeddedDex,
313 HasNoCode: a.hasNoCode,
314 LoggingParent: a.LoggingParent,
315 EnforceDefaultTargetSdkVersion: enforceDefaultTargetSdkVersion,
Gurpreet Singh75d65f32022-01-24 17:44:05 +0000316 })
Colin Cross90c25c62019-04-19 16:22:57 -0700317
Luca Stefanifd898822019-09-10 22:13:31 +0200318 // Add additional manifest files to transitive manifests.
319 additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
320 a.transitiveManifestPaths = append(android.Paths{manifestPath}, additionalManifests...)
321 a.transitiveManifestPaths = append(a.transitiveManifestPaths, transitiveStaticLibManifests...)
Colin Cross90c25c62019-04-19 16:22:57 -0700322
Sasha Smundak541056c2019-10-28 15:50:06 -0700323 if len(a.transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
Luca Stefanifd898822019-09-10 22:13:31 +0200324 a.mergedManifestFile = manifestMerger(ctx, a.transitiveManifestPaths[0], a.transitiveManifestPaths[1:], a.isLibrary)
Colin Cross90c25c62019-04-19 16:22:57 -0700325 if !a.isLibrary {
326 // Only use the merged manifest for applications. For libraries, the transitive closure of manifests
327 // will be propagated to the final application and merged there. The merged manifest for libraries is
328 // only passed to Make, which can't handle transitive dependencies.
329 manifestPath = a.mergedManifestFile
330 }
331 } else {
332 a.mergedManifestFile = manifestPath
333 }
Colin Cross31656952018-05-24 16:11:20 -0700334
Colin Crossa0ba2f52019-06-22 12:59:27 -0700335 compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
Colin Cross31656952018-05-24 16:11:20 -0700336
Colin Crossc1c37552019-01-31 11:42:41 -0800337 rroDirs = append(rroDirs, staticRRODirs...)
Colin Cross31656952018-05-24 16:11:20 -0700338 linkFlags = append(linkFlags, libFlags...)
339 linkDeps = append(linkDeps, libDeps...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700340 linkFlags = append(linkFlags, extraLinkFlags...)
Colin Cross1b6a3cf2018-07-24 14:51:30 -0700341 if a.isLibrary {
342 linkFlags = append(linkFlags, "--static-lib")
343 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700344
345 packageRes := android.PathForModuleOut(ctx, "package-res.apk")
Jiyong Parkb7c639e2019-08-19 14:56:02 +0900346 // the subdir "android" is required to be filtered by package names
347 srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
Colin Crossa97c5d32018-03-28 14:58:31 -0700348 proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
349 rTxt := android.PathForModuleOut(ctx, "R.txt")
Colin Cross66f78822018-05-02 12:58:28 -0700350 // This file isn't used by Soong, but is generated for exporting
351 extraPackages := android.PathForModuleOut(ctx, "extra_packages")
Colin Crossa97c5d32018-03-28 14:58:31 -0700352
Colin Cross4aaa84a2018-08-21 15:14:37 -0700353 var compiledResDirs []android.Paths
Colin Crossa97c5d32018-03-28 14:58:31 -0700354 for _, dir := range resDirs {
Colin Cross014489c2020-06-02 20:09:13 -0700355 a.resourceFiles = append(a.resourceFiles, dir.files...)
Colin Crossa0ba2f52019-06-22 12:59:27 -0700356 compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths())
Colin Crossa97c5d32018-03-28 14:58:31 -0700357 }
Colin Cross4aaa84a2018-08-21 15:14:37 -0700358
Colin Crossa592e3e2019-02-19 16:59:53 -0800359 for i, zip := range resZips {
360 flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i))
Colin Crossa0ba2f52019-06-22 12:59:27 -0700361 aapt2CompileZip(ctx, flata, zip, "", compileFlags)
Colin Crossa592e3e2019-02-19 16:59:53 -0800362 compiledResDirs = append(compiledResDirs, android.Paths{flata})
363 }
364
Colin Cross4aaa84a2018-08-21 15:14:37 -0700365 var compiledRes, compiledOverlay android.Paths
366
367 compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
368
Colin Crossbec85302019-02-13 13:15:46 -0800369 if len(transitiveStaticLibs) > 0 {
Colin Cross4aaa84a2018-08-21 15:14:37 -0700370 // If we are using static android libraries, every source file becomes an overlay.
371 // This is to emulate old AAPT behavior which simulated library support.
372 for _, compiledResDir := range compiledResDirs {
373 compiledOverlay = append(compiledOverlay, compiledResDir...)
374 }
Colin Crossbec85302019-02-13 13:15:46 -0800375 } else if a.isLibrary {
376 // Otherwise, for a static library we treat all the resources equally with no overlay.
377 for _, compiledResDir := range compiledResDirs {
378 compiledRes = append(compiledRes, compiledResDir...)
379 }
Colin Cross4aaa84a2018-08-21 15:14:37 -0700380 } else if len(compiledResDirs) > 0 {
381 // Without static libraries, the first directory is our directory, which can then be
382 // overlaid by the rest.
383 compiledRes = append(compiledRes, compiledResDirs[0]...)
384 for _, compiledResDir := range compiledResDirs[1:] {
385 compiledOverlay = append(compiledOverlay, compiledResDir...)
386 }
387 }
388
Colin Crossa97c5d32018-03-28 14:58:31 -0700389 for _, dir := range overlayDirs {
Colin Crossa0ba2f52019-06-22 12:59:27 -0700390 compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700391 }
392
Colin Crosse560c4a2019-03-19 16:03:11 -0700393 var splitPackages android.WritablePaths
394 var splits []split
395
396 for _, s := range a.splitNames {
397 suffix := strings.Replace(s, ",", "_", -1)
398 path := android.PathForModuleOut(ctx, "package_"+suffix+".apk")
399 linkFlags = append(linkFlags, "--split", path.String()+":"+s)
400 splitPackages = append(splitPackages, path)
401 splits = append(splits, split{
402 name: s,
403 suffix: suffix,
404 path: path,
405 })
406 }
407
Colin Cross66f78822018-05-02 12:58:28 -0700408 aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800409 linkFlags, linkDeps, compiledRes, compiledOverlay, assetPackages, splitPackages)
410
411 // Extract assets from the resource package output so that they can be used later in aapt2link
412 // for modules that depend on this one.
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800413 if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 {
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800414 assets := android.PathForModuleOut(ctx, "assets.zip")
415 ctx.Build(pctx, android.BuildParams{
416 Rule: extractAssetsRule,
417 Input: packageRes,
418 Output: assets,
419 Description: "extract assets from built resource file",
420 })
421 a.assetPackage = android.OptionalPathForPath(assets)
422 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700423
424 a.aaptSrcJar = srcJar
425 a.exportPackage = packageRes
426 a.manifestPath = manifestPath
427 a.proguardOptionsFile = proguardOptionsFile
428 a.rroDirs = rroDirs
Colin Cross66f78822018-05-02 12:58:28 -0700429 a.extraAaptPackagesFile = extraPackages
Colin Crossa97c5d32018-03-28 14:58:31 -0700430 a.rTxt = rTxt
Colin Crosse560c4a2019-03-19 16:03:11 -0700431 a.splits = splits
Colin Crossa97c5d32018-03-28 14:58:31 -0700432}
433
434// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
Jiyong Parkf1691d22021-03-29 20:11:58 +0900435func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) (
Ulya Trafimovich18554242020-11-03 15:55:11 +0000436 transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) {
Colin Cross66f78822018-05-02 12:58:28 -0700437
Colin Crossa97c5d32018-03-28 14:58:31 -0700438 var sharedLibs android.Paths
439
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +0100440 if classLoaderContexts == nil {
Ulya Trafimovich18554242020-11-03 15:55:11 +0000441 // Not all callers need to compute class loader context, those who don't just pass nil.
442 // Create a temporary class loader context here (it will be computed, but not used).
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +0100443 classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
Ulya Trafimovich18554242020-11-03 15:55:11 +0000444 }
445
Colin Cross83bb3162018-06-25 15:48:06 -0700446 sdkDep := decodeSdkDep(ctx, sdkContext)
Colin Crossa97c5d32018-03-28 14:58:31 -0700447 if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700448 sharedLibs = append(sharedLibs, sdkDep.jars...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700449 }
450
451 ctx.VisitDirectDeps(func(module android.Module) {
Ulya Trafimovich65b03192020-12-03 16:50:22 +0000452 depTag := ctx.OtherModuleDependencyTag(module)
Ulya Trafimovich18554242020-11-03 15:55:11 +0000453
Colin Crossa97c5d32018-03-28 14:58:31 -0700454 var exportPackage android.Path
Colin Cross66f78822018-05-02 12:58:28 -0700455 aarDep, _ := module.(AndroidLibraryDependency)
456 if aarDep != nil {
Colin Crossa97c5d32018-03-28 14:58:31 -0700457 exportPackage = aarDep.ExportPackage()
458 }
459
Ulya Trafimovich65b03192020-12-03 16:50:22 +0000460 switch depTag {
Colin Cross4b964c02018-10-15 16:18:06 -0700461 case instrumentationForTag:
462 // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
Liz Kammeref28a4c2022-09-23 16:50:56 -0400463 case sdkLibTag, libTag:
Colin Cross5446e882019-05-22 10:46:27 -0700464 if exportPackage != nil {
465 sharedLibs = append(sharedLibs, exportPackage)
466 }
Colin Cross5446e882019-05-22 10:46:27 -0700467 case frameworkResTag:
Colin Crossa97c5d32018-03-28 14:58:31 -0700468 if exportPackage != nil {
469 sharedLibs = append(sharedLibs, exportPackage)
470 }
471 case staticLibTag:
472 if exportPackage != nil {
Colin Cross66f78822018-05-02 12:58:28 -0700473 transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
Colin Crossbec85302019-02-13 13:15:46 -0800474 transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
Colin Cross90c25c62019-04-19 16:22:57 -0700475 transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800476 if aarDep.ExportedAssets().Valid() {
477 assets = append(assets, aarDep.ExportedAssets().Path())
478 }
Anton Hansson53c88442019-03-18 15:53:16 +0000479
Jeongik Chacee5ba92021-02-19 12:11:51 +0900480 outer:
481 for _, d := range aarDep.ExportedRRODirs() {
482 for _, e := range staticRRODirs {
483 if d.path == e.path {
484 continue outer
Anton Hansson53c88442019-03-18 15:53:16 +0000485 }
486 }
Jeongik Chacee5ba92021-02-19 12:11:51 +0900487 staticRRODirs = append(staticRRODirs, d)
Anton Hansson53c88442019-03-18 15:53:16 +0000488 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700489 }
490 }
Ulya Trafimovich18554242020-11-03 15:55:11 +0000491
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +0000492 addCLCFromDep(ctx, module, classLoaderContexts)
Colin Crossa97c5d32018-03-28 14:58:31 -0700493 })
494
495 deps = append(deps, sharedLibs...)
Colin Cross66f78822018-05-02 12:58:28 -0700496 deps = append(deps, transitiveStaticLibs...)
Colin Crossa97c5d32018-03-28 14:58:31 -0700497
Colin Cross66f78822018-05-02 12:58:28 -0700498 if len(transitiveStaticLibs) > 0 {
Colin Crossa97c5d32018-03-28 14:58:31 -0700499 flags = append(flags, "--auto-add-overlay")
500 }
501
502 for _, sharedLib := range sharedLibs {
503 flags = append(flags, "-I "+sharedLib.String())
504 }
505
Colin Cross66f78822018-05-02 12:58:28 -0700506 transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
Colin Cross90c25c62019-04-19 16:22:57 -0700507 transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
Colin Cross66f78822018-05-02 12:58:28 -0700508
Ulya Trafimovich18554242020-11-03 15:55:11 +0000509 return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags
Colin Crossa97c5d32018-03-28 14:58:31 -0700510}
511
512type AndroidLibrary struct {
513 Library
514 aapt
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -0500515 android.BazelModuleBase
Colin Crossa97c5d32018-03-28 14:58:31 -0700516
517 androidLibraryProperties androidLibraryProperties
518
519 aarFile android.WritablePath
Colin Cross89c31582018-04-30 15:55:11 -0700520
Jared Duke5979b302022-12-19 21:08:39 +0000521 exportedStaticPackages android.Paths
Colin Cross89c31582018-04-30 15:55:11 -0700522}
523
Saeid Farivar Asanjan1fca3012021-09-14 18:40:19 +0000524var _ android.OutputFileProducer = (*AndroidLibrary)(nil)
525
526// For OutputFileProducer interface
527func (a *AndroidLibrary) OutputFiles(tag string) (android.Paths, error) {
528 switch tag {
529 case ".aar":
530 return []android.Path{a.aarFile}, nil
531 default:
532 return a.Library.OutputFiles(tag)
533 }
534}
535
Colin Cross66f78822018-05-02 12:58:28 -0700536func (a *AndroidLibrary) ExportedStaticPackages() android.Paths {
537 return a.exportedStaticPackages
538}
539
Colin Crossa97c5d32018-03-28 14:58:31 -0700540var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
541
542func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
543 a.Module.deps(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +0900544 sdkDep := decodeSdkDep(ctx, android.SdkContext(a))
Paul Duffin250e6192019-06-07 10:44:37 +0100545 if sdkDep.hasFrameworkLibs() {
546 a.aapt.deps(ctx, sdkDep)
Colin Crossa97c5d32018-03-28 14:58:31 -0700547 }
Colin Cross4a80a152022-12-21 21:51:52 -0800548 a.usesLibrary.deps(ctx, false)
Colin Crossa97c5d32018-03-28 14:58:31 -0700549}
550
551func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosse4246ab2019-02-05 21:55:21 -0800552 a.aapt.isLibrary = true
Ulya Trafimovich42c7f0d2021-08-17 16:20:29 +0100553 a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
Harshit Mahajan5b8b7302022-06-10 11:24:05 +0000554 a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, nil, false)
Colin Crossa97c5d32018-03-28 14:58:31 -0700555
Colin Cross56a83212020-09-15 18:30:11 -0700556 a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
557
Colin Crossa97c5d32018-03-28 14:58:31 -0700558 ctx.CheckbuildFile(a.proguardOptionsFile)
559 ctx.CheckbuildFile(a.exportPackage)
560 ctx.CheckbuildFile(a.aaptSrcJar)
561
562 // apps manifests are handled by aapt, don't let Module see them
563 a.properties.Manifest = nil
564
Colin Cross014489c2020-06-02 20:09:13 -0700565 a.linter.mergedManifest = a.aapt.mergedManifestFile
566 a.linter.manifest = a.aapt.manifestPath
567 a.linter.resources = a.aapt.resourceFiles
568
Colin Crossa97c5d32018-03-28 14:58:31 -0700569 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
570 a.proguardOptionsFile)
571
572 a.Module.compile(ctx, a.aaptSrcJar)
573
Colin Crossf57c5782019-01-25 13:20:38 -0800574 a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar")
Colin Crossa97c5d32018-03-28 14:58:31 -0700575 var res android.Paths
576 if a.androidLibraryProperties.BuildAAR {
577 BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res)
578 ctx.CheckbuildFile(a.aarFile)
579 }
Colin Cross89c31582018-04-30 15:55:11 -0700580
Cole Faust9a631312020-10-22 21:05:24 +0000581 a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles,
582 android.PathsForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)...)
Colin Cross89c31582018-04-30 15:55:11 -0700583 ctx.VisitDirectDeps(func(m android.Module) {
Jared Duke5979b302022-12-19 21:08:39 +0000584 if ctx.OtherModuleDependencyTag(m) == staticLibTag {
585 if lib, ok := m.(LibraryDependency); ok {
586 a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
587 }
588 if alib, ok := m.(AndroidLibraryDependency); ok {
589 a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportPackage())
590 a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportedStaticPackages()...)
591 }
Colin Cross89c31582018-04-30 15:55:11 -0700592 }
593 })
Colin Cross89c31582018-04-30 15:55:11 -0700594 a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
Colin Cross66f78822018-05-02 12:58:28 -0700595 a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages)
Sam Delmerico82602492022-06-10 17:05:42 +0000596
597 prebuiltJniPackages := android.Paths{}
598 ctx.VisitDirectDeps(func(module android.Module) {
599 if info, ok := ctx.OtherModuleProvider(module, JniPackageProvider).(JniPackageInfo); ok {
600 prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...)
601 }
602 })
603 if len(prebuiltJniPackages) > 0 {
604 ctx.SetProvider(JniPackageProvider, JniPackageInfo{
605 JniPackages: prebuiltJniPackages,
606 })
607 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700608}
609
Colin Cross1b16b0e2019-02-12 14:41:32 -0800610// android_library builds and links sources into a `.jar` file for the device along with Android resources.
611//
612// An android_library has a single variant that produces a `.jar` file containing `.class` files that were
Sam Delmerico82602492022-06-10 17:05:42 +0000613// compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled
Colin Cross1b16b0e2019-02-12 14:41:32 -0800614// with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of
615// an android_app module.
Colin Crossa97c5d32018-03-28 14:58:31 -0700616func AndroidLibraryFactory() android.Module {
617 module := &AndroidLibrary{}
618
Colin Crossce6734e2020-06-15 16:09:53 -0700619 module.Module.addHostAndDeviceProperties()
Colin Crossa97c5d32018-03-28 14:58:31 -0700620 module.AddProperties(
Colin Crossa97c5d32018-03-28 14:58:31 -0700621 &module.aaptProperties,
622 &module.androidLibraryProperties)
623
624 module.androidLibraryProperties.BuildAAR = true
Colin Cross014489c2020-06-02 20:09:13 -0700625 module.Module.linter.library = true
Colin Crossa97c5d32018-03-28 14:58:31 -0700626
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900627 android.InitApexModule(module)
Colin Cross48de9a42018-10-02 13:53:33 -0700628 InitJavaModule(module, android.DeviceSupported)
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -0500629 android.InitBazelModule(module)
Colin Crossa97c5d32018-03-28 14:58:31 -0700630 return module
631}
632
Colin Crossfabb6082018-02-20 17:22:23 -0800633//
634// AAR (android library) prebuilts
635//
Colin Crossfabb6082018-02-20 17:22:23 -0800636
Vinh Trance0781f2022-04-13 01:30:44 +0000637// Properties for android_library_import
Colin Crossfabb6082018-02-20 17:22:23 -0800638type AARImportProperties struct {
Vinh Trance0781f2022-04-13 01:30:44 +0000639 // ARR (android library prebuilt) filepath. Exactly one ARR is required.
Colin Cross27b922f2019-03-04 22:35:41 -0800640 Aars []string `android:"path"`
Vinh Trance0781f2022-04-13 01:30:44 +0000641 // If not blank, set to the version of the sdk to compile against.
642 // Defaults to private.
643 // Values are of one of the following forms:
644 // 1) numerical API level, "current", "none", or "core_platform"
645 // 2) An SDK kind with an API level: "<sdk kind>_<API level>"
646 // See build/soong/android/sdk_version.go for the complete and up to date list of SDK kinds.
647 // If the SDK kind is empty, it will be set to public
648 Sdk_version *string
649 // If not blank, set the minimum version of the sdk that the compiled artifacts will run against.
650 // Defaults to sdk_version if not set. See sdk_version for possible values.
Colin Cross479884c2018-07-10 13:39:30 -0700651 Min_sdk_version *string
Vinh Trance0781f2022-04-13 01:30:44 +0000652 // List of java static libraries that the included ARR (android library prebuilts) has dependencies to.
Colin Crossa97c5d32018-03-28 14:58:31 -0700653 Static_libs []string
Vinh Trance0781f2022-04-13 01:30:44 +0000654 // List of java libraries that the included ARR (android library prebuilts) has dependencies to.
655 Libs []string
656 // If set to true, run Jetifier against .aar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -0700657 Jetifier *bool
Sam Delmerico82602492022-06-10 17:05:42 +0000658 // If true, extract JNI libs from AAR archive. These libs will be accessible to android_app modules and
659 // will be passed transitively through android_libraries to an android_app.
660 //TODO(b/241138093) evaluate whether we can have this flag default to true for Bazel conversion
661 Extract_jni *bool
Colin Crossfabb6082018-02-20 17:22:23 -0800662}
663
664type AARImport struct {
665 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -0700666 android.DefaultableModuleBase
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900667 android.ApexModuleBase
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -0500668 android.BazelModuleBase
Colin Crossfabb6082018-02-20 17:22:23 -0800669 prebuilt android.Prebuilt
670
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900671 // Functionality common to Module and Import.
672 embeddableInModuleAndImport
673
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500674 providesTransitiveHeaderJars
675
Colin Crossfabb6082018-02-20 17:22:23 -0800676 properties AARImportProperties
677
Colin Cross66f78822018-05-02 12:58:28 -0700678 classpathFile android.WritablePath
679 proguardFlags android.WritablePath
680 exportPackage android.WritablePath
681 extraAaptPackagesFile android.WritablePath
Colin Cross10f7c4a2018-05-23 10:59:28 -0700682 manifest android.WritablePath
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800683 assetsPackage android.WritablePath
Colin Cross66f78822018-05-02 12:58:28 -0700684
685 exportedStaticPackages android.Paths
Colin Cross56a83212020-09-15 18:30:11 -0700686
687 hideApexVariantFromMake bool
Saeid Farivar Asanjanf0436962020-10-05 19:09:09 +0000688
Sam Delmerico82602492022-06-10 17:05:42 +0000689 aarPath android.Path
690 jniPackages android.Paths
Jiyong Park92315372021-04-02 08:45:46 +0900691
692 sdkVersion android.SdkSpec
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000693 minSdkVersion android.ApiLevel
Saeid Farivar Asanjanf0436962020-10-05 19:09:09 +0000694}
695
696var _ android.OutputFileProducer = (*AARImport)(nil)
697
698// For OutputFileProducer interface
699func (a *AARImport) OutputFiles(tag string) (android.Paths, error) {
700 switch tag {
701 case ".aar":
702 return []android.Path{a.aarPath}, nil
703 case "":
704 return []android.Path{a.classpathFile}, nil
705 default:
706 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
707 }
Colin Crossfabb6082018-02-20 17:22:23 -0800708}
709
Jiyong Park92315372021-04-02 08:45:46 +0900710func (a *AARImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
711 return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700712}
713
Jiyong Parkf1691d22021-03-29 20:11:58 +0900714func (a *AARImport) SystemModules() string {
Paul Duffine25c6442019-10-11 13:50:28 +0100715 return ""
716}
717
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000718func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
Colin Cross479884c2018-07-10 13:39:30 -0700719 if a.properties.Min_sdk_version != nil {
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000720 return android.ApiLevelFrom(ctx, *a.properties.Min_sdk_version)
Colin Cross479884c2018-07-10 13:39:30 -0700721 }
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000722 return a.SdkVersion(ctx).ApiLevel
Colin Cross83bb3162018-06-25 15:48:06 -0700723}
724
Spandan Dasa26eda72023-03-02 00:56:06 +0000725func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel {
726 return android.SdkSpecFrom(ctx, "").ApiLevel
William Loh5a082f92022-05-17 20:21:50 +0000727}
728
Spandan Dasca70fc42023-03-01 23:38:49 +0000729func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
730 return a.SdkVersion(ctx).ApiLevel
Dan Willemsen419290a2018-10-31 15:28:47 -0700731}
732
Colin Cross1e743852019-10-28 11:37:20 -0700733func (a *AARImport) javaVersion() string {
734 return ""
735}
736
Colin Crossa97c5d32018-03-28 14:58:31 -0700737var _ AndroidLibraryDependency = (*AARImport)(nil)
738
739func (a *AARImport) ExportPackage() android.Path {
740 return a.exportPackage
741}
742
Colin Cross89c31582018-04-30 15:55:11 -0700743func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
744 return android.Paths{a.proguardFlags}
745}
746
Anton Hansson53c88442019-03-18 15:53:16 +0000747func (a *AARImport) ExportedRRODirs() []rroDir {
Colin Crossc1c37552019-01-31 11:42:41 -0800748 return nil
749}
750
Colin Cross66f78822018-05-02 12:58:28 -0700751func (a *AARImport) ExportedStaticPackages() android.Paths {
752 return a.exportedStaticPackages
753}
754
Colin Cross90c25c62019-04-19 16:22:57 -0700755func (a *AARImport) ExportedManifests() android.Paths {
756 return android.Paths{a.manifest}
Colin Cross31656952018-05-24 16:11:20 -0700757}
758
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800759func (a *AARImport) ExportedAssets() android.OptionalPath {
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800760 return android.OptionalPathForPath(a.assetsPackage)
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800761}
762
Jaewoong Jungc779cd42020-10-06 18:56:10 -0700763// RRO enforcement is not available on aar_import since its RRO dirs are not
764// exported.
765func (a *AARImport) SetRROEnforcedForDependent(enforce bool) {
766}
767
768// RRO enforcement is not available on aar_import since its RRO dirs are not
769// exported.
770func (a *AARImport) IsRROEnforced(ctx android.BaseModuleContext) bool {
771 return false
772}
773
Colin Crossfabb6082018-02-20 17:22:23 -0800774func (a *AARImport) Prebuilt() *android.Prebuilt {
775 return &a.prebuilt
776}
777
778func (a *AARImport) Name() string {
779 return a.prebuilt.Name(a.ModuleBase.Name())
780}
781
Jiyong Park618922e2020-01-08 13:35:43 +0900782func (a *AARImport) JacocoReportClassesFile() android.Path {
783 return nil
784}
785
Colin Crossfabb6082018-02-20 17:22:23 -0800786func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) {
Jeongik Cha816a23a2020-07-08 01:09:23 +0900787 if !ctx.Config().AlwaysUsePrebuiltSdks() {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900788 sdkDep := decodeSdkDep(ctx, android.SdkContext(a))
Colin Crossa97c5d32018-03-28 14:58:31 -0700789 if sdkDep.useModule && sdkDep.frameworkResModule != "" {
Colin Cross42d48b72018-08-29 14:10:52 -0700790 ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule)
Colin Crossfabb6082018-02-20 17:22:23 -0800791 }
792 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700793
Colin Cross42d48b72018-08-29 14:10:52 -0700794 ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...)
795 ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...)
Colin Crossfabb6082018-02-20 17:22:23 -0800796}
797
Sam Delmerico82602492022-06-10 17:05:42 +0000798type JniPackageInfo struct {
799 // List of zip files containing JNI libraries
800 // Zip files should have directory structure jni/<arch>/*.so
801 JniPackages android.Paths
802}
803
804var JniPackageProvider = blueprint.NewProvider(JniPackageInfo{})
805
806// Unzip an AAR and extract the JNI libs for $archString.
807var extractJNI = pctx.AndroidStaticRule("extractJNI",
808 blueprint.RuleParams{
809 Command: `rm -rf $out $outDir && touch $out && ` +
810 `unzip -qoDD -d $outDir $in "jni/${archString}/*" && ` +
811 `jni_files=$$(find $outDir/jni -type f) && ` +
812 // print error message if there are no JNI libs for this arch
813 `[ -n "$$jni_files" ] || (echo "ERROR: no JNI libs found for arch ${archString}" && exit 1) && ` +
814 `${config.SoongZipCmd} -o $out -P 'lib/${archString}' ` +
815 `-C $outDir/jni/${archString} $$(echo $$jni_files | xargs -n1 printf " -f %s")`,
816 CommandDeps: []string{"${config.SoongZipCmd}"},
817 },
818 "outDir", "archString")
819
Colin Crossfabb6082018-02-20 17:22:23 -0800820// 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 -0700821// 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 -0800822var unzipAAR = pctx.AndroidStaticRule("unzipAAR",
823 blueprint.RuleParams{
Dan Willemsen304cfec2019-05-28 14:49:06 -0700824 Command: `rm -rf $outDir && mkdir -p $outDir && ` +
Colin Cross205e9112020-08-06 13:20:17 -0700825 `unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` +
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800826 `${config.Zip2ZipCmd} -i $in -o $assetsPackage 'assets/**/*' && ` +
Colin Cross205e9112020-08-06 13:20:17 -0700827 `${config.MergeZipsCmd} $combinedClassesJar $$(ls $outDir/classes.jar 2> /dev/null) $$(ls $outDir/libs/*.jar 2> /dev/null)`,
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800828 CommandDeps: []string{"${config.MergeZipsCmd}", "${config.Zip2ZipCmd}"},
Colin Crossfabb6082018-02-20 17:22:23 -0800829 },
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800830 "outDir", "combinedClassesJar", "assetsPackage")
Colin Crossfabb6082018-02-20 17:22:23 -0800831
832func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
833 if len(a.properties.Aars) != 1 {
834 ctx.PropertyErrorf("aars", "exactly one aar is required")
835 return
836 }
837
Jiyong Park92315372021-04-02 08:45:46 +0900838 a.sdkVersion = a.SdkVersion(ctx)
839 a.minSdkVersion = a.MinSdkVersion(ctx)
840
Colin Cross56a83212020-09-15 18:30:11 -0700841 a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
842
Nan Zhang4c819fb2018-08-27 18:31:46 -0700843 aarName := ctx.ModuleName() + ".aar"
Saeid Farivar Asanjanf0436962020-10-05 19:09:09 +0000844 a.aarPath = android.PathForModuleSrc(ctx, a.properties.Aars[0])
845
Colin Cross1001a792019-03-21 22:21:39 -0700846 if Bool(a.properties.Jetifier) {
Saeid Farivar Asanjanf0436962020-10-05 19:09:09 +0000847 inputFile := a.aarPath
848 a.aarPath = android.PathForModuleOut(ctx, "jetifier", aarName)
849 TransformJetifier(ctx, a.aarPath.(android.WritablePath), inputFile)
Nan Zhang4c819fb2018-08-27 18:31:46 -0700850 }
Colin Crossfabb6082018-02-20 17:22:23 -0800851
852 extractedAARDir := android.PathForModuleOut(ctx, "aar")
Colin Cross205e9112020-08-06 13:20:17 -0700853 a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar")
Colin Crossfabb6082018-02-20 17:22:23 -0800854 a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt")
Colin Cross10f7c4a2018-05-23 10:59:28 -0700855 a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml")
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800856 a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip")
Colin Crossfabb6082018-02-20 17:22:23 -0800857
858 ctx.Build(pctx, android.BuildParams{
859 Rule: unzipAAR,
Saeid Farivar Asanjanf0436962020-10-05 19:09:09 +0000860 Input: a.aarPath,
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800861 Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage},
Colin Crossfabb6082018-02-20 17:22:23 -0800862 Description: "unzip AAR",
863 Args: map[string]string{
Colin Cross205e9112020-08-06 13:20:17 -0700864 "outDir": extractedAARDir.String(),
865 "combinedClassesJar": a.classpathFile.String(),
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800866 "assetsPackage": a.assetsPackage.String(),
Colin Crossfabb6082018-02-20 17:22:23 -0800867 },
868 })
869
Colin Crossa0ba2f52019-06-22 12:59:27 -0700870 // Always set --pseudo-localize, it will be stripped out later for release
871 // builds that don't want it.
872 compileFlags := []string{"--pseudo-localize"}
Colin Crossfabb6082018-02-20 17:22:23 -0800873 compiledResDir := android.PathForModuleOut(ctx, "flat-res")
Colin Crossfabb6082018-02-20 17:22:23 -0800874 flata := compiledResDir.Join(ctx, "gen_res.flata")
Saeid Farivar Asanjanf0436962020-10-05 19:09:09 +0000875 aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags)
Colin Crossfabb6082018-02-20 17:22:23 -0800876
877 a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
Jiyong Parkb7c639e2019-08-19 14:56:02 +0900878 // the subdir "android" is required to be filtered by package names
879 srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
Colin Crossfabb6082018-02-20 17:22:23 -0800880 proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
Colin Crossa97c5d32018-03-28 14:58:31 -0700881 rTxt := android.PathForModuleOut(ctx, "R.txt")
Colin Cross66f78822018-05-02 12:58:28 -0700882 a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
Colin Crossfabb6082018-02-20 17:22:23 -0800883
884 var linkDeps android.Paths
885
886 linkFlags := []string{
887 "--static-lib",
888 "--no-static-lib-packages",
889 "--auto-add-overlay",
890 }
891
Colin Cross10f7c4a2018-05-23 10:59:28 -0700892 linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
893 linkDeps = append(linkDeps, a.manifest)
Colin Crossfabb6082018-02-20 17:22:23 -0800894
Ulya Trafimovich18554242020-11-03 15:55:11 +0000895 transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags :=
Jiyong Parkf1691d22021-03-29 20:11:58 +0900896 aaptLibs(ctx, android.SdkContext(a), nil)
Colin Cross31656952018-05-24 16:11:20 -0700897
898 _ = staticLibManifests
Colin Crossc1c37552019-01-31 11:42:41 -0800899 _ = staticRRODirs
Colin Crossfabb6082018-02-20 17:22:23 -0800900
Colin Crossa97c5d32018-03-28 14:58:31 -0700901 linkDeps = append(linkDeps, libDeps...)
902 linkFlags = append(linkFlags, libFlags...)
Colin Crossfabb6082018-02-20 17:22:23 -0800903
Colin Cross66f78822018-05-02 12:58:28 -0700904 overlayRes := append(android.Paths{flata}, transitiveStaticLibs...)
Colin Crossfabb6082018-02-20 17:22:23 -0800905
Colin Cross66f78822018-05-02 12:58:28 -0700906 aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
Jaewoong Jung6431ca72020-01-15 14:15:10 -0800907 linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
Colin Crossfabb6082018-02-20 17:22:23 -0800908
Michael Rosenfeld5ad15572021-12-03 13:25:10 -0800909 // Merge this import's assets with its dependencies' assets (if there are any).
910 if len(transitiveAssets) > 0 {
911 mergedAssets := android.PathForModuleOut(ctx, "merged-assets.zip")
912 inputZips := append(android.Paths{a.assetsPackage}, transitiveAssets...)
913 ctx.Build(pctx, android.BuildParams{
914 Rule: mergeAssetsRule,
915 Inputs: inputZips,
916 Output: mergedAssets,
917 Description: "merge assets from dependencies and self",
918 })
919 a.assetsPackage = mergedAssets
920 }
921
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500922 a.collectTransitiveHeaderJars(ctx)
Colin Crossdcf71b22021-02-01 13:59:03 -0800923 ctx.SetProvider(JavaInfoProvider, JavaInfo{
924 HeaderJars: android.PathsIfNonNil(a.classpathFile),
Sam Delmerico9f9c0a22022-11-29 11:19:37 -0500925 TransitiveLibsHeaderJars: a.transitiveLibsHeaderJars,
926 TransitiveStaticLibsHeaderJars: a.transitiveStaticLibsHeaderJars,
Colin Crossdcf71b22021-02-01 13:59:03 -0800927 ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile),
928 ImplementationJars: android.PathsIfNonNil(a.classpathFile),
929 })
Sam Delmerico82602492022-06-10 17:05:42 +0000930
931 if proptools.Bool(a.properties.Extract_jni) {
932 for _, t := range ctx.MultiTargets() {
933 arch := t.Arch.Abi[0]
934 path := android.PathForModuleOut(ctx, arch+"_jni.zip")
935 a.jniPackages = append(a.jniPackages, path)
936
937 outDir := android.PathForModuleOut(ctx, "aarForJni")
938 aarPath := android.PathForModuleSrc(ctx, a.properties.Aars[0])
939 ctx.Build(pctx, android.BuildParams{
940 Rule: extractJNI,
941 Input: aarPath,
942 Outputs: android.WritablePaths{path},
943 Description: "extract JNI from AAR",
944 Args: map[string]string{
945 "outDir": outDir.String(),
946 "archString": arch,
947 },
948 })
949 }
950
951 ctx.SetProvider(JniPackageProvider, JniPackageInfo{
952 JniPackages: a.jniPackages,
953 })
954 }
Colin Crossdcf71b22021-02-01 13:59:03 -0800955}
Colin Crossfabb6082018-02-20 17:22:23 -0800956
957func (a *AARImport) HeaderJars() android.Paths {
958 return android.Paths{a.classpathFile}
959}
960
Colin Cross331a1212018-08-15 20:40:52 -0700961func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
962 return android.Paths{a.classpathFile}
963}
964
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000965func (a *AARImport) DexJarBuildPath() android.Path {
Colin Crossf24a22a2019-01-31 14:12:44 -0800966 return nil
967}
968
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +0100969func (a *AARImport) DexJarInstallPath() android.Path {
970 return nil
971}
972
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +0100973func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
Jiyong Park1be96912018-05-28 18:02:19 +0900974 return nil
975}
976
Jiyong Park45bf82e2020-12-15 22:29:02 +0900977var _ android.ApexModule = (*AARImport)(nil)
978
979// Implements android.ApexModule
Jooyung Hanacc7bbe2020-05-20 09:06:00 +0900980func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
981 return a.depIsInSameApex(ctx, dep)
982}
983
Jiyong Park45bf82e2020-12-15 22:29:02 +0900984// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -0700985func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
986 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900987 return nil
988}
989
Sam Delmericoaf8bb702022-07-25 15:39:32 -0400990var _ android.PrebuiltInterface = (*AARImport)(nil)
Colin Crossfabb6082018-02-20 17:22:23 -0800991
Colin Cross1b16b0e2019-02-12 14:41:32 -0800992// android_library_import imports an `.aar` file into the build graph as if it was built with android_library.
993//
994// This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of
995// an android_app module.
Colin Crossfabb6082018-02-20 17:22:23 -0800996func AARImportFactory() android.Module {
997 module := &AARImport{}
998
999 module.AddProperties(&module.properties)
1000
1001 android.InitPrebuiltModule(module, &module.properties.Aars)
Jooyung Hanacc7bbe2020-05-20 09:06:00 +09001002 android.InitApexModule(module)
Sam Delmerico82602492022-06-10 17:05:42 +00001003 InitJavaModuleMultiTargets(module, android.DeviceSupported)
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001004 android.InitBazelModule(module)
Colin Crossfabb6082018-02-20 17:22:23 -08001005 return module
1006}
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001007
1008type bazelAapt struct {
1009 Manifest bazel.Label
1010 Resource_files bazel.LabelListAttribute
1011}
1012
1013type bazelAndroidLibrary struct {
1014 *javaLibraryAttributes
1015 *bazelAapt
1016}
1017
1018type bazelAndroidLibraryImport struct {
1019 Aar bazel.Label
1020 Deps bazel.LabelListAttribute
1021 Exports bazel.LabelListAttribute
1022}
1023
1024func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) *bazelAapt {
1025 manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
1026
1027 resourceFiles := bazel.LabelList{
1028 Includes: []bazel.Label{},
1029 }
1030 for _, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") {
1031 files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))
1032 resourceFiles.Includes = append(resourceFiles.Includes, files...)
1033 }
1034 return &bazelAapt{
1035 android.BazelLabelForModuleSrcSingle(ctx, manifest),
1036 bazel.MakeLabelListAttribute(resourceFiles),
1037 }
1038}
1039
1040func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
1041 aars := android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Aars, []string{})
1042 exportableStaticLibs := []string{}
1043 // TODO(b/240716882): investigate and handle static_libs deps that are not imports. They are not supported for export by Bazel.
1044 for _, depName := range a.properties.Static_libs {
1045 if dep, ok := ctx.ModuleFromName(depName); ok {
1046 switch dep.(type) {
1047 case *AARImport, *Import:
1048 exportableStaticLibs = append(exportableStaticLibs, depName)
1049 }
1050 }
1051 }
1052 name := android.RemoveOptionalPrebuiltPrefix(a.Name())
1053 deps := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(append(a.properties.Static_libs, a.properties.Libs...))))
1054 exports := android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(exportableStaticLibs))
1055
1056 ctx.CreateBazelTargetModule(
1057 bazel.BazelTargetModuleProperties{
1058 Rule_class: "aar_import",
Romain Jobredeaux5ccb4602022-12-19 11:17:16 -05001059 Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001060 },
1061 android.CommonAttributes{Name: name},
1062 &bazelAndroidLibraryImport{
1063 Aar: aars.Includes[0],
1064 Deps: bazel.MakeLabelListAttribute(deps),
1065 Exports: bazel.MakeLabelListAttribute(exports),
1066 },
1067 )
1068
Alix14101de2023-01-06 03:42:07 +00001069 neverlink := true
1070 ctx.CreateBazelTargetModule(
Alix32540022023-03-16 21:06:13 +00001071 AndroidLibraryBazelTargetModuleProperties(),
Alix14101de2023-01-06 03:42:07 +00001072 android.CommonAttributes{Name: name + "-neverlink"},
1073 &bazelAndroidLibrary{
1074 javaLibraryAttributes: &javaLibraryAttributes{
1075 Neverlink: bazel.BoolAttribute{Value: &neverlink},
1076 Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
1077 },
1078 },
1079 )
1080
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001081}
Alix32540022023-03-16 21:06:13 +00001082func AndroidLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties {
1083 return bazel.BazelTargetModuleProperties{
1084 Rule_class: "android_library",
1085 Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
1086 }
1087}
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001088
1089func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
Alix8062f4d2022-11-14 21:38:07 +00001090 commonAttrs, bp2buildInfo := a.convertLibraryAttrsBp2Build(ctx)
1091 depLabels := bp2buildInfo.DepLabels
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001092
1093 deps := depLabels.Deps
1094 if !commonAttrs.Srcs.IsEmpty() {
1095 deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
1096 } else if !depLabels.Deps.IsEmpty() {
1097 ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
1098 }
Alix82fb94e2022-10-26 20:40:18 +00001099 name := a.Name()
Alix32540022023-03-16 21:06:13 +00001100 props := AndroidLibraryBazelTargetModuleProperties()
Alix82fb94e2022-10-26 20:40:18 +00001101
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001102 ctx.CreateBazelTargetModule(
Alix82fb94e2022-10-26 20:40:18 +00001103 props,
1104 android.CommonAttributes{Name: name},
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001105 &bazelAndroidLibrary{
1106 &javaLibraryAttributes{
1107 javaCommonAttributes: commonAttrs,
1108 Deps: deps,
1109 Exports: depLabels.StaticDeps,
1110 },
1111 a.convertAaptAttrsWithBp2Build(ctx),
1112 },
1113 )
Alix82fb94e2022-10-26 20:40:18 +00001114
1115 neverlink := true
1116 ctx.CreateBazelTargetModule(
1117 props,
1118 android.CommonAttributes{Name: name + "-neverlink"},
1119 &bazelAndroidLibrary{
1120 javaLibraryAttributes: &javaLibraryAttributes{
1121 Neverlink: bazel.BoolAttribute{Value: &neverlink},
1122 Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
1123 },
1124 },
1125 )
Romain Jobredeauxc9b2bba2022-02-15 09:35:07 -05001126}