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