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 | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 20 | "strconv" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 21 | "strings" |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 22 | |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 23 | "android/soong/android" |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 24 | "android/soong/dexpreopt" |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 25 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 30 | type AndroidLibraryDependency interface { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 31 | ExportPackage() android.Path |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 32 | ExportedProguardFlagFiles() android.Paths |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 33 | ExportedRRODirs() []rroDir |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 34 | ExportedStaticPackages() android.Paths |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 35 | ExportedManifests() android.Paths |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 36 | ExportedAssets() android.OptionalPath |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 37 | SetRROEnforcedForDependent(enforce bool) |
| 38 | IsRROEnforced(ctx android.BaseModuleContext) bool |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | func init() { |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 42 | RegisterAARBuildComponents(android.InitRegistrationContext) |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 43 | |
| 44 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 45 | ctx.TopDown("propagate_rro_enforcement", propagateRROEnforcementMutator).Parallel() |
| 46 | }) |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | func RegisterAARBuildComponents(ctx android.RegistrationContext) { |
| 50 | ctx.RegisterModuleType("android_library_import", AARImportFactory) |
| 51 | ctx.RegisterModuleType("android_library", AndroidLibraryFactory) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // |
| 55 | // AAR (android library) |
| 56 | // |
| 57 | |
| 58 | type androidLibraryProperties struct { |
| 59 | BuildAAR bool `blueprint:"mutated"` |
| 60 | } |
| 61 | |
| 62 | type aaptProperties struct { |
| 63 | // flags passed to aapt when creating the apk |
| 64 | Aaptflags []string |
| 65 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 66 | // include all resource configurations, not just the product-configured |
| 67 | // ones. |
| 68 | Aapt_include_all_resources *bool |
| 69 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 70 | // list of directories relative to the Blueprints file containing assets. |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 71 | // Defaults to ["assets"] if a directory called assets exists. Set to [] |
| 72 | // to disable the default. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 73 | Asset_dirs []string |
| 74 | |
| 75 | // list of directories relative to the Blueprints file containing |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 76 | // Android resources. Defaults to ["res"] if a directory called res exists. |
| 77 | // Set to [] to disable the default. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 78 | Resource_dirs []string |
| 79 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 80 | // list of zip files containing Android resources. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 81 | Resource_zips []string `android:"path"` |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 82 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 83 | // path to AndroidManifest.xml. If unset, defaults to "AndroidManifest.xml". |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 84 | Manifest *string `android:"path"` |
changho.shin | b5432b7 | 2019-08-08 18:37:17 +0900 | [diff] [blame] | 85 | |
| 86 | // paths to additional manifest files to merge with main manifest. |
| 87 | Additional_manifests []string `android:"path"` |
Sasha Smundak | 541056c | 2019-10-28 15:50:06 -0700 | [diff] [blame] | 88 | |
| 89 | // do not include AndroidManifest from dependent libraries |
| 90 | Dont_merge_manifests *bool |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 91 | |
| 92 | // true if RRO is enforced for any of the dependent modules |
| 93 | RROEnforcedForDependent bool `blueprint:"mutated"` |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | type aapt struct { |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 97 | aaptSrcJar android.Path |
| 98 | exportPackage android.Path |
| 99 | manifestPath android.Path |
| 100 | transitiveManifestPaths android.Paths |
| 101 | proguardOptionsFile android.Path |
| 102 | rroDirs []rroDir |
| 103 | rTxt android.Path |
| 104 | extraAaptPackagesFile android.Path |
| 105 | mergedManifestFile android.Path |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 106 | noticeFile android.OptionalPath |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 107 | assetPackage android.OptionalPath |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 108 | isLibrary bool |
Sasha Smundak | 6ad7725 | 2019-05-01 13:16:22 -0700 | [diff] [blame] | 109 | useEmbeddedNativeLibs bool |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 110 | useEmbeddedDex bool |
| 111 | usesNonSdkApis bool |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 112 | hasNoCode bool |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 113 | LoggingParent string |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 114 | resourceFiles android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 115 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 116 | splitNames []string |
| 117 | splits []split |
| 118 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 119 | aaptProperties aaptProperties |
| 120 | } |
| 121 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 122 | type split struct { |
| 123 | name string |
| 124 | suffix string |
| 125 | path android.Path |
| 126 | } |
| 127 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 128 | // Propagate RRO enforcement flag to static lib dependencies transitively. |
| 129 | func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) { |
| 130 | m := ctx.Module() |
| 131 | if d, ok := m.(AndroidLibraryDependency); ok && d.IsRROEnforced(ctx) { |
| 132 | ctx.VisitDirectDepsWithTag(staticLibTag, func(d android.Module) { |
| 133 | if a, ok := d.(AndroidLibraryDependency); ok { |
| 134 | a.SetRROEnforcedForDependent(true) |
| 135 | } |
| 136 | }) |
| 137 | } |
| 138 | } |
| 139 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 140 | func (a *aapt) ExportPackage() android.Path { |
| 141 | return a.exportPackage |
| 142 | } |
| 143 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 144 | func (a *aapt) ExportedRRODirs() []rroDir { |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 145 | return a.rroDirs |
| 146 | } |
| 147 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 148 | func (a *aapt) ExportedManifests() android.Paths { |
| 149 | return a.transitiveManifestPaths |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 152 | func (a *aapt) ExportedAssets() android.OptionalPath { |
| 153 | return a.assetPackage |
| 154 | } |
| 155 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 156 | func (a *aapt) SetRROEnforcedForDependent(enforce bool) { |
| 157 | a.aaptProperties.RROEnforcedForDependent = enforce |
| 158 | } |
| 159 | |
| 160 | func (a *aapt) IsRROEnforced(ctx android.BaseModuleContext) bool { |
| 161 | // True if RRO is enforced for this module or... |
| 162 | return ctx.Config().EnforceRROForModule(ctx.ModuleName()) || |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 163 | // if RRO is enforced for any of its dependents. |
| 164 | a.aaptProperties.RROEnforcedForDependent |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 167 | func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, |
| 168 | manifestPath android.Path) (compileFlags, linkFlags []string, linkDeps android.Paths, |
| 169 | resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 170 | |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 171 | hasVersionCode := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-code") |
| 172 | hasVersionName := android.PrefixInList(a.aaptProperties.Aaptflags, "--version-name") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 173 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 174 | // Flags specified in Android.bp |
| 175 | linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...) |
| 176 | |
| 177 | linkFlags = append(linkFlags, "--no-static-lib-packages") |
| 178 | |
| 179 | // Find implicit or explicit asset and resource dirs |
| 180 | assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") |
| 181 | resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 182 | resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 183 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 184 | // Glob directories into lists of paths |
| 185 | for _, dir := range resourceDirs { |
| 186 | resDirs = append(resDirs, globbedResourceDir{ |
| 187 | dir: dir, |
| 188 | files: androidResourceGlob(ctx, dir), |
| 189 | }) |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 190 | resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, a, dir) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 191 | overlayDirs = append(overlayDirs, resOverlayDirs...) |
| 192 | rroDirs = append(rroDirs, resRRODirs...) |
| 193 | } |
| 194 | |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 195 | var assetDeps android.Paths |
| 196 | for i, dir := range assetDirs { |
| 197 | // Add a dependency on every file in the asset directory. This ensures the aapt2 |
| 198 | // rule will be rerun if one of the files in the asset directory is modified. |
| 199 | assetDeps = append(assetDeps, androidResourceGlob(ctx, dir)...) |
| 200 | |
| 201 | // Add a dependency on a file that contains a list of all the files in the asset directory. |
| 202 | // This ensures the aapt2 rule will be run if a file is removed from the asset directory, |
| 203 | // or a file is added whose timestamp is older than the output of aapt2. |
| 204 | assetFileListFile := android.PathForModuleOut(ctx, "asset_dir_globs", strconv.Itoa(i)+".glob") |
| 205 | androidResourceGlobList(ctx, dir, assetFileListFile) |
| 206 | assetDeps = append(assetDeps, assetFileListFile) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 209 | assetDirStrings := assetDirs.Strings() |
| 210 | if a.noticeFile.Valid() { |
| 211 | assetDirStrings = append(assetDirStrings, filepath.Dir(a.noticeFile.Path().String())) |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 212 | assetDeps = append(assetDeps, a.noticeFile.Path()) |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 215 | linkFlags = append(linkFlags, "--manifest "+manifestPath.String()) |
| 216 | linkDeps = append(linkDeps, manifestPath) |
| 217 | |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 218 | linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirStrings, "-A ")) |
Colin Cross | c20dc85 | 2020-11-10 12:27:45 -0800 | [diff] [blame] | 219 | linkDeps = append(linkDeps, assetDeps...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 220 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 221 | // SDK version flags |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 222 | minSdkVersion, err := sdkContext.minSdkVersion().effectiveVersionString(ctx) |
| 223 | if err != nil { |
| 224 | ctx.ModuleErrorf("invalid minSdkVersion: %s", err) |
| 225 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 226 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 227 | linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion) |
| 228 | linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 229 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 230 | // Version code |
| 231 | if !hasVersionCode { |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 232 | linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | if !hasVersionName { |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 236 | var versionName string |
| 237 | if ctx.ModuleName() == "framework-res" { |
| 238 | // Some builds set AppsDefaultVersionName() to include the build number ("O-123456"). aapt2 copies the |
| 239 | // 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] | 240 | // if it contains the build number. Use the PlatformVersionName instead. |
| 241 | versionName = ctx.Config().PlatformVersionName() |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 242 | } else { |
| 243 | versionName = ctx.Config().AppsDefaultVersionName() |
| 244 | } |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 245 | versionName = proptools.NinjaEscape(versionName) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 246 | linkFlags = append(linkFlags, "--version-name ", versionName) |
| 247 | } |
| 248 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 249 | linkFlags, compileFlags = android.FilterList(linkFlags, []string{"--legacy"}) |
| 250 | |
| 251 | // Always set --pseudo-localize, it will be stripped out later for release |
| 252 | // builds that don't want it. |
| 253 | compileFlags = append(compileFlags, "--pseudo-localize") |
| 254 | |
| 255 | return compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 258 | func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkDep sdkDep) { |
Colin Cross | 42308aa | 2018-11-14 21:44:17 -0800 | [diff] [blame] | 259 | if sdkDep.frameworkResModule != "" { |
| 260 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 264 | var extractAssetsRule = pctx.AndroidStaticRule("extractAssets", |
| 265 | blueprint.RuleParams{ |
| 266 | Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} "assets/**/*"`, |
| 267 | CommandDeps: []string{"${config.Zip2ZipCmd}"}, |
| 268 | }) |
| 269 | |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 270 | func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 271 | classLoaderContexts dexpreopt.ClassLoaderContextMap, extraLinkFlags ...string) { |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 272 | |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 273 | transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags := |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 274 | aaptLibs(ctx, sdkContext, classLoaderContexts) |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 275 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 276 | // App manifest file |
| 277 | manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") |
| 278 | manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) |
| 279 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 280 | manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, classLoaderContexts, |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 281 | a.isLibrary, a.useEmbeddedNativeLibs, a.usesNonSdkApis, a.useEmbeddedDex, a.hasNoCode, |
| 282 | a.LoggingParent) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 283 | |
Luca Stefani | fd89882 | 2019-09-10 22:13:31 +0200 | [diff] [blame] | 284 | // Add additional manifest files to transitive manifests. |
| 285 | additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests) |
| 286 | a.transitiveManifestPaths = append(android.Paths{manifestPath}, additionalManifests...) |
| 287 | a.transitiveManifestPaths = append(a.transitiveManifestPaths, transitiveStaticLibManifests...) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 288 | |
Sasha Smundak | 541056c | 2019-10-28 15:50:06 -0700 | [diff] [blame] | 289 | if len(a.transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) { |
Luca Stefani | fd89882 | 2019-09-10 22:13:31 +0200 | [diff] [blame] | 290 | a.mergedManifestFile = manifestMerger(ctx, a.transitiveManifestPaths[0], a.transitiveManifestPaths[1:], a.isLibrary) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 291 | if !a.isLibrary { |
| 292 | // Only use the merged manifest for applications. For libraries, the transitive closure of manifests |
| 293 | // will be propagated to the final application and merged there. The merged manifest for libraries is |
| 294 | // only passed to Make, which can't handle transitive dependencies. |
| 295 | manifestPath = a.mergedManifestFile |
| 296 | } |
| 297 | } else { |
| 298 | a.mergedManifestFile = manifestPath |
| 299 | } |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 300 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 301 | compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 302 | |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 303 | rroDirs = append(rroDirs, staticRRODirs...) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 304 | linkFlags = append(linkFlags, libFlags...) |
| 305 | linkDeps = append(linkDeps, libDeps...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 306 | linkFlags = append(linkFlags, extraLinkFlags...) |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame] | 307 | if a.isLibrary { |
| 308 | linkFlags = append(linkFlags, "--static-lib") |
| 309 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 310 | |
| 311 | packageRes := android.PathForModuleOut(ctx, "package-res.apk") |
Jiyong Park | b7c639e | 2019-08-19 14:56:02 +0900 | [diff] [blame] | 312 | // the subdir "android" is required to be filtered by package names |
| 313 | srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 314 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
| 315 | rTxt := android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 316 | // This file isn't used by Soong, but is generated for exporting |
| 317 | extraPackages := android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 318 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 319 | var compiledResDirs []android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 320 | for _, dir := range resDirs { |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 321 | a.resourceFiles = append(a.resourceFiles, dir.files...) |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 322 | compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 323 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 324 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 325 | for i, zip := range resZips { |
| 326 | flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i)) |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 327 | aapt2CompileZip(ctx, flata, zip, "", compileFlags) |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 328 | compiledResDirs = append(compiledResDirs, android.Paths{flata}) |
| 329 | } |
| 330 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 331 | var compiledRes, compiledOverlay android.Paths |
| 332 | |
| 333 | compiledOverlay = append(compiledOverlay, transitiveStaticLibs...) |
| 334 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 335 | if len(transitiveStaticLibs) > 0 { |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 336 | // If we are using static android libraries, every source file becomes an overlay. |
| 337 | // This is to emulate old AAPT behavior which simulated library support. |
| 338 | for _, compiledResDir := range compiledResDirs { |
| 339 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 340 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 341 | } else if a.isLibrary { |
| 342 | // Otherwise, for a static library we treat all the resources equally with no overlay. |
| 343 | for _, compiledResDir := range compiledResDirs { |
| 344 | compiledRes = append(compiledRes, compiledResDir...) |
| 345 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 346 | } else if len(compiledResDirs) > 0 { |
| 347 | // Without static libraries, the first directory is our directory, which can then be |
| 348 | // overlaid by the rest. |
| 349 | compiledRes = append(compiledRes, compiledResDirs[0]...) |
| 350 | for _, compiledResDir := range compiledResDirs[1:] { |
| 351 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 352 | } |
| 353 | } |
| 354 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 355 | for _, dir := range overlayDirs { |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 356 | compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags).Paths()...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 359 | var splitPackages android.WritablePaths |
| 360 | var splits []split |
| 361 | |
| 362 | for _, s := range a.splitNames { |
| 363 | suffix := strings.Replace(s, ",", "_", -1) |
| 364 | path := android.PathForModuleOut(ctx, "package_"+suffix+".apk") |
| 365 | linkFlags = append(linkFlags, "--split", path.String()+":"+s) |
| 366 | splitPackages = append(splitPackages, path) |
| 367 | splits = append(splits, split{ |
| 368 | name: s, |
| 369 | suffix: suffix, |
| 370 | path: path, |
| 371 | }) |
| 372 | } |
| 373 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 374 | aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages, |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 375 | linkFlags, linkDeps, compiledRes, compiledOverlay, assetPackages, splitPackages) |
| 376 | |
| 377 | // Extract assets from the resource package output so that they can be used later in aapt2link |
| 378 | // for modules that depend on this one. |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 379 | if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 { |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 380 | assets := android.PathForModuleOut(ctx, "assets.zip") |
| 381 | ctx.Build(pctx, android.BuildParams{ |
| 382 | Rule: extractAssetsRule, |
| 383 | Input: packageRes, |
| 384 | Output: assets, |
| 385 | Description: "extract assets from built resource file", |
| 386 | }) |
| 387 | a.assetPackage = android.OptionalPathForPath(assets) |
| 388 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 389 | |
| 390 | a.aaptSrcJar = srcJar |
| 391 | a.exportPackage = packageRes |
| 392 | a.manifestPath = manifestPath |
| 393 | a.proguardOptionsFile = proguardOptionsFile |
| 394 | a.rroDirs = rroDirs |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 395 | a.extraAaptPackagesFile = extraPackages |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 396 | a.rTxt = rTxt |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 397 | a.splits = splits |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // aaptLibs collects libraries from dependencies and sdk_version and converts them into paths |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 401 | func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) ( |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 402 | transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) { |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 403 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 404 | var sharedLibs android.Paths |
| 405 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 406 | if classLoaderContexts == nil { |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 407 | // Not all callers need to compute class loader context, those who don't just pass nil. |
| 408 | // 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] | 409 | classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 412 | sdkDep := decodeSdkDep(ctx, sdkContext) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 413 | if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 414 | sharedLibs = append(sharedLibs, sdkDep.jars...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | ctx.VisitDirectDeps(func(module android.Module) { |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 418 | depTag := ctx.OtherModuleDependencyTag(module) |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 419 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 420 | var exportPackage android.Path |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 421 | aarDep, _ := module.(AndroidLibraryDependency) |
| 422 | if aarDep != nil { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 423 | exportPackage = aarDep.ExportPackage() |
| 424 | } |
| 425 | |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 426 | switch depTag { |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 427 | case instrumentationForTag: |
| 428 | // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2. |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 429 | case libTag: |
| 430 | if exportPackage != nil { |
| 431 | sharedLibs = append(sharedLibs, exportPackage) |
| 432 | } |
Colin Cross | 5446e88 | 2019-05-22 10:46:27 -0700 | [diff] [blame] | 433 | case frameworkResTag: |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 434 | if exportPackage != nil { |
| 435 | sharedLibs = append(sharedLibs, exportPackage) |
| 436 | } |
| 437 | case staticLibTag: |
| 438 | if exportPackage != nil { |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 439 | transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...) |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 440 | transitiveStaticLibs = append(transitiveStaticLibs, exportPackage) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 441 | transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 442 | if aarDep.ExportedAssets().Valid() { |
| 443 | assets = append(assets, aarDep.ExportedAssets().Path()) |
| 444 | } |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 445 | |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 446 | outer: |
| 447 | for _, d := range aarDep.ExportedRRODirs() { |
| 448 | for _, e := range staticRRODirs { |
| 449 | if d.path == e.path { |
| 450 | continue outer |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 451 | } |
| 452 | } |
Jeongik Cha | cee5ba9 | 2021-02-19 12:11:51 +0900 | [diff] [blame] | 453 | staticRRODirs = append(staticRRODirs, d) |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 454 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 457 | |
Ulya Trafimovich | 88bb6f6 | 2020-12-16 16:16:11 +0000 | [diff] [blame] | 458 | addCLCFromDep(ctx, module, classLoaderContexts) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 459 | }) |
| 460 | |
| 461 | deps = append(deps, sharedLibs...) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 462 | deps = append(deps, transitiveStaticLibs...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 463 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 464 | if len(transitiveStaticLibs) > 0 { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 465 | flags = append(flags, "--auto-add-overlay") |
| 466 | } |
| 467 | |
| 468 | for _, sharedLib := range sharedLibs { |
| 469 | flags = append(flags, "-I "+sharedLib.String()) |
| 470 | } |
| 471 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 472 | transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 473 | transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 474 | |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 475 | return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | type AndroidLibrary struct { |
| 479 | Library |
| 480 | aapt |
| 481 | |
| 482 | androidLibraryProperties androidLibraryProperties |
| 483 | |
| 484 | aarFile android.WritablePath |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 485 | |
| 486 | exportedProguardFlagFiles android.Paths |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 487 | exportedStaticPackages android.Paths |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths { |
| 491 | return a.exportedProguardFlagFiles |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 494 | func (a *AndroidLibrary) ExportedStaticPackages() android.Paths { |
| 495 | return a.exportedStaticPackages |
| 496 | } |
| 497 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 498 | var _ AndroidLibraryDependency = (*AndroidLibrary)(nil) |
| 499 | |
| 500 | func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 501 | a.Module.deps(ctx) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 502 | sdkDep := decodeSdkDep(ctx, sdkContext(a)) |
| 503 | if sdkDep.hasFrameworkLibs() { |
| 504 | a.aapt.deps(ctx, sdkDep) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 509 | a.aapt.isLibrary = true |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 510 | a.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap) |
| 511 | a.aapt.buildActions(ctx, sdkContext(a), a.classLoaderContexts) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 512 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 513 | a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
| 514 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 515 | ctx.CheckbuildFile(a.proguardOptionsFile) |
| 516 | ctx.CheckbuildFile(a.exportPackage) |
| 517 | ctx.CheckbuildFile(a.aaptSrcJar) |
| 518 | |
| 519 | // apps manifests are handled by aapt, don't let Module see them |
| 520 | a.properties.Manifest = nil |
| 521 | |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 522 | a.linter.mergedManifest = a.aapt.mergedManifestFile |
| 523 | a.linter.manifest = a.aapt.manifestPath |
| 524 | a.linter.resources = a.aapt.resourceFiles |
| 525 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 526 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, |
| 527 | a.proguardOptionsFile) |
| 528 | |
| 529 | a.Module.compile(ctx, a.aaptSrcJar) |
| 530 | |
Colin Cross | f57c578 | 2019-01-25 13:20:38 -0800 | [diff] [blame] | 531 | a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 532 | var res android.Paths |
| 533 | if a.androidLibraryProperties.BuildAAR { |
| 534 | BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res) |
| 535 | ctx.CheckbuildFile(a.aarFile) |
| 536 | } |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 537 | |
Cole Faust | 9a63131 | 2020-10-22 21:05:24 +0000 | [diff] [blame] | 538 | a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, |
| 539 | android.PathsForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)...) |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 540 | ctx.VisitDirectDeps(func(m android.Module) { |
| 541 | if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 542 | a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 543 | a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportPackage()) |
| 544 | a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportedStaticPackages()...) |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 545 | } |
| 546 | }) |
| 547 | |
| 548 | a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 549 | a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 552 | // android_library builds and links sources into a `.jar` file for the device along with Android resources. |
| 553 | // |
| 554 | // An android_library has a single variant that produces a `.jar` file containing `.class` files that were |
| 555 | // compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled |
| 556 | // with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 557 | // an android_app module. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 558 | func AndroidLibraryFactory() android.Module { |
| 559 | module := &AndroidLibrary{} |
| 560 | |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 561 | module.Module.addHostAndDeviceProperties() |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 562 | module.AddProperties( |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 563 | &module.aaptProperties, |
| 564 | &module.androidLibraryProperties) |
| 565 | |
| 566 | module.androidLibraryProperties.BuildAAR = true |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 567 | module.Module.linter.library = true |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 568 | |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 569 | android.InitApexModule(module) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 570 | InitJavaModule(module, android.DeviceSupported) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 571 | return module |
| 572 | } |
| 573 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 574 | // |
| 575 | // AAR (android library) prebuilts |
| 576 | // |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 577 | |
| 578 | type AARImportProperties struct { |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 579 | Aars []string `android:"path"` |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 580 | |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 581 | Sdk_version *string |
| 582 | Min_sdk_version *string |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 583 | |
| 584 | Static_libs []string |
| 585 | Libs []string |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 586 | |
| 587 | // if set to true, run Jetifier against .aar file. Defaults to false. |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 588 | Jetifier *bool |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | type AARImport struct { |
| 592 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 593 | android.DefaultableModuleBase |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 594 | android.ApexModuleBase |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 595 | prebuilt android.Prebuilt |
| 596 | |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 597 | // Functionality common to Module and Import. |
| 598 | embeddableInModuleAndImport |
| 599 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 600 | properties AARImportProperties |
| 601 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 602 | classpathFile android.WritablePath |
| 603 | proguardFlags android.WritablePath |
| 604 | exportPackage android.WritablePath |
| 605 | extraAaptPackagesFile android.WritablePath |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 606 | manifest android.WritablePath |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 607 | |
| 608 | exportedStaticPackages android.Paths |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 609 | |
| 610 | hideApexVariantFromMake bool |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 611 | |
| 612 | aarPath android.Path |
| 613 | } |
| 614 | |
| 615 | var _ android.OutputFileProducer = (*AARImport)(nil) |
| 616 | |
| 617 | // For OutputFileProducer interface |
| 618 | func (a *AARImport) OutputFiles(tag string) (android.Paths, error) { |
| 619 | switch tag { |
| 620 | case ".aar": |
| 621 | return []android.Path{a.aarPath}, nil |
| 622 | case "": |
| 623 | return []android.Path{a.classpathFile}, nil |
| 624 | default: |
| 625 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 626 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 629 | func (a *AARImport) sdkVersion() sdkSpec { |
| 630 | return sdkSpecFrom(String(a.properties.Sdk_version)) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 633 | func (a *AARImport) systemModules() string { |
| 634 | return "" |
| 635 | } |
| 636 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 637 | func (a *AARImport) minSdkVersion() sdkSpec { |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 638 | if a.properties.Min_sdk_version != nil { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 639 | return sdkSpecFrom(*a.properties.Min_sdk_version) |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 640 | } |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 641 | return a.sdkVersion() |
| 642 | } |
| 643 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 644 | func (a *AARImport) targetSdkVersion() sdkSpec { |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 645 | return a.sdkVersion() |
| 646 | } |
| 647 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 648 | func (a *AARImport) javaVersion() string { |
| 649 | return "" |
| 650 | } |
| 651 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 652 | var _ AndroidLibraryDependency = (*AARImport)(nil) |
| 653 | |
| 654 | func (a *AARImport) ExportPackage() android.Path { |
| 655 | return a.exportPackage |
| 656 | } |
| 657 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 658 | func (a *AARImport) ExportedProguardFlagFiles() android.Paths { |
| 659 | return android.Paths{a.proguardFlags} |
| 660 | } |
| 661 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 662 | func (a *AARImport) ExportedRRODirs() []rroDir { |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 663 | return nil |
| 664 | } |
| 665 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 666 | func (a *AARImport) ExportedStaticPackages() android.Paths { |
| 667 | return a.exportedStaticPackages |
| 668 | } |
| 669 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame] | 670 | func (a *AARImport) ExportedManifests() android.Paths { |
| 671 | return android.Paths{a.manifest} |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 674 | // TODO(jungjw): Decide whether we want to implement this. |
| 675 | func (a *AARImport) ExportedAssets() android.OptionalPath { |
| 676 | return android.OptionalPath{} |
| 677 | } |
| 678 | |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 679 | // RRO enforcement is not available on aar_import since its RRO dirs are not |
| 680 | // exported. |
| 681 | func (a *AARImport) SetRROEnforcedForDependent(enforce bool) { |
| 682 | } |
| 683 | |
| 684 | // RRO enforcement is not available on aar_import since its RRO dirs are not |
| 685 | // exported. |
| 686 | func (a *AARImport) IsRROEnforced(ctx android.BaseModuleContext) bool { |
| 687 | return false |
| 688 | } |
| 689 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 690 | func (a *AARImport) Prebuilt() *android.Prebuilt { |
| 691 | return &a.prebuilt |
| 692 | } |
| 693 | |
| 694 | func (a *AARImport) Name() string { |
| 695 | return a.prebuilt.Name(a.ModuleBase.Name()) |
| 696 | } |
| 697 | |
Jiyong Park | 618922e | 2020-01-08 13:35:43 +0900 | [diff] [blame] | 698 | func (a *AARImport) JacocoReportClassesFile() android.Path { |
| 699 | return nil |
| 700 | } |
| 701 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 702 | func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 703 | if !ctx.Config().AlwaysUsePrebuiltSdks() { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 704 | sdkDep := decodeSdkDep(ctx, sdkContext(a)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 705 | if sdkDep.useModule && sdkDep.frameworkResModule != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 706 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 707 | } |
| 708 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 709 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 710 | ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...) |
| 711 | ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | // 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] | 715 | // 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] | 716 | var unzipAAR = pctx.AndroidStaticRule("unzipAAR", |
| 717 | blueprint.RuleParams{ |
Dan Willemsen | 304cfec | 2019-05-28 14:49:06 -0700 | [diff] [blame] | 718 | Command: `rm -rf $outDir && mkdir -p $outDir && ` + |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 719 | `unzip -qoDD -d $outDir $in && rm -rf $outDir/res && touch $out && ` + |
| 720 | `${config.MergeZipsCmd} $combinedClassesJar $$(ls $outDir/classes.jar 2> /dev/null) $$(ls $outDir/libs/*.jar 2> /dev/null)`, |
| 721 | CommandDeps: []string{"${config.MergeZipsCmd}"}, |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 722 | }, |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 723 | "outDir", "combinedClassesJar") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 724 | |
| 725 | func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 726 | if len(a.properties.Aars) != 1 { |
| 727 | ctx.PropertyErrorf("aars", "exactly one aar is required") |
| 728 | return |
| 729 | } |
| 730 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 731 | a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
| 732 | |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 733 | aarName := ctx.ModuleName() + ".aar" |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 734 | a.aarPath = android.PathForModuleSrc(ctx, a.properties.Aars[0]) |
| 735 | |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 736 | if Bool(a.properties.Jetifier) { |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 737 | inputFile := a.aarPath |
| 738 | a.aarPath = android.PathForModuleOut(ctx, "jetifier", aarName) |
| 739 | TransformJetifier(ctx, a.aarPath.(android.WritablePath), inputFile) |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 740 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 741 | |
| 742 | extractedAARDir := android.PathForModuleOut(ctx, "aar") |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 743 | a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 744 | a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 745 | a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 746 | |
| 747 | ctx.Build(pctx, android.BuildParams{ |
| 748 | Rule: unzipAAR, |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 749 | Input: a.aarPath, |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 750 | Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest}, |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 751 | Description: "unzip AAR", |
| 752 | Args: map[string]string{ |
Colin Cross | 205e911 | 2020-08-06 13:20:17 -0700 | [diff] [blame] | 753 | "outDir": extractedAARDir.String(), |
| 754 | "combinedClassesJar": a.classpathFile.String(), |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 755 | }, |
| 756 | }) |
| 757 | |
Colin Cross | a0ba2f5 | 2019-06-22 12:59:27 -0700 | [diff] [blame] | 758 | // Always set --pseudo-localize, it will be stripped out later for release |
| 759 | // builds that don't want it. |
| 760 | compileFlags := []string{"--pseudo-localize"} |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 761 | compiledResDir := android.PathForModuleOut(ctx, "flat-res") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 762 | flata := compiledResDir.Join(ctx, "gen_res.flata") |
Saeid Farivar Asanjan | f043696 | 2020-10-05 19:09:09 +0000 | [diff] [blame] | 763 | aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 764 | |
| 765 | a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk") |
Jiyong Park | b7c639e | 2019-08-19 14:56:02 +0900 | [diff] [blame] | 766 | // the subdir "android" is required to be filtered by package names |
| 767 | srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 768 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 769 | rTxt := android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 770 | a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 771 | |
| 772 | var linkDeps android.Paths |
| 773 | |
| 774 | linkFlags := []string{ |
| 775 | "--static-lib", |
| 776 | "--no-static-lib-packages", |
| 777 | "--auto-add-overlay", |
| 778 | } |
| 779 | |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 780 | linkFlags = append(linkFlags, "--manifest "+a.manifest.String()) |
| 781 | linkDeps = append(linkDeps, a.manifest) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 782 | |
Ulya Trafimovich | 1855424 | 2020-11-03 15:55:11 +0000 | [diff] [blame] | 783 | transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags := |
| 784 | aaptLibs(ctx, sdkContext(a), nil) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 785 | |
| 786 | _ = staticLibManifests |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 787 | _ = staticRRODirs |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 788 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 789 | linkDeps = append(linkDeps, libDeps...) |
| 790 | linkFlags = append(linkFlags, libFlags...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 791 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 792 | overlayRes := append(android.Paths{flata}, transitiveStaticLibs...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 793 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 794 | aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile, |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 795 | linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 796 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 797 | ctx.SetProvider(JavaInfoProvider, JavaInfo{ |
| 798 | HeaderJars: android.PathsIfNonNil(a.classpathFile), |
| 799 | ImplementationAndResourcesJars: android.PathsIfNonNil(a.classpathFile), |
| 800 | ImplementationJars: android.PathsIfNonNil(a.classpathFile), |
| 801 | }) |
| 802 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 803 | |
| 804 | func (a *AARImport) HeaderJars() android.Paths { |
| 805 | return android.Paths{a.classpathFile} |
| 806 | } |
| 807 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 808 | func (a *AARImport) ImplementationAndResourcesJars() android.Paths { |
| 809 | return android.Paths{a.classpathFile} |
| 810 | } |
| 811 | |
Ulyana Trafimovich | 5539e7b | 2020-06-04 14:08:17 +0000 | [diff] [blame] | 812 | func (a *AARImport) DexJarBuildPath() android.Path { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 813 | return nil |
| 814 | } |
| 815 | |
Ulya Trafimovich | 9f3052c | 2020-06-09 14:31:19 +0100 | [diff] [blame] | 816 | func (a *AARImport) DexJarInstallPath() android.Path { |
| 817 | return nil |
| 818 | } |
| 819 | |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 820 | func (a *AARImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 821 | return nil |
| 822 | } |
| 823 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 824 | var _ android.ApexModule = (*AARImport)(nil) |
| 825 | |
| 826 | // Implements android.ApexModule |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 827 | func (a *AARImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 828 | return a.depIsInSameApex(ctx, dep) |
| 829 | } |
| 830 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 831 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 832 | func (g *AARImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 833 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 834 | return nil |
| 835 | } |
| 836 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 837 | var _ android.PrebuiltInterface = (*Import)(nil) |
| 838 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 839 | // android_library_import imports an `.aar` file into the build graph as if it was built with android_library. |
| 840 | // |
| 841 | // This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 842 | // an android_app module. |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 843 | func AARImportFactory() android.Module { |
| 844 | module := &AARImport{} |
| 845 | |
| 846 | module.AddProperties(&module.properties) |
| 847 | |
| 848 | android.InitPrebuiltModule(module, &module.properties.Aars) |
Jooyung Han | acc7bbe | 2020-05-20 09:06:00 +0900 | [diff] [blame] | 849 | android.InitApexModule(module) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 850 | InitJavaModule(module, android.DeviceSupported) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 851 | return module |
| 852 | } |