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