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 ( |
| 18 | "android/soong/android" |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 19 | "fmt" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 20 | "strings" |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 21 | |
| 22 | "github.com/google/blueprint" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 26 | type AndroidLibraryDependency interface { |
| 27 | Dependency |
| 28 | ExportPackage() android.Path |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 29 | ExportedProguardFlagFiles() android.Paths |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 30 | ExportedRRODirs() []rroDir |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 31 | ExportedStaticPackages() android.Paths |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 32 | ExportedManifests() android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | func init() { |
| 36 | android.RegisterModuleType("android_library_import", AARImportFactory) |
| 37 | android.RegisterModuleType("android_library", AndroidLibraryFactory) |
| 38 | } |
| 39 | |
| 40 | // |
| 41 | // AAR (android library) |
| 42 | // |
| 43 | |
| 44 | type androidLibraryProperties struct { |
| 45 | BuildAAR bool `blueprint:"mutated"` |
| 46 | } |
| 47 | |
| 48 | type aaptProperties struct { |
| 49 | // flags passed to aapt when creating the apk |
| 50 | Aaptflags []string |
| 51 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 52 | // include all resource configurations, not just the product-configured |
| 53 | // ones. |
| 54 | Aapt_include_all_resources *bool |
| 55 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 56 | // list of directories relative to the Blueprints file containing assets. |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 57 | // Defaults to ["assets"] if a directory called assets exists. Set to [] |
| 58 | // to disable the default. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 59 | Asset_dirs []string |
| 60 | |
| 61 | // list of directories relative to the Blueprints file containing |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 62 | // Android resources. Defaults to ["res"] if a directory called res exists. |
| 63 | // Set to [] to disable the default. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 64 | Resource_dirs []string |
| 65 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 66 | // list of zip files containing Android resources. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 67 | Resource_zips []string `android:"path"` |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 68 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 69 | // path to AndroidManifest.xml. If unset, defaults to "AndroidManifest.xml". |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 70 | Manifest *string `android:"path"` |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | type aapt struct { |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 74 | aaptSrcJar android.Path |
| 75 | exportPackage android.Path |
| 76 | manifestPath android.Path |
| 77 | transitiveManifestPaths android.Paths |
| 78 | proguardOptionsFile android.Path |
| 79 | rroDirs []rroDir |
| 80 | rTxt android.Path |
| 81 | extraAaptPackagesFile android.Path |
| 82 | mergedManifestFile android.Path |
| 83 | isLibrary bool |
| 84 | uncompressedJNI bool |
| 85 | useEmbeddedDex bool |
| 86 | usesNonSdkApis bool |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 87 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 88 | splitNames []string |
| 89 | splits []split |
| 90 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 91 | aaptProperties aaptProperties |
| 92 | } |
| 93 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 94 | type split struct { |
| 95 | name string |
| 96 | suffix string |
| 97 | path android.Path |
| 98 | } |
| 99 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 100 | func (a *aapt) ExportPackage() android.Path { |
| 101 | return a.exportPackage |
| 102 | } |
| 103 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 104 | func (a *aapt) ExportedRRODirs() []rroDir { |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 105 | return a.rroDirs |
| 106 | } |
| 107 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 108 | func (a *aapt) ExportedManifests() android.Paths { |
| 109 | return a.transitiveManifestPaths |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 112 | func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string, |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 113 | deps android.Paths, resDirs, overlayDirs []globbedResourceDir, rroDirs []rroDir, resZips android.Paths) { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 114 | |
| 115 | hasVersionCode := false |
| 116 | hasVersionName := false |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 117 | for _, f := range a.aaptProperties.Aaptflags { |
| 118 | if strings.HasPrefix(f, "--version-code") { |
| 119 | hasVersionCode = true |
| 120 | } else if strings.HasPrefix(f, "--version-name") { |
| 121 | hasVersionName = true |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | var linkFlags []string |
| 126 | |
| 127 | // Flags specified in Android.bp |
| 128 | linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...) |
| 129 | |
| 130 | linkFlags = append(linkFlags, "--no-static-lib-packages") |
| 131 | |
| 132 | // Find implicit or explicit asset and resource dirs |
| 133 | assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") |
| 134 | resourceDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 135 | resourceZips := android.PathsForModuleSrc(ctx, a.aaptProperties.Resource_zips) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 136 | |
| 137 | var linkDeps android.Paths |
| 138 | |
| 139 | // Glob directories into lists of paths |
| 140 | for _, dir := range resourceDirs { |
| 141 | resDirs = append(resDirs, globbedResourceDir{ |
| 142 | dir: dir, |
| 143 | files: androidResourceGlob(ctx, dir), |
| 144 | }) |
| 145 | resOverlayDirs, resRRODirs := overlayResourceGlob(ctx, dir) |
| 146 | overlayDirs = append(overlayDirs, resOverlayDirs...) |
| 147 | rroDirs = append(rroDirs, resRRODirs...) |
| 148 | } |
| 149 | |
| 150 | var assetFiles android.Paths |
| 151 | for _, dir := range assetDirs { |
| 152 | assetFiles = append(assetFiles, androidResourceGlob(ctx, dir)...) |
| 153 | } |
| 154 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 155 | linkFlags = append(linkFlags, "--manifest "+manifestPath.String()) |
| 156 | linkDeps = append(linkDeps, manifestPath) |
| 157 | |
| 158 | linkFlags = append(linkFlags, android.JoinWithPrefix(assetDirs.Strings(), "-A ")) |
| 159 | linkDeps = append(linkDeps, assetFiles...) |
| 160 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 161 | // SDK version flags |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 162 | minSdkVersion := sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 163 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 164 | linkFlags = append(linkFlags, "--min-sdk-version "+minSdkVersion) |
| 165 | linkFlags = append(linkFlags, "--target-sdk-version "+minSdkVersion) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 166 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 167 | // Version code |
| 168 | if !hasVersionCode { |
| 169 | linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion()) |
| 170 | } |
| 171 | |
| 172 | if !hasVersionName { |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 173 | var versionName string |
| 174 | if ctx.ModuleName() == "framework-res" { |
| 175 | // Some builds set AppsDefaultVersionName() to include the build number ("O-123456"). aapt2 copies the |
| 176 | // 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] | 177 | // if it contains the build number. Use the PlatformVersionName instead. |
| 178 | versionName = ctx.Config().PlatformVersionName() |
Colin Cross | 402d5e0 | 2018-04-25 14:54:06 -0700 | [diff] [blame] | 179 | } else { |
| 180 | versionName = ctx.Config().AppsDefaultVersionName() |
| 181 | } |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 182 | versionName = proptools.NinjaEscape(versionName) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 183 | linkFlags = append(linkFlags, "--version-name ", versionName) |
| 184 | } |
| 185 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 186 | return linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resourceZips |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 189 | func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) { |
Colin Cross | 42308aa | 2018-11-14 21:44:17 -0800 | [diff] [blame] | 190 | sdkDep := decodeSdkDep(ctx, sdkContext) |
| 191 | if sdkDep.frameworkResModule != "" { |
| 192 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 196 | func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) { |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 197 | transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 198 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 199 | // App manifest file |
| 200 | manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") |
| 201 | manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) |
| 202 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 203 | manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext, |
| 204 | a.isLibrary, a.uncompressedJNI, a.usesNonSdkApis, a.useEmbeddedDex) |
| 205 | |
| 206 | a.transitiveManifestPaths = append(android.Paths{manifestPath}, transitiveStaticLibManifests...) |
| 207 | |
| 208 | if len(transitiveStaticLibManifests) > 0 { |
| 209 | a.mergedManifestFile = manifestMerger(ctx, manifestPath, transitiveStaticLibManifests) |
| 210 | if !a.isLibrary { |
| 211 | // Only use the merged manifest for applications. For libraries, the transitive closure of manifests |
| 212 | // will be propagated to the final application and merged there. The merged manifest for libraries is |
| 213 | // only passed to Make, which can't handle transitive dependencies. |
| 214 | manifestPath = a.mergedManifestFile |
| 215 | } |
| 216 | } else { |
| 217 | a.mergedManifestFile = manifestPath |
| 218 | } |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 219 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 220 | linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 221 | |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 222 | rroDirs = append(rroDirs, staticRRODirs...) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 223 | linkFlags = append(linkFlags, libFlags...) |
| 224 | linkDeps = append(linkDeps, libDeps...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 225 | linkFlags = append(linkFlags, extraLinkFlags...) |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame] | 226 | if a.isLibrary { |
| 227 | linkFlags = append(linkFlags, "--static-lib") |
| 228 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 229 | |
| 230 | packageRes := android.PathForModuleOut(ctx, "package-res.apk") |
| 231 | srcJar := android.PathForModuleGen(ctx, "R.jar") |
| 232 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
| 233 | rTxt := android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 234 | // This file isn't used by Soong, but is generated for exporting |
| 235 | extraPackages := android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 236 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 237 | var compiledResDirs []android.Paths |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 238 | for _, dir := range resDirs { |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 239 | compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files).Paths()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 240 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 241 | |
Colin Cross | a592e3e | 2019-02-19 16:59:53 -0800 | [diff] [blame] | 242 | for i, zip := range resZips { |
| 243 | flata := android.PathForModuleOut(ctx, fmt.Sprintf("reszip.%d.flata", i)) |
| 244 | aapt2CompileZip(ctx, flata, zip) |
| 245 | compiledResDirs = append(compiledResDirs, android.Paths{flata}) |
| 246 | } |
| 247 | |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 248 | var compiledRes, compiledOverlay android.Paths |
| 249 | |
| 250 | compiledOverlay = append(compiledOverlay, transitiveStaticLibs...) |
| 251 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 252 | if len(transitiveStaticLibs) > 0 { |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 253 | // If we are using static android libraries, every source file becomes an overlay. |
| 254 | // This is to emulate old AAPT behavior which simulated library support. |
| 255 | for _, compiledResDir := range compiledResDirs { |
| 256 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 257 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 258 | } else if a.isLibrary { |
| 259 | // Otherwise, for a static library we treat all the resources equally with no overlay. |
| 260 | for _, compiledResDir := range compiledResDirs { |
| 261 | compiledRes = append(compiledRes, compiledResDir...) |
| 262 | } |
Colin Cross | 4aaa84a | 2018-08-21 15:14:37 -0700 | [diff] [blame] | 263 | } else if len(compiledResDirs) > 0 { |
| 264 | // Without static libraries, the first directory is our directory, which can then be |
| 265 | // overlaid by the rest. |
| 266 | compiledRes = append(compiledRes, compiledResDirs[0]...) |
| 267 | for _, compiledResDir := range compiledResDirs[1:] { |
| 268 | compiledOverlay = append(compiledOverlay, compiledResDir...) |
| 269 | } |
| 270 | } |
| 271 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 272 | for _, dir := range overlayDirs { |
| 273 | compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files).Paths()...) |
| 274 | } |
| 275 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 276 | var splitPackages android.WritablePaths |
| 277 | var splits []split |
| 278 | |
| 279 | for _, s := range a.splitNames { |
| 280 | suffix := strings.Replace(s, ",", "_", -1) |
| 281 | path := android.PathForModuleOut(ctx, "package_"+suffix+".apk") |
| 282 | linkFlags = append(linkFlags, "--split", path.String()+":"+s) |
| 283 | splitPackages = append(splitPackages, path) |
| 284 | splits = append(splits, split{ |
| 285 | name: s, |
| 286 | suffix: suffix, |
| 287 | path: path, |
| 288 | }) |
| 289 | } |
| 290 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 291 | aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages, |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 292 | linkFlags, linkDeps, compiledRes, compiledOverlay, splitPackages) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 293 | |
| 294 | a.aaptSrcJar = srcJar |
| 295 | a.exportPackage = packageRes |
| 296 | a.manifestPath = manifestPath |
| 297 | a.proguardOptionsFile = proguardOptionsFile |
| 298 | a.rroDirs = rroDirs |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 299 | a.extraAaptPackagesFile = extraPackages |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 300 | a.rTxt = rTxt |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 301 | a.splits = splits |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // aaptLibs collects libraries from dependencies and sdk_version and converts them into paths |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 305 | func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths, |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 306 | staticRRODirs []rroDir, deps android.Paths, flags []string) { |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 307 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 308 | var sharedLibs android.Paths |
| 309 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 310 | sdkDep := decodeSdkDep(ctx, sdkContext) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 311 | if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 312 | sharedLibs = append(sharedLibs, sdkDep.jars...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | ctx.VisitDirectDeps(func(module android.Module) { |
| 316 | var exportPackage android.Path |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 317 | aarDep, _ := module.(AndroidLibraryDependency) |
| 318 | if aarDep != nil { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 319 | exportPackage = aarDep.ExportPackage() |
| 320 | } |
| 321 | |
| 322 | switch ctx.OtherModuleDependencyTag(module) { |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 323 | case instrumentationForTag: |
| 324 | // Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 325 | case libTag, frameworkResTag: |
| 326 | if exportPackage != nil { |
| 327 | sharedLibs = append(sharedLibs, exportPackage) |
| 328 | } |
| 329 | case staticLibTag: |
| 330 | if exportPackage != nil { |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 331 | transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...) |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 332 | transitiveStaticLibs = append(transitiveStaticLibs, exportPackage) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 333 | transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...) |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 334 | |
| 335 | outer: |
| 336 | for _, d := range aarDep.ExportedRRODirs() { |
| 337 | for _, e := range staticRRODirs { |
| 338 | if d.path == e.path { |
| 339 | continue outer |
| 340 | } |
| 341 | } |
| 342 | staticRRODirs = append(staticRRODirs, d) |
| 343 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | }) |
| 347 | |
| 348 | deps = append(deps, sharedLibs...) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 349 | deps = append(deps, transitiveStaticLibs...) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 350 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 351 | if len(transitiveStaticLibs) > 0 { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 352 | flags = append(flags, "--auto-add-overlay") |
| 353 | } |
| 354 | |
| 355 | for _, sharedLib := range sharedLibs { |
| 356 | flags = append(flags, "-I "+sharedLib.String()) |
| 357 | } |
| 358 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 359 | transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs) |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 360 | transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 361 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 362 | return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, deps, flags |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | type AndroidLibrary struct { |
| 366 | Library |
| 367 | aapt |
| 368 | |
| 369 | androidLibraryProperties androidLibraryProperties |
| 370 | |
| 371 | aarFile android.WritablePath |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 372 | |
| 373 | exportedProguardFlagFiles android.Paths |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 374 | exportedStaticPackages android.Paths |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths { |
| 378 | return a.exportedProguardFlagFiles |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 381 | func (a *AndroidLibrary) ExportedStaticPackages() android.Paths { |
| 382 | return a.exportedStaticPackages |
| 383 | } |
| 384 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 385 | var _ AndroidLibraryDependency = (*AndroidLibrary)(nil) |
| 386 | |
| 387 | func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 388 | a.Module.deps(ctx) |
| 389 | if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 390 | a.aapt.deps(ctx, sdkContext(a)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
| 394 | func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 395 | a.aapt.isLibrary = true |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame] | 396 | a.aapt.buildActions(ctx, sdkContext(a)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 397 | |
| 398 | ctx.CheckbuildFile(a.proguardOptionsFile) |
| 399 | ctx.CheckbuildFile(a.exportPackage) |
| 400 | ctx.CheckbuildFile(a.aaptSrcJar) |
| 401 | |
| 402 | // apps manifests are handled by aapt, don't let Module see them |
| 403 | a.properties.Manifest = nil |
| 404 | |
| 405 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, |
| 406 | a.proguardOptionsFile) |
| 407 | |
| 408 | a.Module.compile(ctx, a.aaptSrcJar) |
| 409 | |
Colin Cross | f57c578 | 2019-01-25 13:20:38 -0800 | [diff] [blame] | 410 | a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 411 | var res android.Paths |
| 412 | if a.androidLibraryProperties.BuildAAR { |
| 413 | BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res) |
| 414 | ctx.CheckbuildFile(a.aarFile) |
| 415 | } |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 416 | |
| 417 | ctx.VisitDirectDeps(func(m android.Module) { |
| 418 | if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 419 | a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 420 | a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportPackage()) |
| 421 | a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportedStaticPackages()...) |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 422 | } |
| 423 | }) |
| 424 | |
| 425 | a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles) |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 426 | a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 429 | // android_library builds and links sources into a `.jar` file for the device along with Android resources. |
| 430 | // |
| 431 | // An android_library has a single variant that produces a `.jar` file containing `.class` files that were |
| 432 | // compiled against the device bootclasspath, along with a `package-res.apk` file containing Android resources compiled |
| 433 | // with aapt2. This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 434 | // an android_app module. |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 435 | func AndroidLibraryFactory() android.Module { |
| 436 | module := &AndroidLibrary{} |
| 437 | |
| 438 | module.AddProperties( |
| 439 | &module.Module.properties, |
| 440 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 441 | &module.Module.dexpreoptProperties, |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 442 | &module.Module.protoProperties, |
| 443 | &module.aaptProperties, |
| 444 | &module.androidLibraryProperties) |
| 445 | |
| 446 | module.androidLibraryProperties.BuildAAR = true |
| 447 | |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 448 | InitJavaModule(module, android.DeviceSupported) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 449 | return module |
| 450 | } |
| 451 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 452 | // |
| 453 | // AAR (android library) prebuilts |
| 454 | // |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 455 | |
| 456 | type AARImportProperties struct { |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 457 | Aars []string `android:"path"` |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 458 | |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 459 | Sdk_version *string |
| 460 | Min_sdk_version *string |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 461 | |
| 462 | Static_libs []string |
| 463 | Libs []string |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 464 | |
| 465 | // if set to true, run Jetifier against .aar file. Defaults to false. |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 466 | Jetifier *bool |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | type AARImport struct { |
| 470 | android.ModuleBase |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 471 | android.DefaultableModuleBase |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 472 | prebuilt android.Prebuilt |
| 473 | |
| 474 | properties AARImportProperties |
| 475 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 476 | classpathFile android.WritablePath |
| 477 | proguardFlags android.WritablePath |
| 478 | exportPackage android.WritablePath |
| 479 | extraAaptPackagesFile android.WritablePath |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 480 | manifest android.WritablePath |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 481 | |
| 482 | exportedStaticPackages android.Paths |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 483 | } |
| 484 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 485 | func (a *AARImport) sdkVersion() string { |
| 486 | return String(a.properties.Sdk_version) |
| 487 | } |
| 488 | |
| 489 | func (a *AARImport) minSdkVersion() string { |
Colin Cross | 479884c | 2018-07-10 13:39:30 -0700 | [diff] [blame] | 490 | if a.properties.Min_sdk_version != nil { |
| 491 | return *a.properties.Min_sdk_version |
| 492 | } |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 493 | return a.sdkVersion() |
| 494 | } |
| 495 | |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 496 | func (a *AARImport) targetSdkVersion() string { |
| 497 | return a.sdkVersion() |
| 498 | } |
| 499 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 500 | var _ AndroidLibraryDependency = (*AARImport)(nil) |
| 501 | |
| 502 | func (a *AARImport) ExportPackage() android.Path { |
| 503 | return a.exportPackage |
| 504 | } |
| 505 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 506 | func (a *AARImport) ExportedProguardFlagFiles() android.Paths { |
| 507 | return android.Paths{a.proguardFlags} |
| 508 | } |
| 509 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 510 | func (a *AARImport) ExportedRRODirs() []rroDir { |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 511 | return nil |
| 512 | } |
| 513 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 514 | func (a *AARImport) ExportedStaticPackages() android.Paths { |
| 515 | return a.exportedStaticPackages |
| 516 | } |
| 517 | |
Colin Cross | 90c25c6 | 2019-04-19 16:22:57 -0700 | [diff] [blame^] | 518 | func (a *AARImport) ExportedManifests() android.Paths { |
| 519 | return android.Paths{a.manifest} |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 522 | func (a *AARImport) Prebuilt() *android.Prebuilt { |
| 523 | return &a.prebuilt |
| 524 | } |
| 525 | |
| 526 | func (a *AARImport) Name() string { |
| 527 | return a.prebuilt.Name(a.ModuleBase.Name()) |
| 528 | } |
| 529 | |
| 530 | func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 531 | if !ctx.Config().UnbundledBuildUsePrebuiltSdks() { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 532 | sdkDep := decodeSdkDep(ctx, sdkContext(a)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 533 | if sdkDep.useModule && sdkDep.frameworkResModule != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 534 | ctx.AddVariationDependencies(nil, frameworkResTag, sdkDep.frameworkResModule) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 535 | } |
| 536 | } |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 537 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 538 | ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...) |
| 539 | ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // Unzip an AAR into its constituent files and directories. Any files in Outputs that don't exist in the AAR will be |
| 543 | // touched to create an empty file, and any directories in $expectedDirs will be created. |
| 544 | var unzipAAR = pctx.AndroidStaticRule("unzipAAR", |
| 545 | blueprint.RuleParams{ |
| 546 | Command: `rm -rf $outDir && mkdir -p $outDir $expectedDirs && ` + |
| 547 | `unzip -qo -d $outDir $in && touch $out`, |
| 548 | }, |
| 549 | "expectedDirs", "outDir") |
| 550 | |
| 551 | func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 552 | if len(a.properties.Aars) != 1 { |
| 553 | ctx.PropertyErrorf("aars", "exactly one aar is required") |
| 554 | return |
| 555 | } |
| 556 | |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 557 | aarName := ctx.ModuleName() + ".aar" |
| 558 | var aar android.Path |
| 559 | aar = android.PathForModuleSrc(ctx, a.properties.Aars[0]) |
Colin Cross | 1001a79 | 2019-03-21 22:21:39 -0700 | [diff] [blame] | 560 | if Bool(a.properties.Jetifier) { |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 561 | inputFile := aar |
| 562 | aar = android.PathForModuleOut(ctx, "jetifier", aarName) |
| 563 | TransformJetifier(ctx, aar.(android.WritablePath), inputFile) |
| 564 | } |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 565 | |
| 566 | extractedAARDir := android.PathForModuleOut(ctx, "aar") |
| 567 | extractedResDir := extractedAARDir.Join(ctx, "res") |
| 568 | a.classpathFile = extractedAARDir.Join(ctx, "classes.jar") |
| 569 | a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 570 | a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 571 | |
| 572 | ctx.Build(pctx, android.BuildParams{ |
| 573 | Rule: unzipAAR, |
| 574 | Input: aar, |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 575 | Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest}, |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 576 | Description: "unzip AAR", |
| 577 | Args: map[string]string{ |
| 578 | "expectedDirs": extractedResDir.String(), |
| 579 | "outDir": extractedAARDir.String(), |
| 580 | }, |
| 581 | }) |
| 582 | |
| 583 | compiledResDir := android.PathForModuleOut(ctx, "flat-res") |
| 584 | aaptCompileDeps := android.Paths{a.classpathFile} |
| 585 | aaptCompileDirs := android.Paths{extractedResDir} |
| 586 | flata := compiledResDir.Join(ctx, "gen_res.flata") |
| 587 | aapt2CompileDirs(ctx, flata, aaptCompileDirs, aaptCompileDeps) |
| 588 | |
| 589 | a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk") |
| 590 | srcJar := android.PathForModuleGen(ctx, "R.jar") |
| 591 | proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 592 | rTxt := android.PathForModuleOut(ctx, "R.txt") |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 593 | a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 594 | |
| 595 | var linkDeps android.Paths |
| 596 | |
| 597 | linkFlags := []string{ |
| 598 | "--static-lib", |
| 599 | "--no-static-lib-packages", |
| 600 | "--auto-add-overlay", |
| 601 | } |
| 602 | |
Colin Cross | 10f7c4a | 2018-05-23 10:59:28 -0700 | [diff] [blame] | 603 | linkFlags = append(linkFlags, "--manifest "+a.manifest.String()) |
| 604 | linkDeps = append(linkDeps, a.manifest) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 605 | |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 606 | transitiveStaticLibs, staticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext(a)) |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 607 | |
| 608 | _ = staticLibManifests |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 609 | _ = staticRRODirs |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 610 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 611 | linkDeps = append(linkDeps, libDeps...) |
| 612 | linkFlags = append(linkFlags, libFlags...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 613 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 614 | overlayRes := append(android.Paths{flata}, transitiveStaticLibs...) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 615 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 616 | aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile, |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 617 | linkFlags, linkDeps, nil, overlayRes, nil) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | var _ Dependency = (*AARImport)(nil) |
| 621 | |
| 622 | func (a *AARImport) HeaderJars() android.Paths { |
| 623 | return android.Paths{a.classpathFile} |
| 624 | } |
| 625 | |
| 626 | func (a *AARImport) ImplementationJars() android.Paths { |
| 627 | return android.Paths{a.classpathFile} |
| 628 | } |
| 629 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 630 | func (a *AARImport) ResourceJars() android.Paths { |
| 631 | return nil |
| 632 | } |
| 633 | |
| 634 | func (a *AARImport) ImplementationAndResourcesJars() android.Paths { |
| 635 | return android.Paths{a.classpathFile} |
| 636 | } |
| 637 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 638 | func (a *AARImport) DexJar() android.Path { |
| 639 | return nil |
| 640 | } |
| 641 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 642 | func (a *AARImport) AidlIncludeDirs() android.Paths { |
| 643 | return nil |
| 644 | } |
| 645 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 646 | func (a *AARImport) ExportedSdkLibs() []string { |
| 647 | return nil |
| 648 | } |
| 649 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 650 | var _ android.PrebuiltInterface = (*Import)(nil) |
| 651 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 652 | // android_library_import imports an `.aar` file into the build graph as if it was built with android_library. |
| 653 | // |
| 654 | // This module is not suitable for installing on a device, but can be used as a `static_libs` dependency of |
| 655 | // an android_app module. |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 656 | func AARImportFactory() android.Module { |
| 657 | module := &AARImport{} |
| 658 | |
| 659 | module.AddProperties(&module.properties) |
| 660 | |
| 661 | android.InitPrebuiltModule(module, &module.properties.Aars) |
Colin Cross | 48de9a4 | 2018-10-02 13:53:33 -0700 | [diff] [blame] | 662 | InitJavaModule(module, android.DeviceSupported) |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 663 | return module |
| 664 | } |