| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 18 | "fmt" | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 19 | "path/filepath" | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 20 | "slices" | 
| Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 21 | "strconv" | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 22 | "strings" | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 23 |  | 
| Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 24 | "android/soong/android" | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 25 | "android/soong/dexpreopt" | 
| Jihoon Kang | fe914ed | 2024-02-12 22:49:21 +0000 | [diff] [blame] | 26 |  | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 27 | "github.com/google/blueprint" | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 29 | ) | 
|  | 30 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 31 | type AndroidLibraryDependency interface { | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 32 | ExportPackage() android.Path | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 33 | ResourcesNodeDepSet() *android.DepSet[*resourcesNode] | 
|  | 34 | RRODirsDepSet() *android.DepSet[rroDir] | 
|  | 35 | ManifestsDepSet() *android.DepSet[android.Path] | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 36 | SetRROEnforcedForDependent(enforce bool) | 
|  | 37 | IsRROEnforced(ctx android.BaseModuleContext) bool | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 38 | } | 
|  | 39 |  | 
|  | 40 | func init() { | 
| Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 41 | RegisterAARBuildComponents(android.InitRegistrationContext) | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | func RegisterAARBuildComponents(ctx android.RegistrationContext) { | 
|  | 45 | ctx.RegisterModuleType("android_library_import", AARImportFactory) | 
|  | 46 | ctx.RegisterModuleType("android_library", AndroidLibraryFactory) | 
| Paul Duffin | 04ba70d | 2021-03-22 13:56:43 +0000 | [diff] [blame] | 47 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { | 
| Colin Cross | 7e6a901 | 2024-01-17 14:58:38 -0800 | [diff] [blame] | 48 | ctx.TopDown("propagate_rro_enforcement", propagateRROEnforcementMutator) | 
| Paul Duffin | 04ba70d | 2021-03-22 13:56:43 +0000 | [diff] [blame] | 49 | }) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 50 | } | 
|  | 51 |  | 
|  | 52 | // | 
|  | 53 | // AAR (android library) | 
|  | 54 | // | 
|  | 55 |  | 
|  | 56 | type androidLibraryProperties struct { | 
|  | 57 | BuildAAR bool `blueprint:"mutated"` | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | type aaptProperties struct { | 
|  | 61 | // flags passed to aapt when creating the apk | 
|  | 62 | Aaptflags []string | 
|  | 63 |  | 
| Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 64 | // include all resource configurations, not just the product-configured | 
|  | 65 | // ones. | 
|  | 66 | Aapt_include_all_resources *bool | 
|  | 67 |  | 
| Jiakai Zhang | ba82e28 | 2023-10-13 18:08:59 +0100 | [diff] [blame] | 68 | // list of files to use as assets. | 
|  | 69 | Assets []string `android:"path"` | 
|  | 70 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 71 | // list of directories relative to the Blueprints file containing assets. | 
| Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 72 | // Defaults to ["assets"] if a directory called assets exists.  Set to [] | 
|  | 73 | // to disable the default. | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 74 | Asset_dirs []string | 
|  | 75 |  | 
|  | 76 | // list of directories relative to the Blueprints file containing | 
| Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 77 | // Android resources.  Defaults to ["res"] if a directory called res exists. | 
|  | 78 | // Set to [] to disable the default. | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 79 | Resource_dirs []string | 
|  | 80 |  | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 81 | // list of zip files containing Android resources. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 82 | Resource_zips []string `android:"path"` | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 83 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 84 | // path to AndroidManifest.xml.  If unset, defaults to "AndroidManifest.xml". | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 85 | Manifest *string `android:"path"` | 
| changho.shin | b5432b7 | 2019-08-08 18:37:17 +0900 | [diff] [blame] | 86 |  | 
|  | 87 | // paths to additional manifest files to merge with main manifest. | 
|  | 88 | Additional_manifests []string `android:"path"` | 
| Sasha Smundak | 541056c | 2019-10-28 15:50:06 -0700 | [diff] [blame] | 89 |  | 
|  | 90 | // do not include AndroidManifest from dependent libraries | 
|  | 91 | Dont_merge_manifests *bool | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 92 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 93 | // If use_resource_processor is set, use Bazel's resource processor instead of aapt2 to generate R.class files. | 
|  | 94 | // The resource processor produces more optimal R.class files that only list resources in the package of the | 
|  | 95 | // library that provided them, as opposed to aapt2 which produces R.java files for every package containing | 
|  | 96 | // every resource.  Using the resource processor can provide significant build time speedups, but requires | 
|  | 97 | // fixing the module to use the correct package to reference each resource, and to avoid having any other | 
|  | 98 | // libraries in the tree that use the same package name.  Defaults to false, but will default to true in the | 
|  | 99 | // future. | 
|  | 100 | Use_resource_processor *bool | 
|  | 101 |  | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 102 | // true if RRO is enforced for any of the dependent modules | 
|  | 103 | RROEnforcedForDependent bool `blueprint:"mutated"` | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 104 |  | 
|  | 105 | // Filter only specified product and ignore other products | 
|  | 106 | Filter_product *string `blueprint:"mutated"` | 
| Jihoon Kang | 9049c27 | 2024-03-19 21:57:36 +0000 | [diff] [blame] | 107 |  | 
|  | 108 | // Names of aconfig_declarations modules that specify aconfig flags that the module depends on. | 
|  | 109 | Flags_packages []string | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 110 | } | 
|  | 111 |  | 
|  | 112 | type aapt struct { | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 113 | aaptSrcJar                         android.Path | 
|  | 114 | transitiveAaptRJars                android.Paths | 
|  | 115 | transitiveAaptResourcePackagesFile android.Path | 
|  | 116 | exportPackage                      android.Path | 
|  | 117 | manifestPath                       android.Path | 
|  | 118 | proguardOptionsFile                android.Path | 
|  | 119 | rTxt                               android.Path | 
|  | 120 | rJar                               android.Path | 
|  | 121 | extraAaptPackagesFile              android.Path | 
|  | 122 | mergedManifestFile                 android.Path | 
|  | 123 | noticeFile                         android.OptionalPath | 
|  | 124 | assetPackage                       android.OptionalPath | 
|  | 125 | isLibrary                          bool | 
|  | 126 | defaultManifestVersion             string | 
|  | 127 | useEmbeddedNativeLibs              bool | 
|  | 128 | useEmbeddedDex                     bool | 
|  | 129 | usesNonSdkApis                     bool | 
|  | 130 | hasNoCode                          bool | 
|  | 131 | LoggingParent                      string | 
|  | 132 | resourceFiles                      android.Paths | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 133 |  | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 134 | splitNames []string | 
|  | 135 | splits     []split | 
|  | 136 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 137 | aaptProperties aaptProperties | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 138 |  | 
|  | 139 | resourcesNodesDepSet *android.DepSet[*resourcesNode] | 
|  | 140 | rroDirsDepSet        *android.DepSet[rroDir] | 
|  | 141 | manifestsDepSet      *android.DepSet[android.Path] | 
| Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 142 |  | 
|  | 143 | manifestValues struct { | 
|  | 144 | applicationId string | 
|  | 145 | } | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 146 | } | 
|  | 147 |  | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 148 | type split struct { | 
|  | 149 | name   string | 
|  | 150 | suffix string | 
|  | 151 | path   android.Path | 
|  | 152 | } | 
|  | 153 |  | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 154 | // Propagate RRO enforcement flag to static lib dependencies transitively. | 
|  | 155 | func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) { | 
|  | 156 | m := ctx.Module() | 
|  | 157 | if d, ok := m.(AndroidLibraryDependency); ok && d.IsRROEnforced(ctx) { | 
|  | 158 | ctx.VisitDirectDepsWithTag(staticLibTag, func(d android.Module) { | 
|  | 159 | if a, ok := d.(AndroidLibraryDependency); ok { | 
|  | 160 | a.SetRROEnforcedForDependent(true) | 
|  | 161 | } | 
|  | 162 | }) | 
|  | 163 | } | 
|  | 164 | } | 
|  | 165 |  | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 166 | func (a *aapt) useResourceProcessorBusyBox(ctx android.BaseModuleContext) bool { | 
| Colin Cross | eee4ab1 | 2024-03-27 11:54:10 -0700 | [diff] [blame] | 167 | return BoolDefault(a.aaptProperties.Use_resource_processor, ctx.Config().UseResourceProcessorByDefault()) && | 
|  | 168 | // TODO(b/331641946): remove this when ResourceProcessorBusyBox supports generating shared libraries. | 
|  | 169 | !slices.Contains(a.aaptProperties.Aaptflags, "--shared-lib") | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 172 | func (a *aapt) filterProduct() string { | 
|  | 173 | return String(a.aaptProperties.Filter_product) | 
|  | 174 | } | 
|  | 175 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 176 | func (a *aapt) ExportPackage() android.Path { | 
|  | 177 | return a.exportPackage | 
|  | 178 | } | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 179 | func (a *aapt) ResourcesNodeDepSet() *android.DepSet[*resourcesNode] { | 
|  | 180 | return a.resourcesNodesDepSet | 
| Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 181 | } | 
|  | 182 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 183 | func (a *aapt) RRODirsDepSet() *android.DepSet[rroDir] { | 
|  | 184 | return a.rroDirsDepSet | 
| Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 185 | } | 
|  | 186 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 187 | func (a *aapt) ManifestsDepSet() *android.DepSet[android.Path] { | 
|  | 188 | return a.manifestsDepSet | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 189 | } | 
|  | 190 |  | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 191 | func (a *aapt) SetRROEnforcedForDependent(enforce bool) { | 
|  | 192 | a.aaptProperties.RROEnforcedForDependent = enforce | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | func (a *aapt) IsRROEnforced(ctx android.BaseModuleContext) bool { | 
|  | 196 | // True if RRO is enforced for this module or... | 
|  | 197 | return ctx.Config().EnforceRROForModule(ctx.ModuleName()) || | 
| Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 198 | // if RRO is enforced for any of its dependents. | 
|  | 199 | a.aaptProperties.RROEnforcedForDependent | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 200 | } | 
|  | 201 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 202 | func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkContext, | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 203 | manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths, | 
|  | 204 | resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) { | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 205 |  | 
| Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 206 | hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code") | 
|  | 207 | hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name") | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 208 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 209 | // Flags specified in Android.bp | 
|  | 210 | linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...) | 
|  | 211 |  | 
| Eric Miao | 40eab20 | 2023-03-30 16:57:17 +0000 | [diff] [blame] | 212 | linkFlags = append(linkFlags, "--enable-compact-entries") | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 213 |  | 
|  | 214 | // Find implicit or explicit asset and resource dirs | 
| Jiakai Zhang | ba82e28 | 2023-10-13 18:08:59 +0100 | [diff] [blame] | 215 | assets := android.PathsRelativeToModuleSourceDir(android.SourceInput{ | 
|  | 216 | Context:     ctx, | 
|  | 217 | Paths:       a.aaptProperties.Assets, | 
|  | 218 | IncludeDirs: false, | 
|  | 219 | }) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 220 | assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") | 
|  | 221 | resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") | 
| Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 222 | resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 223 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 224 | // Glob directories into lists of paths | 
|  | 225 | for _, dir := range resourceDirs { | 
|  | 226 | resDirs = append(resDirs, globbedResourceDir{ | 
|  | 227 | dir:   dir, | 
|  | 228 | files: androidResourceGlob(ctx, dir), | 
|  | 229 | }) | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 230 | resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, a, dir) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 231 | overlayDirs = append(overlayDirs, resOverlayDirs...) | 
|  | 232 | rroDirs = append(rroDirs, resRRODirs...) | 
|  | 233 | } | 
|  | 234 |  | 
| Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 235 | var assetDeps android.Paths | 
|  | 236 | for i, dir := range assetDirs { | 
|  | 237 | // Add a dependency on every file in the asset directory.  This ensures the aapt2 | 
|  | 238 | // rule will be rerun if one of the files in the asset directory is modified. | 
|  | 239 | assetDeps = append(assetDeps, androidResourceGlob(ctx, dir)...) | 
|  | 240 |  | 
|  | 241 | // Add a dependency on a file that contains a list of all the files in the asset directory. | 
|  | 242 | // This ensures the aapt2 rule will be run if a file is removed from the asset directory, | 
|  | 243 | // or a file is added whose timestamp is older than the output of aapt2. | 
|  | 244 | assetFileListFile := android.PathForModuleOut(ctx, "asset_dir_globs", strconv.Itoa(i)+".glob") | 
|  | 245 | androidResourceGlobList(ctx, dir, assetFileListFile) | 
|  | 246 | assetDeps = append(assetDeps, assetFileListFile) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 247 | } | 
|  | 248 |  | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 249 | assetDirStrings := assetDirs.Strings() | 
|  | 250 | if a.noticeFile.Valid() { | 
|  | 251 | assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String())) | 
| Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 252 | assetDeps = append(assetDeps, a.noticeFile.Path()) | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 253 | } | 
| Jiakai Zhang | ba82e28 | 2023-10-13 18:08:59 +0100 | [diff] [blame] | 254 | if len(assets) > 0 { | 
|  | 255 | // aapt2 doesn't support adding individual asset files. Create a temp directory to hold asset | 
|  | 256 | // files and pass it to aapt2. | 
|  | 257 | tmpAssetDir := android.PathForModuleOut(ctx, "tmp_asset_dir") | 
|  | 258 |  | 
|  | 259 | rule := android.NewRuleBuilder(pctx, ctx) | 
|  | 260 | rule.Command(). | 
|  | 261 | Text("rm -rf").Text(tmpAssetDir.String()). | 
|  | 262 | Text("&&"). | 
|  | 263 | Text("mkdir -p").Text(tmpAssetDir.String()) | 
|  | 264 |  | 
|  | 265 | for _, asset := range assets { | 
|  | 266 | output := tmpAssetDir.Join(ctx, asset.Rel()) | 
|  | 267 | assetDeps = append(assetDeps, output) | 
|  | 268 | rule.Command().Text("mkdir -p").Text(filepath.Dir(output.String())) | 
|  | 269 | rule.Command().Text("cp").Input(asset).Output(output) | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | rule.Build("tmp_asset_dir", "tmp_asset_dir") | 
|  | 273 |  | 
|  | 274 | assetDirStrings = append(assetDirStrings, tmpAssetDir.String()) | 
|  | 275 | } | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 276 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 277 | linkFlags = append(linkFlags, "--manifest "+manifestPath.String()) | 
|  | 278 | linkDeps = append(linkDeps, manifestPath) | 
|  | 279 |  | 
| Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 280 | linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A ")) | 
| Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 281 | linkDeps = append(linkDeps, assetDeps...) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 282 |  | 
| Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 283 | // Returns the effective version for {min|target}_sdk_version | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 284 | effectiveVersionString := func(sdkVersion android.SdkSpec, minSdkVersion android.ApiLevel) string { | 
| Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 285 | // If {min|target}_sdk_version is current, use sdk_version to determine the effective level | 
|  | 286 | // This is necessary for vendor modules. | 
|  | 287 | // The effective version does not _only_ depend on {min|target}_sdk_version(level), | 
|  | 288 | // but also on the sdk_version (kind+level) | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 289 | if minSdkVersion.IsCurrent() { | 
| Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 290 | ret, err := sdkVersion.EffectiveVersionString(ctx) | 
|  | 291 | if err != nil { | 
|  | 292 | ctx.ModuleErrorf("invalid sdk_version: %s", err) | 
|  | 293 | } | 
|  | 294 | return ret | 
|  | 295 | } | 
|  | 296 | ret, err := minSdkVersion.EffectiveVersionString(ctx) | 
|  | 297 | if err != nil { | 
|  | 298 | ctx.ModuleErrorf("invalid min_sdk_version: %s", err) | 
|  | 299 | } | 
|  | 300 | return ret | 
| Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 301 | } | 
| Spandan Das | 50885c0 | 2023-02-23 21:31:33 +0000 | [diff] [blame] | 302 | // SDK version flags | 
|  | 303 | sdkVersion := sdkContext.SdkVersion(ctx) | 
|  | 304 | minSdkVersion := effectiveVersionString(sdkVersion, sdkContext.MinSdkVersion(ctx)) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 305 |  | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 306 | linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion) | 
| Spandan Das | 6450b55 | 2023-02-23 19:27:07 +0000 | [diff] [blame] | 307 | // Use minSdkVersion for target-sdk-version, even if `target_sdk_version` is set | 
|  | 308 | // This behavior has been copied from Make. | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 309 | linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 310 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 311 | // Version code | 
|  | 312 | if !hasVersionCode { | 
| Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 313 | linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String()) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 314 | } | 
|  | 315 |  | 
|  | 316 | if !hasVersionName { | 
| Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 317 | var versionName string | 
|  | 318 | if ctx.ModuleName() == "framework-res" { | 
|  | 319 | // Some builds set AppsDefaultVersionName() to include the build number ("O-123456").  aapt2 copies the | 
|  | 320 | // version name of framework-res into app manifests as compileSdkVersionCodename, which confuses things | 
| Colin Cross | bfd347d | 2018-05-09 11:11:35 -0700 | [diff] [blame] | 321 | // if it contains the build number.  Use the PlatformVersionName instead. | 
|  | 322 | versionName = ctx.Config().PlatformVersionName() | 
| Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 323 | } else { | 
|  | 324 | versionName = ctx.Config().AppsDefaultVersionName() | 
|  | 325 | } | 
| Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 326 | versionName = proptools.NinjaEscape(versionName) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 327 | linkFlags = append(linkFlags, "--version-name ", versionName) | 
|  | 328 | } | 
|  | 329 |  | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 330 | linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"}) | 
|  | 331 |  | 
|  | 332 | // Always set --pseudo-localize, it will be stripped out later for release | 
|  | 333 | // builds that don't want it. | 
|  | 334 | compileFlags = append(compileFlags, "--pseudo-localize") | 
|  | 335 |  | 
|  | 336 | return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 337 | } | 
|  | 338 |  | 
| Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 339 | func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) { | 
| Colin Cross | 42308aa | 2018-11-14 21:44:17 -0800 | [diff] [blame] | 340 | if sdkDep.frameworkResModule != "" { | 
|  | 341 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 342 | } | 
|  | 343 | } | 
|  | 344 |  | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 345 | var extractAssetsRule = pctx.AndroidStaticRule("extractAssets", | 
|  | 346 | blueprint.RuleParams{ | 
|  | 347 | Command:     `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`, | 
|  | 348 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, | 
|  | 349 | }) | 
|  | 350 |  | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 351 | type aaptBuildActionOptions struct { | 
|  | 352 | sdkContext                     android.SdkContext | 
|  | 353 | classLoaderContexts            dexpreopt.ClassLoaderContextMap | 
|  | 354 | excludedLibs                   []string | 
|  | 355 | enforceDefaultTargetSdkVersion bool | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 356 | forceNonFinalResourceIDs       bool | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 357 | extraLinkFlags                 []string | 
| Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 358 | aconfigTextFiles               android.Paths | 
| Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 359 | usesLibrary                    *usesLibrary | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 360 | } | 
|  | 361 |  | 
|  | 362 | func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptions) { | 
| Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 363 |  | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 364 | staticResourcesNodesDepSet, sharedResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedExportPackages, libFlags := | 
| Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 365 | aaptLibs(ctx, opts.sdkContext, opts.classLoaderContexts, opts.usesLibrary) | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 366 |  | 
| Paul Duffin | 0653057 | 2022-02-03 17:54:15 +0000 | [diff] [blame] | 367 | // Exclude any libraries from the supplied list. | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 368 | opts.classLoaderContexts = opts.classLoaderContexts.ExcludeLibs(opts.excludedLibs) | 
| Paul Duffin | 0653057 | 2022-02-03 17:54:15 +0000 | [diff] [blame] | 369 |  | 
| Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 370 | // App manifest file | 
|  | 371 | manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") | 
|  | 372 | manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) | 
|  | 373 |  | 
| Gurpreet Singh | 7deabfa | 2022-02-10 13:28:35 +0000 | [diff] [blame] | 374 | manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{ | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 375 | SdkContext:                     opts.sdkContext, | 
|  | 376 | ClassLoaderContexts:            opts.classLoaderContexts, | 
| Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 377 | IsLibrary:                      a.isLibrary, | 
|  | 378 | DefaultManifestVersion:         a.defaultManifestVersion, | 
|  | 379 | UseEmbeddedNativeLibs:          a.useEmbeddedNativeLibs, | 
|  | 380 | UsesNonSdkApis:                 a.usesNonSdkApis, | 
|  | 381 | UseEmbeddedDex:                 a.useEmbeddedDex, | 
|  | 382 | HasNoCode:                      a.hasNoCode, | 
|  | 383 | LoggingParent:                  a.LoggingParent, | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 384 | EnforceDefaultTargetSdkVersion: opts.enforceDefaultTargetSdkVersion, | 
| Gurpreet Singh | 75d65f3 | 2022-01-24 17:44:05 +0000 | [diff] [blame] | 385 | }) | 
| Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 386 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 387 | staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList()) | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 388 | sharedDeps := transitiveAarDeps(sharedResourcesNodesDepSet.ToList()) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 389 |  | 
| Luca Stefani | fd89882 | 2019-09-10 22:13:31 +0200 | [diff] [blame] | 390 | // Add additional manifest files to transitive manifests. | 
|  | 391 | additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 392 | transitiveManifestPaths := append(android.Paths{manifestPath}, additionalManifests...) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 393 | transitiveManifestPaths = append(transitiveManifestPaths, staticManifestsDepSet.ToList()...) | 
| Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 394 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 395 | if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) { | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 396 | manifestMergerParams := ManifestMergerParams{ | 
|  | 397 | staticLibManifests: transitiveManifestPaths[1:], | 
| Alix | 96ea8845 | 2023-08-31 15:48:23 +0000 | [diff] [blame] | 398 | isLibrary:          a.isLibrary, | 
|  | 399 | packageName:        a.manifestValues.applicationId, | 
|  | 400 | } | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 401 | a.mergedManifestFile = manifestMerger(ctx, transitiveManifestPaths[0], manifestMergerParams) | 
| Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 402 | if !a.isLibrary { | 
|  | 403 | // Only use the merged manifest for applications.  For libraries, the transitive closure of manifests | 
|  | 404 | // will be propagated to the final application and merged there.  The merged manifest for libraries is | 
|  | 405 | // only passed to Make, which can't handle transitive dependencies. | 
|  | 406 | manifestPath = a.mergedManifestFile | 
|  | 407 | } | 
|  | 408 | } else { | 
|  | 409 | a.mergedManifestFile = manifestPath | 
|  | 410 | } | 
| Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 411 |  | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 412 | compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, opts.sdkContext, manifestPath) | 
| Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 413 |  | 
|  | 414 | linkFlags = append(linkFlags, libFlags...) | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 415 | linkDeps = append(linkDeps, sharedExportPackages...) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 416 | linkDeps = append(linkDeps, staticDeps.resPackages()...) | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 417 | linkFlags = append(linkFlags, opts.extraLinkFlags...) | 
| Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame] | 418 | if a.isLibrary { | 
|  | 419 | linkFlags = append(linkFlags, "--static-lib") | 
|  | 420 | } | 
| Rico Wind | 7152e82 | 2024-04-19 08:14:15 +0200 | [diff] [blame] | 421 | if opts.forceNonFinalResourceIDs { | 
|  | 422 | linkFlags = append(linkFlags, "--non-final-ids") | 
|  | 423 | } | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 424 |  | 
| Colin Cross | 7c4dc5d | 2024-02-13 14:29:45 -0800 | [diff] [blame] | 425 | linkFlags = append(linkFlags, "--no-static-lib-packages") | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 426 | if a.isLibrary && a.useResourceProcessorBusyBox(ctx) { | 
| Colin Cross | 7c4dc5d | 2024-02-13 14:29:45 -0800 | [diff] [blame] | 427 | // When building an android_library using ResourceProcessorBusyBox pass --merge-only to skip resource | 
|  | 428 | // references validation until the final app link step when all static libraries are present. | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 429 | linkFlags = append(linkFlags, "--merge-only") | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 430 | } | 
|  | 431 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 432 | packageRes := android.PathForModuleOut(ctx, "package-res.apk") | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 433 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") | 
|  | 434 | rTxt := android.PathForModuleOut(ctx, "R.txt") | 
| Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 435 | // This file isn't used by Soong, but is generated for exporting | 
|  | 436 | extraPackages := android.PathForModuleOut(ctx, "extra_packages") | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 437 | var transitiveRJars android.Paths | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 438 | var srcJar android.WritablePath | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 439 |  | 
| Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 440 | var compiledResDirs []android.Paths | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 441 | for _, dir := range resDirs { | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 442 | a.resourceFiles = append(a.resourceFiles, dir.files...) | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 443 | compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths()) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 444 | } | 
| Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 445 |  | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 446 | for i, zip := range resZips { | 
|  | 447 | flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i)) | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 448 | aapt2CompileZip(ctx, flata, zip, "", compileFlags) | 
| Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 449 | compiledResDirs = append(compiledResDirs, android.Paths{flata}) | 
|  | 450 | } | 
|  | 451 |  | 
| Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 452 | var compiledRes, compiledOverlay android.Paths | 
|  | 453 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 454 | // AAPT2 overlays are in lowest to highest priority order, reverse the topological order | 
|  | 455 | // of transitiveStaticLibs. | 
|  | 456 | transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages()) | 
|  | 457 |  | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 458 | if a.isLibrary && a.useResourceProcessorBusyBox(ctx) { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 459 | // When building an android_library with ResourceProcessorBusyBox enabled treat static library dependencies | 
|  | 460 | // as imports.  The resources from dependencies will not be merged into this module's package-res.apk, and | 
|  | 461 | // instead modules depending on this module will reference package-res.apk from all transitive static | 
|  | 462 | // dependencies. | 
| Colin Cross | 1d3f590 | 2024-03-05 11:51:54 -0800 | [diff] [blame] | 463 | for _, sharedDep := range sharedDeps { | 
|  | 464 | if sharedDep.usedResourceProcessor { | 
|  | 465 | transitiveRJars = append(transitiveRJars, sharedDep.rJar) | 
|  | 466 | } | 
|  | 467 | } | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 468 | for _, staticDep := range staticDeps { | 
|  | 469 | linkDeps = append(linkDeps, staticDep.resPackage) | 
|  | 470 | linkFlags = append(linkFlags, "-I "+staticDep.resPackage.String()) | 
|  | 471 | if staticDep.usedResourceProcessor { | 
|  | 472 | transitiveRJars = append(transitiveRJars, staticDep.rJar) | 
|  | 473 | } | 
|  | 474 | } | 
|  | 475 | } else { | 
|  | 476 | // When building an app or building a library without ResourceProcessorBusyBox enabled all static | 
|  | 477 | // dependencies are compiled into this module's package-res.apk as overlays. | 
|  | 478 | compiledOverlay = append(compiledOverlay, transitiveStaticLibs...) | 
|  | 479 | } | 
| Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 480 |  | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 481 | if len(transitiveStaticLibs) > 0 { | 
| Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 482 | // If we are using static android libraries, every source file becomes an overlay. | 
|  | 483 | // This is to emulate old AAPT behavior which simulated library support. | 
|  | 484 | for _, compiledResDir := range compiledResDirs { | 
|  | 485 | compiledOverlay = append(compiledOverlay, compiledResDir...) | 
|  | 486 | } | 
| Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 487 | } else if a.isLibrary { | 
|  | 488 | // Otherwise, for a static library we treat all the resources equally with no overlay. | 
|  | 489 | for _, compiledResDir := range compiledResDirs { | 
|  | 490 | compiledRes = append(compiledRes, compiledResDir...) | 
|  | 491 | } | 
| Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 492 | } else if len(compiledResDirs) > 0 { | 
|  | 493 | // Without static libraries, the first directory is our directory, which can then be | 
|  | 494 | // overlaid by the rest. | 
|  | 495 | compiledRes = append(compiledRes, compiledResDirs[0]...) | 
|  | 496 | for _, compiledResDir := range compiledResDirs[1:] { | 
|  | 497 | compiledOverlay = append(compiledOverlay, compiledResDir...) | 
|  | 498 | } | 
|  | 499 | } | 
|  | 500 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 501 | for _, dir := range overlayDirs { | 
| Inseob Kim | 34dc4cd | 2023-11-07 13:37:14 +0900 | [diff] [blame] | 502 | compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths()...) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 503 | } | 
|  | 504 |  | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 505 | var splitPackages android.WritablePaths | 
|  | 506 | var splits []split | 
|  | 507 |  | 
|  | 508 | for _, s := range a.splitNames { | 
|  | 509 | suffix := strings.Replace(s, ",", "_", -1) | 
|  | 510 | path := android.PathForModuleOut(ctx, "package_"+suffix+".apk") | 
|  | 511 | linkFlags = append(linkFlags, "--split", path.String()+":"+s) | 
|  | 512 | splitPackages = append(splitPackages, path) | 
|  | 513 | splits = append(splits, split{ | 
|  | 514 | name:   s, | 
|  | 515 | suffix: suffix, | 
|  | 516 | path:   path, | 
|  | 517 | }) | 
|  | 518 | } | 
|  | 519 |  | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 520 | if !a.useResourceProcessorBusyBox(ctx) { | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 521 | // the subdir "android" is required to be filtered by package names | 
|  | 522 | srcJar = android.PathForModuleGen(ctx, "android", "R.srcjar") | 
|  | 523 | } | 
|  | 524 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 525 | // No need to specify assets from dependencies to aapt2Link for libraries, all transitive assets will be | 
|  | 526 | // provided to the final app aapt2Link step. | 
|  | 527 | var transitiveAssets android.Paths | 
|  | 528 | if !a.isLibrary { | 
|  | 529 | transitiveAssets = android.ReverseSliceInPlace(staticDeps.assets()) | 
|  | 530 | } | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 531 | aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, | 
| Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 532 | linkFlags, linkDeps, compiledRes, compiledOverlay, transitiveAssets, splitPackages, | 
|  | 533 | opts.aconfigTextFiles) | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 534 | // Extract assets from the resource package output so that they can be used later in aapt2link | 
|  | 535 | // for modules that depend on this one. | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 536 | if android.PrefixInList(linkFlags, "-A ") { | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 537 | assets := android.PathForModuleOut(ctx, "assets.zip") | 
|  | 538 | ctx.Build(pctx, android.BuildParams{ | 
|  | 539 | Rule:        extractAssetsRule, | 
|  | 540 | Input:       packageRes, | 
|  | 541 | Output:      assets, | 
|  | 542 | Description: "extract assets from built resource file", | 
|  | 543 | }) | 
|  | 544 | a.assetPackage = android.OptionalPathForPath(assets) | 
|  | 545 | } | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 546 |  | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 547 | if a.useResourceProcessorBusyBox(ctx) { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 548 | rJar := android.PathForModuleOut(ctx, "busybox/R.jar") | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 549 | resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary, a.aaptProperties.Aaptflags, | 
|  | 550 | opts.forceNonFinalResourceIDs) | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 551 | aapt2ExtractExtraPackages(ctx, extraPackages, rJar) | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 552 | transitiveRJars = append(transitiveRJars, rJar) | 
|  | 553 | a.rJar = rJar | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 554 | } else { | 
|  | 555 | aapt2ExtractExtraPackages(ctx, extraPackages, srcJar) | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 556 | } | 
|  | 557 |  | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 558 | transitiveAaptResourcePackages := staticDeps.resPackages().Strings() | 
|  | 559 | transitiveAaptResourcePackages = slices.DeleteFunc(transitiveAaptResourcePackages, func(p string) bool { | 
|  | 560 | return p == packageRes.String() | 
|  | 561 | }) | 
|  | 562 | transitiveAaptResourcePackagesFile := android.PathForModuleOut(ctx, "transitive-res-packages") | 
|  | 563 | android.WriteFileRule(ctx, transitiveAaptResourcePackagesFile, strings.Join(transitiveAaptResourcePackages, "\n")) | 
|  | 564 |  | 
| Colin Cross | 1d3f590 | 2024-03-05 11:51:54 -0800 | [diff] [blame] | 565 | // Reverse the list of R.jar files so that the current module comes first, and direct dependencies come before | 
|  | 566 | // transitive dependencies. | 
|  | 567 | transitiveRJars = android.ReversePaths(transitiveRJars) | 
|  | 568 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 569 | a.aaptSrcJar = srcJar | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 570 | a.transitiveAaptRJars = transitiveRJars | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 571 | a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 572 | a.exportPackage = packageRes | 
|  | 573 | a.manifestPath = manifestPath | 
|  | 574 | a.proguardOptionsFile = proguardOptionsFile | 
| Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 575 | a.extraAaptPackagesFile = extraPackages | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 576 | a.rTxt = rTxt | 
| Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 577 | a.splits = splits | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 578 | a.resourcesNodesDepSet = android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL). | 
|  | 579 | Direct(&resourcesNode{ | 
|  | 580 | resPackage:          a.exportPackage, | 
|  | 581 | manifest:            a.manifestPath, | 
|  | 582 | additionalManifests: additionalManifests, | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 583 | rTxt:                a.rTxt, | 
|  | 584 | rJar:                a.rJar, | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 585 | assets:              a.assetPackage, | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 586 |  | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 587 | usedResourceProcessor: a.useResourceProcessorBusyBox(ctx), | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 588 | }). | 
|  | 589 | Transitive(staticResourcesNodesDepSet).Build() | 
|  | 590 | a.rroDirsDepSet = android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL). | 
|  | 591 | Direct(rroDirs...). | 
|  | 592 | Transitive(staticRRODirsDepSet).Build() | 
|  | 593 | a.manifestsDepSet = android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL). | 
|  | 594 | Direct(a.manifestPath). | 
|  | 595 | DirectSlice(additionalManifests). | 
|  | 596 | Transitive(staticManifestsDepSet).Build() | 
|  | 597 | } | 
|  | 598 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 599 | var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox", | 
|  | 600 | blueprint.RuleParams{ | 
|  | 601 | Command: "${config.JavaCmd} -cp ${config.ResourceProcessorBusyBox} " + | 
|  | 602 | "com.google.devtools.build.android.ResourceProcessorBusyBox --tool=GENERATE_BINARY_R -- @${out}.args && " + | 
|  | 603 | "if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out}; fi", | 
|  | 604 | CommandDeps:    []string{"${config.ResourceProcessorBusyBox}"}, | 
|  | 605 | Rspfile:        "${out}.args", | 
|  | 606 | RspfileContent: "--primaryRTxt ${rTxt} --primaryManifest ${manifest} --classJarOutput ${out}.tmp ${args}", | 
|  | 607 | Restat:         true, | 
|  | 608 | }, "rTxt", "manifest", "args") | 
|  | 609 |  | 
|  | 610 | // resourceProcessorBusyBoxGenerateBinaryR converts the R.txt file produced by aapt2 into R.class files | 
|  | 611 | // using Bazel's ResourceProcessorBusyBox tool, which is faster than compiling the R.java files and | 
|  | 612 | // supports producing classes for static dependencies that only include resources from that dependency. | 
|  | 613 | func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, manifest android.Path, | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 614 | rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool, aaptFlags []string, | 
|  | 615 | forceNonFinalIds bool) { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 616 |  | 
|  | 617 | var args []string | 
|  | 618 | var deps android.Paths | 
|  | 619 |  | 
|  | 620 | if !isLibrary { | 
|  | 621 | // When compiling an app, pass all R.txt and AndroidManifest.xml from transitive static library dependencies | 
|  | 622 | // to ResourceProcessorBusyBox so that it can regenerate R.class files with the final resource IDs for each | 
|  | 623 | // package. | 
|  | 624 | args, deps = transitiveDeps.resourceProcessorDeps() | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 625 | if forceNonFinalIds { | 
|  | 626 | args = append(args, "--finalFields=false") | 
|  | 627 | } | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 628 | } else { | 
|  | 629 | // When compiling a library don't pass any dependencies as it only needs to generate an R.class file for this | 
|  | 630 | // library.  Pass --finalFields=false so that the R.class file contains non-final fields so they don't get | 
|  | 631 | // inlined into the library before the final IDs are assigned during app compilation. | 
|  | 632 | args = append(args, "--finalFields=false") | 
|  | 633 | } | 
|  | 634 |  | 
| Colin Cross | d3f7d1a | 2024-01-03 19:42:25 -0800 | [diff] [blame] | 635 | for i, arg := range aaptFlags { | 
|  | 636 | const AAPT_CUSTOM_PACKAGE = "--custom-package" | 
|  | 637 | if strings.HasPrefix(arg, AAPT_CUSTOM_PACKAGE) { | 
|  | 638 | pkg := strings.TrimSpace(strings.TrimPrefix(arg, AAPT_CUSTOM_PACKAGE)) | 
|  | 639 | if pkg == "" && i+1 < len(aaptFlags) { | 
|  | 640 | pkg = aaptFlags[i+1] | 
|  | 641 | } | 
|  | 642 | args = append(args, "--packageForR "+pkg) | 
|  | 643 | } | 
|  | 644 | } | 
|  | 645 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 646 | deps = append(deps, rTxt, manifest) | 
|  | 647 |  | 
|  | 648 | ctx.Build(pctx, android.BuildParams{ | 
|  | 649 | Rule:        resourceProcessorBusyBox, | 
|  | 650 | Output:      rJar, | 
|  | 651 | Implicits:   deps, | 
|  | 652 | Description: "ResourceProcessorBusyBox", | 
|  | 653 | Args: map[string]string{ | 
|  | 654 | "rTxt":     rTxt.String(), | 
|  | 655 | "manifest": manifest.String(), | 
|  | 656 | "args":     strings.Join(args, " "), | 
|  | 657 | }, | 
|  | 658 | }) | 
|  | 659 | } | 
|  | 660 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 661 | type resourcesNode struct { | 
|  | 662 | resPackage          android.Path | 
|  | 663 | manifest            android.Path | 
|  | 664 | additionalManifests android.Paths | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 665 | rTxt                android.Path | 
|  | 666 | rJar                android.Path | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 667 | assets              android.OptionalPath | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 668 |  | 
|  | 669 | usedResourceProcessor bool | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 670 | } | 
|  | 671 |  | 
|  | 672 | type transitiveAarDeps []*resourcesNode | 
|  | 673 |  | 
|  | 674 | func (t transitiveAarDeps) resPackages() android.Paths { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 675 | paths := make(android.Paths, 0, len(t)) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 676 | for _, dep := range t { | 
|  | 677 | paths = append(paths, dep.resPackage) | 
|  | 678 | } | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 679 | return paths | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 680 | } | 
|  | 681 |  | 
|  | 682 | func (t transitiveAarDeps) manifests() android.Paths { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 683 | paths := make(android.Paths, 0, len(t)) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 684 | for _, dep := range t { | 
|  | 685 | paths = append(paths, dep.manifest) | 
|  | 686 | paths = append(paths, dep.additionalManifests...) | 
|  | 687 | } | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 688 | return paths | 
|  | 689 | } | 
|  | 690 |  | 
|  | 691 | func (t transitiveAarDeps) resourceProcessorDeps() (args []string, deps android.Paths) { | 
|  | 692 | for _, dep := range t { | 
|  | 693 | args = append(args, "--library="+dep.rTxt.String()+","+dep.manifest.String()) | 
|  | 694 | deps = append(deps, dep.rTxt, dep.manifest) | 
|  | 695 | } | 
|  | 696 | return args, deps | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 697 | } | 
|  | 698 |  | 
|  | 699 | func (t transitiveAarDeps) assets() android.Paths { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 700 | paths := make(android.Paths, 0, len(t)) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 701 | for _, dep := range t { | 
|  | 702 | if dep.assets.Valid() { | 
|  | 703 | paths = append(paths, dep.assets.Path()) | 
|  | 704 | } | 
|  | 705 | } | 
|  | 706 | return paths | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 707 | } | 
|  | 708 |  | 
|  | 709 | // aaptLibs collects libraries from dependencies and sdk_version and converts them into paths | 
| Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 710 | func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, | 
|  | 711 | classLoaderContexts dexpreopt.ClassLoaderContextMap, usesLibrary *usesLibrary) ( | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 712 | staticResourcesNodes, sharedResourcesNodes *android.DepSet[*resourcesNode], staticRRODirs *android.DepSet[rroDir], | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 713 | staticManifests *android.DepSet[android.Path], sharedLibs android.Paths, flags []string) { | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 714 |  | 
| Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 715 | if classLoaderContexts == nil { | 
| Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 716 | // Not all callers need to compute class loader context, those who don't just pass nil. | 
|  | 717 | // Create a temporary class loader context here (it will be computed, but not used). | 
| Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 718 | classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) | 
| Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 719 | } | 
|  | 720 |  | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 721 | sdkDep := decodeSdkDep(ctx, sdkContext) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 722 | if sdkDep.useFiles { | 
| Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 723 | sharedLibs = append(sharedLibs, sdkDep.jars...) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 724 | } | 
|  | 725 |  | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 726 | var staticResourcesNodeDepSets []*android.DepSet[*resourcesNode] | 
|  | 727 | var sharedResourcesNodeDepSets []*android.DepSet[*resourcesNode] | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 728 | rroDirsDepSetBuilder := android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL) | 
|  | 729 | manifestsDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL) | 
|  | 730 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 731 | ctx.VisitDirectDeps(func(module android.Module) { | 
| Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 732 | depTag := ctx.OtherModuleDependencyTag(module) | 
| Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 733 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 734 | var exportPackage android.Path | 
| Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 735 | aarDep, _ := module.(AndroidLibraryDependency) | 
|  | 736 | if aarDep != nil { | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 737 | exportPackage = aarDep.ExportPackage() | 
|  | 738 | } | 
|  | 739 |  | 
| Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 740 | switch depTag { | 
| Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 741 | case instrumentationForTag: | 
|  | 742 | // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2. | 
| Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 743 | case sdkLibTag, libTag: | 
| Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 744 | if exportPackage != nil { | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 745 | sharedResourcesNodeDepSets = append(sharedResourcesNodeDepSets, aarDep.ResourcesNodeDepSet()) | 
| Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 746 | sharedLibs = append(sharedLibs, exportPackage) | 
|  | 747 | } | 
| Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 748 | case frameworkResTag: | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 749 | if exportPackage != nil { | 
|  | 750 | sharedLibs = append(sharedLibs, exportPackage) | 
|  | 751 | } | 
|  | 752 | case staticLibTag: | 
|  | 753 | if exportPackage != nil { | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 754 | staticResourcesNodeDepSets = append(staticResourcesNodeDepSets, aarDep.ResourcesNodeDepSet()) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 755 | rroDirsDepSetBuilder.Transitive(aarDep.RRODirsDepSet()) | 
|  | 756 | manifestsDepSetBuilder.Transitive(aarDep.ManifestsDepSet()) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 757 | } | 
|  | 758 | } | 
| Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 759 |  | 
| Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 760 | addCLCFromDep(ctx, module, classLoaderContexts) | 
| Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 761 | if usesLibrary != nil { | 
|  | 762 | addMissingOptionalUsesLibsFromDep(ctx, module, usesLibrary) | 
|  | 763 | } | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 764 | }) | 
|  | 765 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 766 | // AAPT2 overlays are in lowest to highest priority order, the topological order will be reversed later. | 
|  | 767 | // Reverse the dependency order now going into the depset so that it comes out in order after the second | 
|  | 768 | // reverse later. | 
|  | 769 | // NOTE: this is legacy and probably incorrect behavior, for most other cases (e.g. conflicting classes in | 
|  | 770 | // dependencies) the highest priority dependency is listed first, but for resources the highest priority | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 771 | // dependency has to be listed last.  This is also inconsistent with the way manifests from the same | 
|  | 772 | // transitive dependencies are merged. | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 773 | staticResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil, | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 774 | android.ReverseSliceInPlace(staticResourcesNodeDepSets)) | 
|  | 775 | sharedResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil, | 
|  | 776 | android.ReverseSliceInPlace(sharedResourcesNodeDepSets)) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 777 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 778 | staticRRODirs = rroDirsDepSetBuilder.Build() | 
|  | 779 | staticManifests = manifestsDepSetBuilder.Build() | 
|  | 780 |  | 
|  | 781 | if len(staticResourcesNodes.ToList()) > 0 { | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 782 | flags = append(flags, "--auto-add-overlay") | 
|  | 783 | } | 
|  | 784 |  | 
|  | 785 | for _, sharedLib := range sharedLibs { | 
|  | 786 | flags = append(flags, "-I "+sharedLib.String()) | 
|  | 787 | } | 
|  | 788 |  | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 789 | return staticResourcesNodes, sharedResourcesNodes, staticRRODirs, staticManifests, sharedLibs, flags | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 790 | } | 
|  | 791 |  | 
|  | 792 | type AndroidLibrary struct { | 
|  | 793 | Library | 
|  | 794 | aapt | 
|  | 795 |  | 
|  | 796 | androidLibraryProperties androidLibraryProperties | 
|  | 797 |  | 
|  | 798 | aarFile android.WritablePath | 
| Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 799 | } | 
|  | 800 |  | 
| Saeid Farivar Asanjan | 1fca301 | 2021-09-14 18:40:19 +0000 | [diff] [blame] | 801 | var _ android.OutputFileProducer = (*AndroidLibrary)(nil) | 
|  | 802 |  | 
|  | 803 | // For OutputFileProducer interface | 
|  | 804 | func (a *AndroidLibrary) OutputFiles(tag string) (android.Paths, error) { | 
|  | 805 | switch tag { | 
|  | 806 | case ".aar": | 
|  | 807 | return []android.Path{a.aarFile}, nil | 
|  | 808 | default: | 
|  | 809 | return a.Library.OutputFiles(tag) | 
|  | 810 | } | 
|  | 811 | } | 
|  | 812 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 813 | var _ AndroidLibraryDependency = (*AndroidLibrary)(nil) | 
|  | 814 |  | 
|  | 815 | func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 816 | a.usesLibrary.deps(ctx, false) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 817 | a.Module.deps(ctx) | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 818 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) | 
| Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 819 | if sdkDep.hasFrameworkLibs() { | 
|  | 820 | a.aapt.deps(ctx, sdkDep) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 821 | } | 
| Jihoon Kang | 9049c27 | 2024-03-19 21:57:36 +0000 | [diff] [blame] | 822 |  | 
|  | 823 | for _, aconfig_declaration := range a.aaptProperties.Flags_packages { | 
|  | 824 | ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration) | 
|  | 825 | } | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 826 | } | 
|  | 827 |  | 
|  | 828 | func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 829 | a.aapt.isLibrary = true | 
| Ulya Trafimovich | 42c7f0d | 2021-08-17 16:20:29 +0100 | [diff] [blame] | 830 | a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) | 
| Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 831 | if a.usesLibrary.shouldDisableDexpreopt { | 
|  | 832 | a.dexpreopter.disableDexpreopt() | 
|  | 833 | } | 
| Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 834 | aconfigTextFilePaths := getAconfigFilePaths(ctx) | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 835 | a.aapt.buildActions(ctx, | 
|  | 836 | aaptBuildActionOptions{ | 
|  | 837 | sdkContext:                     android.SdkContext(a), | 
|  | 838 | classLoaderContexts:            a.classLoaderContexts, | 
|  | 839 | enforceDefaultTargetSdkVersion: false, | 
| Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 840 | aconfigTextFiles:               aconfigTextFilePaths, | 
| Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 841 | usesLibrary:                    &a.usesLibrary, | 
| Alix | f7a1027 | 2023-09-27 16:47:56 +0000 | [diff] [blame] | 842 | }, | 
|  | 843 | ) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 844 |  | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 845 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
|  | 846 | a.hideApexVariantFromMake = !apexInfo.IsForPlatform() | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 847 |  | 
| yangbill | 2af0b6e | 2024-03-15 09:29:29 +0000 | [diff] [blame] | 848 | a.stem = proptools.StringDefault(a.overridableProperties.Stem, ctx.ModuleName()) | 
| Jihoon Kang | 1bfb6f2 | 2023-07-01 00:13:47 +0000 | [diff] [blame] | 849 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 850 | ctx.CheckbuildFile(a.aapt.proguardOptionsFile) | 
|  | 851 | ctx.CheckbuildFile(a.aapt.exportPackage) | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 852 | if a.useResourceProcessorBusyBox(ctx) { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 853 | ctx.CheckbuildFile(a.aapt.rJar) | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 854 | } else { | 
|  | 855 | ctx.CheckbuildFile(a.aapt.aaptSrcJar) | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 856 | } | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 857 |  | 
|  | 858 | // apps manifests are handled by aapt, don't let Module see them | 
|  | 859 | a.properties.Manifest = nil | 
|  | 860 |  | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 861 | a.linter.mergedManifest = a.aapt.mergedManifestFile | 
|  | 862 | a.linter.manifest = a.aapt.manifestPath | 
|  | 863 | a.linter.resources = a.aapt.resourceFiles | 
|  | 864 |  | 
| Sam Delmerico | c8e040c | 2023-10-31 17:27:02 +0000 | [diff] [blame] | 865 | proguardSpecInfo := a.collectProguardSpecInfo(ctx) | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 866 | android.SetProvider(ctx, ProguardSpecInfoProvider, proguardSpecInfo) | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 867 | exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList() | 
|  | 868 | a.extraProguardFlagsFiles = append(a.extraProguardFlagsFiles, exportedProguardFlagsFiles...) | 
|  | 869 | a.extraProguardFlagsFiles = append(a.extraProguardFlagsFiles, a.proguardOptionsFile) | 
|  | 870 |  | 
|  | 871 | combinedExportedProguardFlagFile := android.PathForModuleOut(ctx, "export_proguard_flags") | 
|  | 872 | writeCombinedProguardFlagsFile(ctx, combinedExportedProguardFlagFile, exportedProguardFlagsFiles) | 
|  | 873 | a.combinedExportedProguardFlagsFile = combinedExportedProguardFlagFile | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 874 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 875 | var extraSrcJars android.Paths | 
|  | 876 | var extraCombinedJars android.Paths | 
|  | 877 | var extraClasspathJars android.Paths | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 878 | if a.useResourceProcessorBusyBox(ctx) { | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 879 | // When building a library with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox for this | 
|  | 880 | // library and each of the transitive static android_library dependencies has already created an | 
|  | 881 | // R.class file for the appropriate package.  Add all of those R.class files to the classpath. | 
|  | 882 | extraClasspathJars = a.transitiveAaptRJars | 
|  | 883 | } else { | 
|  | 884 | // When building a library without ResourceProcessorBusyBox the aapt2 rule creates R.srcjar containing | 
|  | 885 | // R.java files for the library's package and the packages from all transitive static android_library | 
|  | 886 | // dependencies.  Compile the srcjar alongside the rest of the sources. | 
|  | 887 | extraSrcJars = android.Paths{a.aapt.aaptSrcJar} | 
|  | 888 | } | 
|  | 889 |  | 
|  | 890 | a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 891 |  | 
| Colin Cross | f57c578 | 2019-01-25 13:20:38 -0800 | [diff] [blame] | 892 | a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar") | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 893 | var res android.Paths | 
|  | 894 | if a.androidLibraryProperties.BuildAAR { | 
|  | 895 | BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res) | 
|  | 896 | ctx.CheckbuildFile(a.aarFile) | 
|  | 897 | } | 
| Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 898 |  | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 899 | prebuiltJniPackages := android.Paths{} | 
|  | 900 | ctx.VisitDirectDeps(func(module android.Module) { | 
| Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 901 | if info, ok := android.OtherModuleProvider(ctx, module, JniPackageProvider); ok { | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 902 | prebuiltJniPackages = append(prebuiltJniPackages, info.JniPackages...) | 
|  | 903 | } | 
|  | 904 | }) | 
|  | 905 | if len(prebuiltJniPackages) > 0 { | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 906 | android.SetProvider(ctx, JniPackageProvider, JniPackageInfo{ | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 907 | JniPackages: prebuiltJniPackages, | 
|  | 908 | }) | 
|  | 909 | } | 
| Jihoon Kang | 9aef777 | 2024-06-14 23:45:06 +0000 | [diff] [blame] | 910 |  | 
|  | 911 | android.SetProvider(ctx, FlagsPackagesProvider, FlagsPackages{ | 
|  | 912 | AconfigTextFiles: aconfigTextFilePaths, | 
|  | 913 | }) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 914 | } | 
|  | 915 |  | 
| Colin Cross | 95b53b8 | 2023-10-17 13:21:02 -0700 | [diff] [blame] | 916 | func (a *AndroidLibrary) IDEInfo(dpInfo *android.IdeInfo) { | 
|  | 917 | a.Library.IDEInfo(dpInfo) | 
|  | 918 | a.aapt.IDEInfo(dpInfo) | 
|  | 919 | } | 
|  | 920 |  | 
|  | 921 | func (a *aapt) IDEInfo(dpInfo *android.IdeInfo) { | 
| Colin Cross | 8f1b033 | 2024-01-25 13:39:06 -0800 | [diff] [blame] | 922 | if a.rJar != nil { | 
| Colin Cross | 95b53b8 | 2023-10-17 13:21:02 -0700 | [diff] [blame] | 923 | dpInfo.Jars = append(dpInfo.Jars, a.rJar.String()) | 
|  | 924 | } | 
|  | 925 | } | 
|  | 926 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 927 | // android_library builds and links sources into a `.jar` file for the device along with Android resources. | 
|  | 928 | // | 
|  | 929 | // An android_library has a single variant that produces a `.jar` file containing `.class` files that were | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 930 | // compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 931 | // with aapt2.  This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of | 
|  | 932 | // an android_app module. | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 933 | func AndroidLibraryFactory() android.Module { | 
|  | 934 | module := &AndroidLibrary{} | 
|  | 935 |  | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 936 | module.Module.addHostAndDeviceProperties() | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 937 | module.AddProperties( | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 938 | &module.aaptProperties, | 
| Ronald Braunstein | cdc66f4 | 2024-04-12 11:23:19 -0700 | [diff] [blame] | 939 | &module.androidLibraryProperties, | 
|  | 940 | &module.sourceProperties) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 941 |  | 
|  | 942 | module.androidLibraryProperties.BuildAAR = true | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 943 | module.Module.linter.library = true | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 944 |  | 
| Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 945 | android.InitApexModule(module) | 
| Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 946 | InitJavaModule(module, android.DeviceSupported) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 947 | return module | 
|  | 948 | } | 
|  | 949 |  | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 950 | // | 
|  | 951 | // AAR (android library) prebuilts | 
|  | 952 | // | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 953 |  | 
| Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 954 | // Properties for android_library_import | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 955 | type AARImportProperties struct { | 
| Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 956 | // ARR (android library prebuilt) filepath. Exactly one ARR is required. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 957 | Aars []string `android:"path"` | 
| Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 958 | // If not blank, set to the version of the sdk to compile against. | 
|  | 959 | // Defaults to private. | 
|  | 960 | // Values are of one of the following forms: | 
|  | 961 | // 1) numerical API level, "current", "none", or "core_platform" | 
|  | 962 | // 2) An SDK kind with an API level: "<sdk kind>_<API level>" | 
|  | 963 | // See build/soong/android/sdk_version.go for the complete and up to date list of SDK kinds. | 
|  | 964 | // If the SDK kind is empty, it will be set to public | 
|  | 965 | Sdk_version *string | 
|  | 966 | // If not blank, set the minimum version of the sdk that the compiled artifacts will run against. | 
|  | 967 | // Defaults to sdk_version if not set. See sdk_version for possible values. | 
| Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 968 | Min_sdk_version *string | 
| Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 969 | // List of java static libraries that the included ARR (android library prebuilts) has dependencies to. | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 970 | Static_libs []string | 
| Vinh Tran | ce0781f | 2022-04-13 01:30:44 +0000 | [diff] [blame] | 971 | // List of java libraries that the included ARR (android library prebuilts) has dependencies to. | 
|  | 972 | Libs []string | 
|  | 973 | // If set to true, run Jetifier against .aar file. Defaults to false. | 
| Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 974 | Jetifier *bool | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 975 | // If true, extract JNI libs from AAR archive. These libs will be accessible to android_app modules and | 
|  | 976 | // will be passed transitively through android_libraries to an android_app. | 
|  | 977 | //TODO(b/241138093) evaluate whether we can have this flag default to true for Bazel conversion | 
|  | 978 | Extract_jni *bool | 
| Colin Cross | 21ed469 | 2024-04-24 20:23:38 +0000 | [diff] [blame] | 979 |  | 
|  | 980 | // If set, overrides the manifest extracted from the AAR with the provided path. | 
|  | 981 | Manifest *string `android:"path"` | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 982 | } | 
|  | 983 |  | 
|  | 984 | type AARImport struct { | 
|  | 985 | android.ModuleBase | 
| Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 986 | android.DefaultableModuleBase | 
| Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 987 | android.ApexModuleBase | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 988 | prebuilt android.Prebuilt | 
|  | 989 |  | 
| Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 990 | // Functionality common to Module and Import. | 
|  | 991 | embeddableInModuleAndImport | 
|  | 992 |  | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 993 | providesTransitiveHeaderJars | 
|  | 994 |  | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 995 | properties AARImportProperties | 
|  | 996 |  | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 997 | headerJarFile                      android.WritablePath | 
|  | 998 | implementationJarFile              android.WritablePath | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 999 | implementationAndResourcesJarFile  android.WritablePath | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 1000 | proguardFlags                      android.WritablePath | 
|  | 1001 | exportPackage                      android.WritablePath | 
|  | 1002 | transitiveAaptResourcePackagesFile android.Path | 
|  | 1003 | extraAaptPackagesFile              android.WritablePath | 
| Colin Cross | 21ed469 | 2024-04-24 20:23:38 +0000 | [diff] [blame] | 1004 | manifest                           android.Path | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 1005 | assetsPackage                      android.WritablePath | 
|  | 1006 | rTxt                               android.WritablePath | 
|  | 1007 | rJar                               android.WritablePath | 
| Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 1008 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1009 | resourcesNodesDepSet *android.DepSet[*resourcesNode] | 
|  | 1010 | manifestsDepSet      *android.DepSet[android.Path] | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1011 |  | 
|  | 1012 | hideApexVariantFromMake bool | 
| Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1013 |  | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1014 | aarPath     android.Path | 
|  | 1015 | jniPackages android.Paths | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1016 |  | 
|  | 1017 | sdkVersion    android.SdkSpec | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1018 | minSdkVersion android.ApiLevel | 
| LaMont Jones | afe7baf | 2024-01-09 22:47:39 +0000 | [diff] [blame] | 1019 |  | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1020 | usesLibrary | 
|  | 1021 | classLoaderContexts dexpreopt.ClassLoaderContextMap | 
| Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1022 | } | 
|  | 1023 |  | 
|  | 1024 | var _ android.OutputFileProducer = (*AARImport)(nil) | 
|  | 1025 |  | 
|  | 1026 | // For OutputFileProducer interface | 
|  | 1027 | func (a *AARImport) OutputFiles(tag string) (android.Paths, error) { | 
|  | 1028 | switch tag { | 
|  | 1029 | case ".aar": | 
|  | 1030 | return []android.Path{a.aarPath}, nil | 
|  | 1031 | case "": | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1032 | return []android.Path{a.implementationAndResourcesJarFile}, nil | 
| Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1033 | default: | 
|  | 1034 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
|  | 1035 | } | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1036 | } | 
|  | 1037 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1038 | func (a *AARImport) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { | 
|  | 1039 | return android.SdkSpecFrom(ctx, String(a.properties.Sdk_version)) | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 1040 | } | 
|  | 1041 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1042 | func (a *AARImport) SystemModules() string { | 
| Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 1043 | return "" | 
|  | 1044 | } | 
|  | 1045 |  | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1046 | func (a *AARImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { | 
| Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 1047 | if a.properties.Min_sdk_version != nil { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1048 | return android.ApiLevelFrom(ctx, *a.properties.Min_sdk_version) | 
| Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 1049 | } | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1050 | return a.SdkVersion(ctx).ApiLevel | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 1051 | } | 
|  | 1052 |  | 
| Spandan Das | a26eda7 | 2023-03-02 00:56:06 +0000 | [diff] [blame] | 1053 | func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.ApiLevel { | 
|  | 1054 | return android.SdkSpecFrom(ctx, "").ApiLevel | 
| William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 1055 | } | 
|  | 1056 |  | 
| Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 1057 | func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { | 
|  | 1058 | return a.SdkVersion(ctx).ApiLevel | 
| Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 1059 | } | 
|  | 1060 |  | 
| Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1061 | func (a *AARImport) javaVersion() string { | 
|  | 1062 | return "" | 
|  | 1063 | } | 
|  | 1064 |  | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 1065 | var _ AndroidLibraryDependency = (*AARImport)(nil) | 
|  | 1066 |  | 
|  | 1067 | func (a *AARImport) ExportPackage() android.Path { | 
|  | 1068 | return a.exportPackage | 
|  | 1069 | } | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1070 | func (a *AARImport) ResourcesNodeDepSet() *android.DepSet[*resourcesNode] { | 
|  | 1071 | return a.resourcesNodesDepSet | 
| Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 1072 | } | 
|  | 1073 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1074 | func (a *AARImport) RRODirsDepSet() *android.DepSet[rroDir] { | 
|  | 1075 | return android.NewDepSet[rroDir](android.TOPOLOGICAL, nil, nil) | 
| Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 1076 | } | 
|  | 1077 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1078 | func (a *AARImport) ManifestsDepSet() *android.DepSet[android.Path] { | 
|  | 1079 | return a.manifestsDepSet | 
| Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 1080 | } | 
|  | 1081 |  | 
| Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 1082 | // RRO enforcement is not available on aar_import since its RRO dirs are not | 
|  | 1083 | // exported. | 
|  | 1084 | func (a *AARImport) SetRROEnforcedForDependent(enforce bool) { | 
|  | 1085 | } | 
|  | 1086 |  | 
|  | 1087 | // RRO enforcement is not available on aar_import since its RRO dirs are not | 
|  | 1088 | // exported. | 
|  | 1089 | func (a *AARImport) IsRROEnforced(ctx android.BaseModuleContext) bool { | 
|  | 1090 | return false | 
|  | 1091 | } | 
|  | 1092 |  | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1093 | func (a *AARImport) Prebuilt() *android.Prebuilt { | 
|  | 1094 | return &a.prebuilt | 
|  | 1095 | } | 
|  | 1096 |  | 
|  | 1097 | func (a *AARImport) Name() string { | 
|  | 1098 | return a.prebuilt.Name(a.ModuleBase.Name()) | 
|  | 1099 | } | 
|  | 1100 |  | 
| Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 1101 | func (a *AARImport) JacocoReportClassesFile() android.Path { | 
|  | 1102 | return nil | 
|  | 1103 | } | 
|  | 1104 |  | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1105 | func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 1106 | if !ctx.Config().AlwaysUsePrebuiltSdks() { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1107 | sdkDep := decodeSdkDep(ctx, android.SdkContext(a)) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 1108 | if sdkDep.useModule && sdkDep.frameworkResModule != "" { | 
| Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1109 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1110 | } | 
|  | 1111 | } | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 1112 |  | 
| Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1113 | ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...) | 
|  | 1114 | ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1115 |  | 
|  | 1116 | a.usesLibrary.deps(ctx, false) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1117 | } | 
|  | 1118 |  | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1119 | type JniPackageInfo struct { | 
|  | 1120 | // List of zip files containing JNI libraries | 
|  | 1121 | // Zip files should have directory structure jni/<arch>/*.so | 
|  | 1122 | JniPackages android.Paths | 
|  | 1123 | } | 
|  | 1124 |  | 
| Colin Cross | bc7d76c | 2023-12-12 16:39:03 -0800 | [diff] [blame] | 1125 | var JniPackageProvider = blueprint.NewProvider[JniPackageInfo]() | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1126 |  | 
|  | 1127 | // Unzip an AAR and extract the JNI libs for $archString. | 
|  | 1128 | var extractJNI = pctx.AndroidStaticRule("extractJNI", | 
|  | 1129 | blueprint.RuleParams{ | 
|  | 1130 | Command: `rm -rf $out $outDir && touch $out && ` + | 
|  | 1131 | `unzip -qoDD -d $outDir $in "jni/${archString}/*" && ` + | 
|  | 1132 | `jni_files=$$(find $outDir/jni -type f) && ` + | 
|  | 1133 | // print error message if there are no JNI libs for this arch | 
|  | 1134 | `[ -n "$$jni_files" ] || (echo "ERROR: no JNI libs found for arch ${archString}" && exit 1) && ` + | 
| Sam Delmerico | 80ee45c | 2023-06-22 15:36:02 -0400 | [diff] [blame] | 1135 | `${config.SoongZipCmd} -o $out -L 0 -P 'lib/${archString}' ` + | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1136 | `-C $outDir/jni/${archString} $$(echo $$jni_files | xargs -n1 printf " -f %s")`, | 
|  | 1137 | CommandDeps: []string{"${config.SoongZipCmd}"}, | 
|  | 1138 | }, | 
|  | 1139 | "outDir", "archString") | 
|  | 1140 |  | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1141 | // Unzip an AAR into its constituent files and directories.  Any files in Outputs that don't exist in the AAR will be | 
| Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 1142 | // touched to create an empty file. The res directory is not extracted, as it will be extracted in its own rule. | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1143 | var unzipAAR = pctx.AndroidStaticRule("unzipAAR", | 
|  | 1144 | blueprint.RuleParams{ | 
| Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 1145 | Command: `rm -rf $outDir && mkdir -p $outDir && ` + | 
| Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 1146 | `unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` + | 
| Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1147 | `${config.Zip2ZipCmd} -i $in -o $assetsPackage 'assets/**/*' && ` + | 
| Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 1148 | `${config.MergeZipsCmd} $combinedClassesJar $$(ls $outDir/classes.jar 2> /dev/null) $$(ls $outDir/libs/*.jar 2> /dev/null)`, | 
| Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1149 | CommandDeps: []string{"${config.MergeZipsCmd}", "${config.Zip2ZipCmd}"}, | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1150 | }, | 
| Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1151 | "outDir", "combinedClassesJar", "assetsPackage") | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1152 |  | 
|  | 1153 | func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 1154 | if len(a.properties.Aars) != 1 { | 
|  | 1155 | ctx.PropertyErrorf("aars", "exactly one aar is required") | 
|  | 1156 | return | 
|  | 1157 | } | 
|  | 1158 |  | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 1159 | a.sdkVersion = a.SdkVersion(ctx) | 
|  | 1160 | a.minSdkVersion = a.MinSdkVersion(ctx) | 
|  | 1161 |  | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 1162 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
|  | 1163 | a.hideApexVariantFromMake = !apexInfo.IsForPlatform() | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1164 |  | 
| Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1165 | aarName := ctx.ModuleName() + ".aar" | 
| Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1166 | a.aarPath = android.PathForModuleSrc(ctx, a.properties.Aars[0]) | 
|  | 1167 |  | 
| Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 1168 | if Bool(a.properties.Jetifier) { | 
| Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1169 | inputFile := a.aarPath | 
|  | 1170 | a.aarPath = android.PathForModuleOut(ctx, "jetifier", aarName) | 
|  | 1171 | TransformJetifier(ctx, a.aarPath.(android.WritablePath), inputFile) | 
| Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 1172 | } | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1173 |  | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1174 | jarName := ctx.ModuleName() + ".jar" | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1175 | extractedAARDir := android.PathForModuleOut(ctx, "aar") | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1176 | classpathFile := extractedAARDir.Join(ctx, jarName) | 
| Colin Cross | 21ed469 | 2024-04-24 20:23:38 +0000 | [diff] [blame] | 1177 |  | 
|  | 1178 | extractedManifest := extractedAARDir.Join(ctx, "AndroidManifest.xml") | 
|  | 1179 | providedManifest := android.OptionalPathForModuleSrc(ctx, a.properties.Manifest) | 
|  | 1180 | if providedManifest.Valid() { | 
|  | 1181 | a.manifest = providedManifest.Path() | 
|  | 1182 | } else { | 
|  | 1183 | a.manifest = extractedManifest | 
|  | 1184 | } | 
|  | 1185 |  | 
| Colin Cross | bb77d8e | 2024-02-15 14:43:47 -0800 | [diff] [blame] | 1186 | a.rTxt = extractedAARDir.Join(ctx, "R.txt") | 
| Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1187 | a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip") | 
| Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 1188 | a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") | 
| Colin Cross | cde5534 | 2024-03-27 14:11:51 -0700 | [diff] [blame] | 1189 | transitiveProguardFlags, transitiveUnconditionalExportedFlags := collectDepProguardSpecInfo(ctx) | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1190 | android.SetProvider(ctx, ProguardSpecInfoProvider, ProguardSpecInfo{ | 
| Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 1191 | ProguardFlagsFiles: android.NewDepSet[android.Path]( | 
|  | 1192 | android.POSTORDER, | 
|  | 1193 | android.Paths{a.proguardFlags}, | 
| Colin Cross | cde5534 | 2024-03-27 14:11:51 -0700 | [diff] [blame] | 1194 | transitiveProguardFlags, | 
|  | 1195 | ), | 
|  | 1196 | UnconditionallyExportedProguardFlags: android.NewDepSet[android.Path]( | 
|  | 1197 | android.POSTORDER, | 
| Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 1198 | nil, | 
| Colin Cross | cde5534 | 2024-03-27 14:11:51 -0700 | [diff] [blame] | 1199 | transitiveUnconditionalExportedFlags, | 
| Sam Delmerico | 95d7094 | 2023-08-02 18:00:35 -0400 | [diff] [blame] | 1200 | ), | 
|  | 1201 | }) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1202 |  | 
|  | 1203 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1204 | Rule:        unzipAAR, | 
| Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1205 | Input:       a.aarPath, | 
| Colin Cross | 21ed469 | 2024-04-24 20:23:38 +0000 | [diff] [blame] | 1206 | Outputs:     android.WritablePaths{classpathFile, a.proguardFlags, extractedManifest, a.assetsPackage, a.rTxt}, | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1207 | Description: "unzip AAR", | 
|  | 1208 | Args: map[string]string{ | 
| Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 1209 | "outDir":             extractedAARDir.String(), | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1210 | "combinedClassesJar": classpathFile.String(), | 
| Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1211 | "assetsPackage":      a.assetsPackage.String(), | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1212 | }, | 
|  | 1213 | }) | 
|  | 1214 |  | 
| Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 1215 | // Always set --pseudo-localize, it will be stripped out later for release | 
|  | 1216 | // builds that don't want it. | 
|  | 1217 | compileFlags := []string{"--pseudo-localize"} | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1218 | compiledResDir := android.PathForModuleOut(ctx, "flat-res") | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1219 | flata := compiledResDir.Join(ctx, "gen_res.flata") | 
| Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 1220 | aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1221 |  | 
|  | 1222 | a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk") | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1223 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") | 
| Colin Cross | bb77d8e | 2024-02-15 14:43:47 -0800 | [diff] [blame] | 1224 | aaptRTxt := android.PathForModuleOut(ctx, "R.txt") | 
| Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 1225 | a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1226 |  | 
|  | 1227 | var linkDeps android.Paths | 
|  | 1228 |  | 
|  | 1229 | linkFlags := []string{ | 
|  | 1230 | "--static-lib", | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1231 | "--merge-only", | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1232 | "--auto-add-overlay", | 
| Colin Cross | 7c4dc5d | 2024-02-13 14:29:45 -0800 | [diff] [blame] | 1233 | "--no-static-lib-packages", | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1234 | } | 
|  | 1235 |  | 
| Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 1236 | linkFlags = append(linkFlags, "--manifest "+a.manifest.String()) | 
|  | 1237 | linkDeps = append(linkDeps, a.manifest) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1238 |  | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1239 | staticResourcesNodesDepSet, sharedResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedLibs, libFlags := | 
| Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 1240 | aaptLibs(ctx, android.SdkContext(a), nil, nil) | 
| Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 1241 |  | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1242 | _ = sharedResourcesNodesDepSet | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1243 | _ = staticRRODirsDepSet | 
| Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1244 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1245 | staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList()) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1246 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1247 | linkDeps = append(linkDeps, sharedLibs...) | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1248 | linkDeps = append(linkDeps, staticDeps.resPackages()...) | 
| Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 1249 | linkFlags = append(linkFlags, libFlags...) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1250 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1251 | overlayRes := android.Paths{flata} | 
|  | 1252 |  | 
|  | 1253 | // Treat static library dependencies of static libraries as imports. | 
|  | 1254 | transitiveStaticLibs := staticDeps.resPackages() | 
|  | 1255 | linkDeps = append(linkDeps, transitiveStaticLibs...) | 
|  | 1256 | for _, staticLib := range transitiveStaticLibs { | 
|  | 1257 | linkFlags = append(linkFlags, "-I "+staticLib.String()) | 
|  | 1258 | } | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1259 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1260 | transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets()) | 
| Colin Cross | bb77d8e | 2024-02-15 14:43:47 -0800 | [diff] [blame] | 1261 | aapt2Link(ctx, a.exportPackage, nil, proguardOptionsFile, aaptRTxt, | 
| Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 1262 | linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil, nil) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1263 |  | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1264 | a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar") | 
| Rico Wind | a2fa263 | 2024-03-13 13:09:17 +0100 | [diff] [blame] | 1265 | resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true, nil, false) | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1266 |  | 
| Colin Cross | f3b7bad | 2023-08-02 15:49:00 -0700 | [diff] [blame] | 1267 | aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar) | 
|  | 1268 |  | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1269 | resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL) | 
|  | 1270 | resourcesNodesDepSetBuilder.Direct(&resourcesNode{ | 
|  | 1271 | resPackage: a.exportPackage, | 
|  | 1272 | manifest:   a.manifest, | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1273 | rTxt:       a.rTxt, | 
|  | 1274 | rJar:       a.rJar, | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1275 | assets:     android.OptionalPathForPath(a.assetsPackage), | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1276 |  | 
|  | 1277 | usedResourceProcessor: true, | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1278 | }) | 
|  | 1279 | resourcesNodesDepSetBuilder.Transitive(staticResourcesNodesDepSet) | 
|  | 1280 | a.resourcesNodesDepSet = resourcesNodesDepSetBuilder.Build() | 
|  | 1281 |  | 
|  | 1282 | manifestDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(a.manifest) | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1283 | manifestDepSetBuilder.Transitive(staticManifestsDepSet) | 
| Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1284 | a.manifestsDepSet = manifestDepSetBuilder.Build() | 
| Michael Rosenfeld | 5ad1557 | 2021-12-03 13:25:10 -0800 | [diff] [blame] | 1285 |  | 
| Colin Cross | 312634e | 2023-11-21 15:13:56 -0800 | [diff] [blame] | 1286 | transitiveAaptResourcePackages := staticDeps.resPackages().Strings() | 
|  | 1287 | transitiveAaptResourcePackages = slices.DeleteFunc(transitiveAaptResourcePackages, func(p string) bool { | 
|  | 1288 | return p == a.exportPackage.String() | 
|  | 1289 | }) | 
|  | 1290 | transitiveAaptResourcePackagesFile := android.PathForModuleOut(ctx, "transitive-res-packages") | 
|  | 1291 | android.WriteFileRule(ctx, transitiveAaptResourcePackagesFile, strings.Join(transitiveAaptResourcePackages, "\n")) | 
|  | 1292 | a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile | 
| Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1293 |  | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1294 | a.collectTransitiveHeaderJars(ctx) | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1295 |  | 
|  | 1296 | a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) | 
|  | 1297 |  | 
|  | 1298 | var staticJars android.Paths | 
|  | 1299 | var staticHeaderJars android.Paths | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1300 | var staticResourceJars android.Paths | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1301 | ctx.VisitDirectDeps(func(module android.Module) { | 
|  | 1302 | if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { | 
|  | 1303 | tag := ctx.OtherModuleDependencyTag(module) | 
|  | 1304 | switch tag { | 
|  | 1305 | case staticLibTag: | 
|  | 1306 | staticJars = append(staticJars, dep.ImplementationJars...) | 
|  | 1307 | staticHeaderJars = append(staticHeaderJars, dep.HeaderJars...) | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1308 | staticResourceJars = append(staticResourceJars, dep.ResourceJars...) | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1309 | } | 
|  | 1310 | } | 
|  | 1311 | addCLCFromDep(ctx, module, a.classLoaderContexts) | 
| Jiakai Zhang | 3693708 | 2024-04-15 11:15:50 +0000 | [diff] [blame] | 1312 | addMissingOptionalUsesLibsFromDep(ctx, module, &a.usesLibrary) | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1313 | }) | 
|  | 1314 |  | 
| Colin Cross | 28ac2ff | 2024-04-02 12:21:34 -0700 | [diff] [blame] | 1315 | var implementationJarFile android.OutputPath | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1316 | if len(staticJars) > 0 { | 
|  | 1317 | combineJars := append(android.Paths{classpathFile}, staticJars...) | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1318 | implementationJarFile = android.PathForModuleOut(ctx, "combined", jarName).OutputPath | 
| Colin Cross | 28ac2ff | 2024-04-02 12:21:34 -0700 | [diff] [blame] | 1319 | TransformJarsToJar(ctx, implementationJarFile, "combine", combineJars, android.OptionalPath{}, false, nil, nil) | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1320 | } else { | 
| Colin Cross | 28ac2ff | 2024-04-02 12:21:34 -0700 | [diff] [blame] | 1321 | implementationJarFile = classpathFile | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1322 | } | 
|  | 1323 |  | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1324 | var resourceJarFile android.Path | 
|  | 1325 | if len(staticResourceJars) > 1 { | 
|  | 1326 | combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) | 
|  | 1327 | TransformJarsToJar(ctx, combinedJar, "for resources", staticResourceJars, android.OptionalPath{}, | 
|  | 1328 | false, nil, nil) | 
|  | 1329 | resourceJarFile = combinedJar | 
|  | 1330 | } else if len(staticResourceJars) == 1 { | 
|  | 1331 | resourceJarFile = staticResourceJars[0] | 
|  | 1332 | } | 
|  | 1333 |  | 
|  | 1334 | // merge implementation jar with resources if necessary | 
|  | 1335 | implementationAndResourcesJar := implementationJarFile | 
|  | 1336 | if resourceJarFile != nil { | 
|  | 1337 | jars := android.Paths{resourceJarFile, implementationAndResourcesJar} | 
|  | 1338 | combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath | 
|  | 1339 | TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{}, | 
|  | 1340 | false, nil, nil) | 
|  | 1341 | implementationAndResourcesJar = combinedJar | 
|  | 1342 | } | 
|  | 1343 |  | 
|  | 1344 | a.implementationJarFile = implementationJarFile | 
| Colin Cross | 28ac2ff | 2024-04-02 12:21:34 -0700 | [diff] [blame] | 1345 | // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1346 | a.implementationAndResourcesJarFile = implementationAndResourcesJar.WithoutRel() | 
| Colin Cross | 28ac2ff | 2024-04-02 12:21:34 -0700 | [diff] [blame] | 1347 |  | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1348 | if len(staticHeaderJars) > 0 { | 
|  | 1349 | combineJars := append(android.Paths{classpathFile}, staticHeaderJars...) | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1350 | a.headerJarFile = android.PathForModuleOut(ctx, "turbine-combined", jarName) | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1351 | TransformJarsToJar(ctx, a.headerJarFile, "combine header jars", combineJars, android.OptionalPath{}, false, nil, nil) | 
|  | 1352 | } else { | 
|  | 1353 | a.headerJarFile = classpathFile | 
|  | 1354 | } | 
|  | 1355 |  | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1356 | android.SetProvider(ctx, JavaInfoProvider, JavaInfo{ | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1357 | HeaderJars:                     android.PathsIfNonNil(a.headerJarFile), | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1358 | ResourceJars:                   android.PathsIfNonNil(resourceJarFile), | 
| Sam Delmerico | 9f9c0a2 | 2022-11-29 11:19:37 -0500 | [diff] [blame] | 1359 | TransitiveLibsHeaderJars:       a.transitiveLibsHeaderJars, | 
|  | 1360 | TransitiveStaticLibsHeaderJars: a.transitiveStaticLibsHeaderJars, | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1361 | ImplementationAndResourcesJars: android.PathsIfNonNil(a.implementationAndResourcesJarFile), | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1362 | ImplementationJars:             android.PathsIfNonNil(a.implementationJarFile), | 
| Jihoon Kang | fe914ed | 2024-02-12 22:49:21 +0000 | [diff] [blame] | 1363 | StubsLinkType:                  Implementation, | 
| Joe Onorato | 6fe59eb | 2023-07-16 13:20:33 -0700 | [diff] [blame] | 1364 | // TransitiveAconfigFiles: // TODO(b/289117800): LOCAL_ACONFIG_FILES for prebuilts | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1365 | }) | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1366 |  | 
|  | 1367 | if proptools.Bool(a.properties.Extract_jni) { | 
|  | 1368 | for _, t := range ctx.MultiTargets() { | 
|  | 1369 | arch := t.Arch.Abi[0] | 
|  | 1370 | path := android.PathForModuleOut(ctx, arch+"_jni.zip") | 
|  | 1371 | a.jniPackages = append(a.jniPackages, path) | 
|  | 1372 |  | 
|  | 1373 | outDir := android.PathForModuleOut(ctx, "aarForJni") | 
|  | 1374 | aarPath := android.PathForModuleSrc(ctx, a.properties.Aars[0]) | 
|  | 1375 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1376 | Rule:        extractJNI, | 
|  | 1377 | Input:       aarPath, | 
|  | 1378 | Outputs:     android.WritablePaths{path}, | 
|  | 1379 | Description: "extract JNI from AAR", | 
|  | 1380 | Args: map[string]string{ | 
|  | 1381 | "outDir":     outDir.String(), | 
|  | 1382 | "archString": arch, | 
|  | 1383 | }, | 
|  | 1384 | }) | 
|  | 1385 | } | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1386 | } | 
| Colin Cross | e8eeec9 | 2023-12-14 14:50:05 -0800 | [diff] [blame] | 1387 |  | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1388 | android.SetProvider(ctx, JniPackageProvider, JniPackageInfo{ | 
| Colin Cross | e8eeec9 | 2023-12-14 14:50:05 -0800 | [diff] [blame] | 1389 | JniPackages: a.jniPackages, | 
|  | 1390 | }) | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 1391 | } | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1392 |  | 
|  | 1393 | func (a *AARImport) HeaderJars() android.Paths { | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1394 | return android.Paths{a.headerJarFile} | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1395 | } | 
|  | 1396 |  | 
| Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1397 | func (a *AARImport) ImplementationAndResourcesJars() android.Paths { | 
| Colin Cross | 607bbd6 | 2024-04-12 13:44:45 -0700 | [diff] [blame] | 1398 | return android.Paths{a.implementationAndResourcesJarFile} | 
| Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1399 | } | 
|  | 1400 |  | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1401 | func (a *AARImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { | 
|  | 1402 | return OptionalDexJarPath{} | 
| Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1403 | } | 
|  | 1404 |  | 
| Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 1405 | func (a *AARImport) DexJarInstallPath() android.Path { | 
|  | 1406 | return nil | 
|  | 1407 | } | 
|  | 1408 |  | 
| Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1409 | func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1410 | return a.classLoaderContexts | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1411 | } | 
|  | 1412 |  | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1413 | var _ UsesLibraryDependency = (*AARImport)(nil) | 
|  | 1414 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1415 | var _ android.ApexModule = (*AARImport)(nil) | 
|  | 1416 |  | 
|  | 1417 | // Implements android.ApexModule | 
| Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 1418 | func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { | 
|  | 1419 | return a.depIsInSameApex(ctx, dep) | 
|  | 1420 | } | 
|  | 1421 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1422 | // Implements android.ApexModule | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1423 | func (a *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1424 | sdkVersion android.ApiLevel) error { | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1425 | return nil | 
|  | 1426 | } | 
|  | 1427 |  | 
| Sam Delmerico | af8bb70 | 2022-07-25 15:39:32 -0400 | [diff] [blame] | 1428 | var _ android.PrebuiltInterface = (*AARImport)(nil) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1429 |  | 
| Jiakai Zhang | f98da19 | 2024-04-15 11:15:41 +0000 | [diff] [blame] | 1430 | func (a *AARImport) UsesLibrary() *usesLibrary { | 
|  | 1431 | return &a.usesLibrary | 
|  | 1432 | } | 
|  | 1433 |  | 
|  | 1434 | var _ ModuleWithUsesLibrary = (*AARImport)(nil) | 
|  | 1435 |  | 
| Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 1436 | // android_library_import imports an `.aar` file into the build graph as if it was built with android_library. | 
|  | 1437 | // | 
|  | 1438 | // This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of | 
|  | 1439 | // an android_app module. | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1440 | func AARImportFactory() android.Module { | 
|  | 1441 | module := &AARImport{} | 
|  | 1442 |  | 
| Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame] | 1443 | module.AddProperties( | 
|  | 1444 | &module.properties, | 
|  | 1445 | &module.usesLibrary.usesLibraryProperties, | 
|  | 1446 | ) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1447 |  | 
|  | 1448 | android.InitPrebuiltModule(module, &module.properties.Aars) | 
| Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 1449 | android.InitApexModule(module) | 
| Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 1450 | InitJavaModuleMultiTargets(module, android.DeviceSupported) | 
| Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 1451 | return module | 
|  | 1452 | } |