Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | // This file contains the module types for compiling Android apps. |
| 18 | |
| 19 | import ( |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 24 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 25 | "android/soong/android" |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 26 | "android/soong/cc" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 27 | "android/soong/tradefed" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 30 | func init() { |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 31 | android.RegisterModuleType("android_app", AndroidAppFactory) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 32 | android.RegisterModuleType("android_test", AndroidTestFactory) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 33 | android.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 34 | android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 37 | // AndroidManifest.xml merging |
| 38 | // package splits |
| 39 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 40 | type appProperties struct { |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 41 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 42 | // or an android_app_certificate module name in the form ":module". |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 43 | Certificate *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 44 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 45 | // Names of extra android_app_certificate modules to sign the apk with in the form ":module". |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 46 | Additional_certificates []string |
| 47 | |
| 48 | // If set, create package-export.apk, which other packages can |
| 49 | // use to get PRODUCT-agnostic resource data like IDs and type definitions. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 50 | Export_package_resources *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 51 | |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 52 | // Specifies that this app should be installed to the priv-app directory, |
| 53 | // where the system will grant it additional privileges not available to |
| 54 | // normal apps. |
| 55 | Privileged *bool |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 56 | |
| 57 | // list of resource labels to generate individual resource packages |
| 58 | Package_splits []string |
Jason Monk | d4122be | 2018-08-10 09:33:36 -0400 | [diff] [blame] | 59 | |
| 60 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 61 | // (in Make or Soong). |
| 62 | // This does not completely prevent installation of the overridden binaries, but if both |
| 63 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 64 | // from PRODUCT_PACKAGES. |
| 65 | Overrides []string |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 66 | |
| 67 | // list of native libraries that will be provided in or alongside the resulting jar |
| 68 | Jni_libs []string `android:"arch_variant"` |
| 69 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 70 | AllowDexPreopt bool `blueprint:"mutated"` |
| 71 | EmbedJNI bool `blueprint:"mutated"` |
| 72 | StripDex bool `blueprint:"mutated"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 75 | type AndroidApp struct { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 76 | Library |
| 77 | aapt |
| 78 | |
| 79 | certificate certificate |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 80 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 81 | appProperties appProperties |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 82 | |
| 83 | extraLinkFlags []string |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 84 | |
| 85 | installJniLibs []jniLib |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 88 | func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths { |
| 89 | return nil |
| 90 | } |
| 91 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 92 | func (a *AndroidApp) ExportedStaticPackages() android.Paths { |
| 93 | return nil |
| 94 | } |
| 95 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 96 | func (a *AndroidApp) ExportedManifest() android.Path { |
| 97 | return a.manifestPath |
| 98 | } |
| 99 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 100 | var _ AndroidLibraryDependency = (*AndroidApp)(nil) |
| 101 | |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 102 | type certificate struct { |
| 103 | pem, key android.Path |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 106 | func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 107 | a.Module.deps(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 108 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 109 | 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] | 110 | a.aapt.deps(ctx, sdkContext(a)) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 111 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 112 | |
| 113 | for _, jniTarget := range ctx.MultiTargets() { |
| 114 | variation := []blueprint.Variation{ |
| 115 | {Mutator: "arch", Variation: jniTarget.String()}, |
| 116 | {Mutator: "link", Variation: "shared"}, |
| 117 | } |
| 118 | tag := &jniDependencyTag{ |
| 119 | target: jniTarget, |
| 120 | } |
| 121 | ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...) |
| 122 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 123 | |
| 124 | cert := android.SrcIsModule(String(a.appProperties.Certificate)) |
| 125 | if cert != "" { |
| 126 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 127 | } |
| 128 | |
| 129 | for _, cert := range a.appProperties.Additional_certificates { |
| 130 | cert = android.SrcIsModule(cert) |
| 131 | if cert != "" { |
| 132 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 133 | } else { |
| 134 | ctx.PropertyErrorf("additional_certificates", |
| 135 | `must be names of android_app_certificate modules in the form ":module"`) |
| 136 | } |
| 137 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 140 | func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 141 | a.generateAndroidBuildActions(ctx) |
| 142 | } |
| 143 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 144 | // Returns whether this module should have the dex file stored uncompressed in the APK, or stripped completely. If |
| 145 | // stripped, the code will still be present on the device in the dexpreopted files. |
| 146 | // This is only necessary for APKs, and not jars, because APKs are signed and the dex file should not be uncompressed |
| 147 | // or removed after the signature has been generated. For jars, which are not signed, the dex file is uncompressed |
| 148 | // or removed at installation time in Make. |
| 149 | func (a *AndroidApp) uncompressOrStripDex(ctx android.ModuleContext) (uncompress, strip bool) { |
| 150 | if ctx.Config().UnbundledBuild() { |
| 151 | return false, false |
| 152 | } |
| 153 | |
| 154 | strip = ctx.Config().DefaultStripDex() |
| 155 | // TODO(ccross): don't strip dex installed on partitions that may be updated separately (like vendor) |
| 156 | // TODO(ccross): don't strip dex on modules with LOCAL_APK_LIBRARIES equivalent |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 157 | |
| 158 | // Uncompress dex in APKs of privileged apps, and modules used by privileged apps. |
| 159 | if ctx.Config().UncompressPrivAppDex() && |
| 160 | (Bool(a.appProperties.Privileged) || |
| 161 | inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) { |
| 162 | |
| 163 | uncompress = true |
| 164 | // If the dex files is store uncompressed, don't strip it, we will reuse the uncompressed dex from the APK |
| 165 | // instead of copying it into the odex file. |
| 166 | strip = false |
| 167 | } |
| 168 | |
| 169 | // If dexpreopt is disabled, don't strip the dex file |
| 170 | if !a.appProperties.AllowDexPreopt || |
| 171 | !BoolDefault(a.deviceProperties.Dex_preopt.Enabled, true) || |
| 172 | ctx.Config().DisableDexPreopt(ctx.ModuleName()) { |
| 173 | strip = false |
| 174 | } |
| 175 | |
Colin Cross | 762fbfb | 2018-10-29 12:58:06 -0700 | [diff] [blame] | 176 | // TODO(ccross): strip dexpropted modules that are not propted to system_other |
| 177 | strip = false |
| 178 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 179 | return uncompress, strip |
| 180 | } |
| 181 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 182 | func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { |
| 183 | linkFlags := append([]string(nil), a.extraLinkFlags...) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 184 | |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 185 | hasProduct := false |
| 186 | for _, f := range a.aaptProperties.Aaptflags { |
| 187 | if strings.HasPrefix(f, "--product") { |
| 188 | hasProduct = true |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // Product characteristics |
| 193 | if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 { |
| 194 | linkFlags = append(linkFlags, "--product", ctx.Config().ProductAAPTCharacteristics()) |
| 195 | } |
| 196 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame^] | 197 | if !Bool(a.aaptProperties.Aapt_include_all_resources) { |
| 198 | // Product AAPT config |
| 199 | for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { |
| 200 | linkFlags = append(linkFlags, "-c", aaptConfig) |
| 201 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 202 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame^] | 203 | // Product AAPT preferred config |
| 204 | if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 { |
| 205 | linkFlags = append(linkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig()) |
| 206 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 209 | // TODO: LOCAL_PACKAGE_OVERRIDES |
| 210 | // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 211 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 212 | a.aapt.buildActions(ctx, sdkContext(a), linkFlags...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 213 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 214 | // apps manifests are handled by aapt, don't let Module see them |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 215 | a.properties.Manifest = nil |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 216 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 217 | var staticLibProguardFlagFiles android.Paths |
| 218 | ctx.VisitDirectDeps(func(m android.Module) { |
| 219 | if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 220 | staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
| 221 | } |
| 222 | }) |
| 223 | |
| 224 | staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles) |
| 225 | |
| 226 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...) |
| 227 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile) |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 228 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 229 | a.deviceProperties.UncompressDex, a.appProperties.StripDex = a.uncompressOrStripDex(ctx) |
| 230 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 231 | if ctx.ModuleName() != "framework-res" { |
| 232 | a.Module.compile(ctx, a.aaptSrcJar) |
| 233 | } |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 234 | dexJarFile := a.dexJarFile |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 235 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 236 | if a.appProperties.StripDex { |
| 237 | dexJarFile = nil |
| 238 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 239 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 240 | var certificates []certificate |
| 241 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 242 | var jniJarFile android.WritablePath |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 243 | jniLibs, certificateDeps := a.collectAppDeps(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 244 | if len(jniLibs) > 0 { |
| 245 | embedJni := ctx.Config().UnbundledBuild() || a.appProperties.EmbedJNI |
| 246 | if embedJni { |
| 247 | jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") |
| 248 | TransformJniLibsToJar(ctx, jniJarFile, jniLibs) |
| 249 | } else { |
| 250 | a.installJniLibs = jniLibs |
| 251 | } |
| 252 | } |
| 253 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 254 | if ctx.Failed() { |
| 255 | return |
| 256 | } |
| 257 | |
| 258 | cert := String(a.appProperties.Certificate) |
| 259 | certModule := android.SrcIsModule(cert) |
| 260 | if certModule != "" { |
| 261 | a.certificate = certificateDeps[0] |
| 262 | certificateDeps = certificateDeps[1:] |
| 263 | } else if cert != "" { |
| 264 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
| 265 | a.certificate = certificate{ |
| 266 | defaultDir.Join(ctx, cert+".x509.pem"), |
| 267 | defaultDir.Join(ctx, cert+".pk8"), |
| 268 | } |
| 269 | } else { |
| 270 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
| 271 | a.certificate = certificate{pem, key} |
| 272 | } |
| 273 | |
| 274 | certificates = append([]certificate{a.certificate}, certificateDeps...) |
| 275 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 276 | packageFile := android.PathForModuleOut(ctx, "package.apk") |
| 277 | CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 278 | a.outputFile = packageFile |
| 279 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 280 | if ctx.ModuleName() == "framework-res" { |
| 281 | // framework-res.apk is installed as system/framework/framework-res.apk |
| 282 | ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile) |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 283 | } else if Bool(a.appProperties.Privileged) { |
| 284 | ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app"), ctx.ModuleName()+".apk", a.outputFile) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 285 | } else { |
| 286 | ctx.InstallFile(android.PathForModuleInstall(ctx, "app"), ctx.ModuleName()+".apk", a.outputFile) |
| 287 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 290 | func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []certificate) { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 291 | var jniLibs []jniLib |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 292 | var certificates []certificate |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 293 | |
| 294 | ctx.VisitDirectDeps(func(module android.Module) { |
| 295 | otherName := ctx.OtherModuleName(module) |
| 296 | tag := ctx.OtherModuleDependencyTag(module) |
| 297 | |
| 298 | if jniTag, ok := tag.(*jniDependencyTag); ok { |
| 299 | if dep, ok := module.(*cc.Module); ok { |
| 300 | lib := dep.OutputFile() |
| 301 | if lib.Valid() { |
| 302 | jniLibs = append(jniLibs, jniLib{ |
| 303 | name: ctx.OtherModuleName(module), |
| 304 | path: lib.Path(), |
| 305 | target: jniTag.target, |
| 306 | }) |
| 307 | } else { |
| 308 | ctx.ModuleErrorf("dependency %q missing output file", otherName) |
| 309 | } |
| 310 | } else { |
| 311 | ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName) |
| 312 | |
| 313 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 314 | } else if tag == certificateTag { |
| 315 | if dep, ok := module.(*AndroidAppCertificate); ok { |
| 316 | certificates = append(certificates, dep.certificate) |
| 317 | } else { |
| 318 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName) |
| 319 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 320 | } |
| 321 | }) |
| 322 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 323 | return jniLibs, certificates |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 326 | func AndroidAppFactory() android.Module { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 327 | module := &AndroidApp{} |
| 328 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 329 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 330 | module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true) |
| 331 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 332 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 333 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 334 | module.appProperties.AllowDexPreopt = true |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 335 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 336 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 337 | &module.Module.properties, |
| 338 | &module.Module.deviceProperties, |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 339 | &module.Module.protoProperties, |
| 340 | &module.aaptProperties, |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 341 | &module.appProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 342 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 343 | module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
| 344 | return class == android.Device && ctx.Config().DevicePrefer32BitApps() |
| 345 | }) |
| 346 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 347 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 348 | android.InitDefaultableModule(module) |
| 349 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 350 | return module |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 351 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 352 | |
| 353 | type appTestProperties struct { |
| 354 | Instrumentation_for *string |
| 355 | } |
| 356 | |
| 357 | type AndroidTest struct { |
| 358 | AndroidApp |
| 359 | |
| 360 | appTestProperties appTestProperties |
| 361 | |
| 362 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 363 | |
| 364 | testConfig android.Path |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 365 | data android.Paths |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 369 | a.generateAndroidBuildActions(ctx) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 370 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 371 | a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath) |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 372 | a.data = ctx.ExpandSources(a.testProperties.Data, nil) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 376 | android.ExtractSourceDeps(ctx, a.testProperties.Test_config) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 377 | android.ExtractSourceDeps(ctx, a.testProperties.Test_config_template) |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 378 | android.ExtractSourcesDeps(ctx, a.testProperties.Data) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 379 | a.AndroidApp.DepsMutator(ctx) |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 380 | if a.appTestProperties.Instrumentation_for != nil { |
| 381 | // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac, |
| 382 | // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so |
| 383 | // use instrumentationForTag instead of libTag. |
| 384 | ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for)) |
| 385 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | func AndroidTestFactory() android.Module { |
| 389 | module := &AndroidTest{} |
| 390 | |
| 391 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
Colin Cross | 5067db9 | 2018-09-17 16:46:35 -0700 | [diff] [blame] | 392 | |
| 393 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 394 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 395 | module.appProperties.EmbedJNI = true |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 396 | module.appProperties.AllowDexPreopt = false |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 397 | |
| 398 | module.AddProperties( |
| 399 | &module.Module.properties, |
| 400 | &module.Module.deviceProperties, |
| 401 | &module.Module.protoProperties, |
| 402 | &module.aaptProperties, |
| 403 | &module.appProperties, |
Dan Willemsen | f5531d2 | 2018-07-16 17:21:19 -0700 | [diff] [blame] | 404 | &module.appTestProperties, |
| 405 | &module.testProperties) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 406 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 407 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 408 | android.InitDefaultableModule(module) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 409 | return module |
| 410 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 411 | |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 412 | type appTestHelperAppProperties struct { |
| 413 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 414 | // installed into. |
| 415 | Test_suites []string `android:"arch_variant"` |
| 416 | } |
| 417 | |
| 418 | type AndroidTestHelperApp struct { |
| 419 | AndroidApp |
| 420 | |
| 421 | appTestHelperAppProperties appTestHelperAppProperties |
| 422 | } |
| 423 | |
| 424 | func AndroidTestHelperAppFactory() android.Module { |
| 425 | module := &AndroidTestHelperApp{} |
| 426 | |
| 427 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 428 | |
| 429 | module.Module.properties.Installable = proptools.BoolPtr(true) |
| 430 | module.appProperties.EmbedJNI = true |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 431 | module.appProperties.AllowDexPreopt = false |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 432 | |
| 433 | module.AddProperties( |
| 434 | &module.Module.properties, |
| 435 | &module.Module.deviceProperties, |
| 436 | &module.Module.protoProperties, |
| 437 | &module.aaptProperties, |
| 438 | &module.appProperties, |
| 439 | &module.appTestHelperAppProperties) |
| 440 | |
| 441 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 442 | android.InitDefaultableModule(module) |
| 443 | return module |
| 444 | } |
| 445 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 446 | type AndroidAppCertificate struct { |
| 447 | android.ModuleBase |
| 448 | properties AndroidAppCertificateProperties |
| 449 | certificate certificate |
| 450 | } |
| 451 | |
| 452 | type AndroidAppCertificateProperties struct { |
| 453 | // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name. |
| 454 | Certificate *string |
| 455 | } |
| 456 | |
| 457 | func AndroidAppCertificateFactory() android.Module { |
| 458 | module := &AndroidAppCertificate{} |
| 459 | module.AddProperties(&module.properties) |
| 460 | android.InitAndroidModule(module) |
| 461 | return module |
| 462 | } |
| 463 | |
| 464 | func (c *AndroidAppCertificate) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 465 | } |
| 466 | |
| 467 | func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 468 | cert := String(c.properties.Certificate) |
| 469 | c.certificate = certificate{ |
| 470 | android.PathForModuleSrc(ctx, cert+".x509.pem"), |
| 471 | android.PathForModuleSrc(ctx, cert+".pk8"), |
| 472 | } |
| 473 | } |