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