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 | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 20 | "path/filepath" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 25 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 26 | "android/soong/android" |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 27 | "android/soong/cc" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 28 | "android/soong/tradefed" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 29 | ) |
| 30 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 31 | func init() { |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 32 | android.RegisterModuleType("android_app", AndroidAppFactory) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 33 | android.RegisterModuleType("android_test", AndroidTestFactory) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 34 | android.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 35 | android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 36 | android.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 39 | // AndroidManifest.xml merging |
| 40 | // package splits |
| 41 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 42 | type appProperties struct { |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 43 | // 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] | 44 | Additional_certificates []string |
| 45 | |
| 46 | // If set, create package-export.apk, which other packages can |
| 47 | // use to get PRODUCT-agnostic resource data like IDs and type definitions. |
Nan Zhang | ea568a4 | 2017-11-08 21:20:04 -0800 | [diff] [blame] | 48 | Export_package_resources *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 49 | |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 50 | // Specifies that this app should be installed to the priv-app directory, |
| 51 | // where the system will grant it additional privileges not available to |
| 52 | // normal apps. |
| 53 | Privileged *bool |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 54 | |
| 55 | // list of resource labels to generate individual resource packages |
| 56 | Package_splits []string |
Jason Monk | d4122be | 2018-08-10 09:33:36 -0400 | [diff] [blame] | 57 | |
| 58 | // Names of modules to be overridden. Listed modules can only be other binaries |
| 59 | // (in Make or Soong). |
| 60 | // This does not completely prevent installation of the overridden binaries, but if both |
| 61 | // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed |
| 62 | // from PRODUCT_PACKAGES. |
| 63 | Overrides []string |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 64 | |
| 65 | // list of native libraries that will be provided in or alongside the resulting jar |
| 66 | Jni_libs []string `android:"arch_variant"` |
| 67 | |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 68 | // Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest |
| 69 | // flag so that they are used from inside the APK at runtime. Defaults to true for android_test modules unless |
| 70 | // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to false for other |
| 71 | // module types where the native libraries are generally preinstalled outside the APK. |
| 72 | Use_embedded_native_libs *bool |
Colin Cross | 46abdad | 2019-02-07 13:07:08 -0800 | [diff] [blame] | 73 | |
| 74 | // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that |
| 75 | // they are used from inside the APK at runtime. |
| 76 | Use_embedded_dex *bool |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 79 | // android_app properties that can be overridden by override_android_app |
| 80 | type overridableAppProperties struct { |
| 81 | // The name of a certificate in the default certificate directory, blank to use the default product certificate, |
| 82 | // or an android_app_certificate module name in the form ":module". |
| 83 | Certificate *string |
| 84 | } |
| 85 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 86 | type AndroidApp struct { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 87 | Library |
| 88 | aapt |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 89 | android.OverridableModuleBase |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 90 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 91 | certificate Certificate |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 92 | |
Colin Cross | fabb608 | 2018-02-20 17:22:23 -0800 | [diff] [blame] | 93 | appProperties appProperties |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 94 | |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 95 | overridableAppProperties overridableAppProperties |
| 96 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 97 | installJniLibs []jniLib |
Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 98 | |
| 99 | bundleFile android.Path |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 100 | |
| 101 | // the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES. |
| 102 | installApkName string |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 103 | |
| 104 | additionalAaptFlags []string |
Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 107 | func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths { |
| 108 | return nil |
| 109 | } |
| 110 | |
Colin Cross | 66f7882 | 2018-05-02 12:58:28 -0700 | [diff] [blame] | 111 | func (a *AndroidApp) ExportedStaticPackages() android.Paths { |
| 112 | return nil |
| 113 | } |
| 114 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 115 | var _ AndroidLibraryDependency = (*AndroidApp)(nil) |
| 116 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 117 | type Certificate struct { |
| 118 | Pem, Key android.Path |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 121 | func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 122 | a.Module.deps(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 123 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 124 | 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] | 125 | a.aapt.deps(ctx, sdkContext(a)) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 126 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 127 | |
| 128 | for _, jniTarget := range ctx.MultiTargets() { |
| 129 | variation := []blueprint.Variation{ |
| 130 | {Mutator: "arch", Variation: jniTarget.String()}, |
| 131 | {Mutator: "link", Variation: "shared"}, |
| 132 | } |
| 133 | tag := &jniDependencyTag{ |
| 134 | target: jniTarget, |
| 135 | } |
| 136 | ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...) |
| 137 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 138 | |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 139 | cert := android.SrcIsModule(a.getCertString(ctx)) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 140 | if cert != "" { |
| 141 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 142 | } |
| 143 | |
| 144 | for _, cert := range a.appProperties.Additional_certificates { |
| 145 | cert = android.SrcIsModule(cert) |
| 146 | if cert != "" { |
| 147 | ctx.AddDependency(ctx.Module(), certificateTag, cert) |
| 148 | } else { |
| 149 | ctx.PropertyErrorf("additional_certificates", |
| 150 | `must be names of android_app_certificate modules in the form ":module"`) |
| 151 | } |
| 152 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 155 | func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 156 | a.aapt.uncompressedJNI = a.shouldUncompressJNI(ctx) |
Colin Cross | 46abdad | 2019-02-07 13:07:08 -0800 | [diff] [blame] | 157 | a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 158 | a.generateAndroidBuildActions(ctx) |
| 159 | } |
| 160 | |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 161 | // shouldUncompressJNI returns true if the native libraries should be stored in the APK uncompressed and the |
| 162 | // extractNativeLibs application flag should be set to false in the manifest. |
| 163 | func (a *AndroidApp) shouldUncompressJNI(ctx android.ModuleContext) bool { |
| 164 | minSdkVersion, err := sdkVersionToNumber(ctx, a.minSdkVersion()) |
| 165 | if err != nil { |
| 166 | ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err) |
| 167 | } |
| 168 | |
| 169 | return minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs) |
| 170 | } |
| 171 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 172 | // Returns whether this module should have the dex file stored uncompressed in the APK. |
| 173 | func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { |
Colin Cross | 46abdad | 2019-02-07 13:07:08 -0800 | [diff] [blame] | 174 | if Bool(a.appProperties.Use_embedded_dex) { |
| 175 | return true |
| 176 | } |
| 177 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 178 | if ctx.Config().UnbundledBuild() { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 179 | return false |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 182 | // Uncompress dex in APKs of privileged apps, and modules used by privileged apps. |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 183 | if ctx.Config().UncompressPrivAppDex() && |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 184 | (Bool(a.appProperties.Privileged) || |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 185 | inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) { |
| 186 | return true |
| 187 | } |
| 188 | |
| 189 | // Uncompress if the dex files is preopted on /system. |
| 190 | if !a.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, a.dexpreopter.installPath)) { |
| 191 | return true |
| 192 | } |
| 193 | |
| 194 | return false |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 197 | func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { |
David Brazdil | d25060a | 2019-02-18 18:24:16 +0000 | [diff] [blame] | 198 | a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis) |
| 199 | |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 200 | aaptLinkFlags := []string{} |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 201 | |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 202 | // Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided. |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 203 | hasProduct := false |
| 204 | for _, f := range a.aaptProperties.Aaptflags { |
| 205 | if strings.HasPrefix(f, "--product") { |
| 206 | hasProduct = true |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 207 | break |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 210 | if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 { |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 211 | aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics()) |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 214 | if !Bool(a.aaptProperties.Aapt_include_all_resources) { |
| 215 | // Product AAPT config |
| 216 | for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 217 | aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig) |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 218 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 219 | |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 220 | // Product AAPT preferred config |
| 221 | if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 { |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 222 | aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig()) |
Dan Willemsen | 72be590 | 2018-10-24 20:24:57 -0700 | [diff] [blame] | 223 | } |
Colin Cross | e78dcd3 | 2018-04-19 15:25:19 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 226 | // TODO: LOCAL_PACKAGE_OVERRIDES |
| 227 | // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 228 | |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 229 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) |
| 230 | if overridden { |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 231 | aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName) |
Jiyong Park | 7f67f48 | 2019-01-05 12:57:48 +0900 | [diff] [blame] | 232 | } |
| 233 | |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 234 | aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...) |
| 235 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 236 | a.aapt.splitNames = a.appProperties.Package_splits |
| 237 | |
Jaewoong Jung | de4c02f | 2019-01-22 11:19:56 -0800 | [diff] [blame] | 238 | a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 239 | |
Colin Cross | 46c9b8b | 2017-06-22 16:51:17 -0700 | [diff] [blame] | 240 | // apps manifests are handled by aapt, don't let Module see them |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 241 | a.properties.Manifest = nil |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 242 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 243 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 244 | func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) { |
Colin Cross | 89c3158 | 2018-04-30 15:55:11 -0700 | [diff] [blame] | 245 | var staticLibProguardFlagFiles android.Paths |
| 246 | ctx.VisitDirectDeps(func(m android.Module) { |
| 247 | if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag { |
| 248 | staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...) |
| 249 | } |
| 250 | }) |
| 251 | |
| 252 | staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles) |
| 253 | |
| 254 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...) |
| 255 | a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile) |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 256 | } |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 257 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 258 | func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 259 | |
| 260 | var installDir string |
| 261 | if ctx.ModuleName() == "framework-res" { |
| 262 | // framework-res.apk is installed as system/framework/framework-res.apk |
| 263 | installDir = "framework" |
| 264 | } else if Bool(a.appProperties.Privileged) { |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 265 | installDir = filepath.Join("priv-app", a.installApkName) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 266 | } else { |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 267 | installDir = filepath.Join("app", a.installApkName) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 268 | } |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 269 | a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk") |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 270 | a.dexpreopter.isInstallable = Bool(a.properties.Installable) |
| 271 | a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx) |
| 272 | a.deviceProperties.UncompressDex = a.dexpreopter.uncompressedDex |
Colin Cross | 5a0dcd5 | 2018-10-05 14:20:06 -0700 | [diff] [blame] | 273 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 274 | if ctx.ModuleName() != "framework-res" { |
| 275 | a.Module.compile(ctx, a.aaptSrcJar) |
| 276 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 277 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 278 | return a.maybeStrippedDexJarFile |
| 279 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 280 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 281 | func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 282 | var jniJarFile android.WritablePath |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 283 | if len(jniLibs) > 0 { |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 284 | embedJni := ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 285 | if embedJni { |
| 286 | jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 287 | TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.shouldUncompressJNI(ctx)) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 288 | } else { |
| 289 | a.installJniLibs = jniLibs |
| 290 | } |
| 291 | } |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 292 | return jniJarFile |
| 293 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 294 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 295 | func (a *AndroidApp) certificateBuildActions(certificateDeps []Certificate, ctx android.ModuleContext) []Certificate { |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 296 | cert := a.getCertString(ctx) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 297 | certModule := android.SrcIsModule(cert) |
| 298 | if certModule != "" { |
| 299 | a.certificate = certificateDeps[0] |
| 300 | certificateDeps = certificateDeps[1:] |
| 301 | } else if cert != "" { |
| 302 | defaultDir := ctx.Config().DefaultAppCertificateDir(ctx) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 303 | a.certificate = Certificate{ |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 304 | defaultDir.Join(ctx, cert+".x509.pem"), |
| 305 | defaultDir.Join(ctx, cert+".pk8"), |
| 306 | } |
| 307 | } else { |
| 308 | pem, key := ctx.Config().DefaultAppCertificate(ctx) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 309 | a.certificate = Certificate{pem, key} |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Jeongik Cha | c946414 | 2019-01-07 12:07:27 +0900 | [diff] [blame] | 312 | if !a.Module.Platform() { |
| 313 | certPath := a.certificate.Pem.String() |
| 314 | systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String() |
| 315 | if strings.HasPrefix(certPath, systemCertPath) { |
| 316 | enforceSystemCert := ctx.Config().EnforceSystemCertificate() |
| 317 | whitelist := ctx.Config().EnforceSystemCertificateWhitelist() |
| 318 | |
| 319 | if enforceSystemCert && !inList(a.Module.Name(), whitelist) { |
| 320 | ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.") |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 325 | return append([]Certificate{a.certificate}, certificateDeps...) |
| 326 | } |
| 327 | |
| 328 | func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 329 | // Check if the install APK name needs to be overridden. |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 330 | a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Name()) |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 331 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 332 | // Process all building blocks, from AAPT to certificates. |
| 333 | a.aaptBuildActions(ctx) |
| 334 | |
| 335 | a.proguardBuildActions(ctx) |
| 336 | |
| 337 | dexJarFile := a.dexBuildActions(ctx) |
| 338 | |
| 339 | jniLibs, certificateDeps := a.collectAppDeps(ctx) |
| 340 | jniJarFile := a.jniBuildActions(jniLibs, ctx) |
| 341 | |
| 342 | if ctx.Failed() { |
| 343 | return |
| 344 | } |
| 345 | |
| 346 | certificates := a.certificateBuildActions(certificateDeps, ctx) |
| 347 | |
| 348 | // Build a final signed app package. |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 349 | // TODO(jungjw): Consider changing this to installApkName. |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 350 | packageFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".apk") |
| 351 | CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 352 | a.outputFile = packageFile |
| 353 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 354 | for _, split := range a.aapt.splits { |
| 355 | // Sign the split APKs |
| 356 | packageFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"_"+split.suffix+".apk") |
| 357 | CreateAppPackage(ctx, packageFile, split.path, nil, nil, certificates) |
| 358 | a.extraOutputFiles = append(a.extraOutputFiles, packageFile) |
| 359 | } |
| 360 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 361 | // Build an app bundle. |
Colin Cross | f623721 | 2018-10-29 23:14:58 -0700 | [diff] [blame] | 362 | bundleFile := android.PathForModuleOut(ctx, "base.zip") |
| 363 | BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile) |
| 364 | a.bundleFile = bundleFile |
| 365 | |
Jaewoong Jung | 590b1ae | 2019-01-22 16:40:58 -0800 | [diff] [blame] | 366 | // Install the app package. |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 367 | var installDir android.OutputPath |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 368 | if ctx.ModuleName() == "framework-res" { |
| 369 | // framework-res.apk is installed as system/framework/framework-res.apk |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 370 | installDir = android.PathForModuleInstall(ctx, "framework") |
Colin Cross | 1605606 | 2017-12-13 22:46:28 -0800 | [diff] [blame] | 371 | } else if Bool(a.appProperties.Privileged) { |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 372 | installDir = android.PathForModuleInstall(ctx, "priv-app", a.installApkName) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 373 | } else { |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 374 | installDir = android.PathForModuleInstall(ctx, "app", a.installApkName) |
| 375 | } |
| 376 | |
| 377 | ctx.InstallFile(installDir, a.installApkName+".apk", a.outputFile) |
| 378 | for _, split := range a.aapt.splits { |
| 379 | ctx.InstallFile(installDir, a.installApkName+"_"+split.suffix+".apk", split.path) |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 380 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 383 | func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) { |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 384 | var jniLibs []jniLib |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 385 | var certificates []Certificate |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 386 | |
| 387 | ctx.VisitDirectDeps(func(module android.Module) { |
| 388 | otherName := ctx.OtherModuleName(module) |
| 389 | tag := ctx.OtherModuleDependencyTag(module) |
| 390 | |
| 391 | if jniTag, ok := tag.(*jniDependencyTag); ok { |
| 392 | if dep, ok := module.(*cc.Module); ok { |
| 393 | lib := dep.OutputFile() |
| 394 | if lib.Valid() { |
| 395 | jniLibs = append(jniLibs, jniLib{ |
| 396 | name: ctx.OtherModuleName(module), |
| 397 | path: lib.Path(), |
| 398 | target: jniTag.target, |
| 399 | }) |
| 400 | } else { |
| 401 | ctx.ModuleErrorf("dependency %q missing output file", otherName) |
| 402 | } |
| 403 | } else { |
| 404 | ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName) |
| 405 | |
| 406 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 407 | } else if tag == certificateTag { |
| 408 | if dep, ok := module.(*AndroidAppCertificate); ok { |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 409 | certificates = append(certificates, dep.Certificate) |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 410 | } else { |
| 411 | ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName) |
| 412 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 413 | } |
| 414 | }) |
| 415 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 416 | return jniLibs, certificates |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 419 | func (a *AndroidApp) getCertString(ctx android.BaseContext) string { |
| 420 | certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName()) |
| 421 | if overridden { |
Jaewoong Jung | acb6db3 | 2019-02-28 16:22:30 +0000 | [diff] [blame] | 422 | return ":" + certificate |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 423 | } |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 424 | return String(a.overridableAppProperties.Certificate) |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 427 | // android_app compiles sources and Android resources into an Android application package `.apk` file. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 428 | func AndroidAppFactory() android.Module { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 429 | module := &AndroidApp{} |
| 430 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 431 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 432 | module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true) |
| 433 | |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 434 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 435 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 436 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 437 | module.AddProperties( |
Colin Cross | 540eff8 | 2017-06-22 17:01:52 -0700 | [diff] [blame] | 438 | &module.Module.properties, |
| 439 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 440 | &module.Module.dexpreoptProperties, |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 441 | &module.Module.protoProperties, |
| 442 | &module.aaptProperties, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 443 | &module.appProperties, |
| 444 | &module.overridableAppProperties) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 445 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 446 | module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
| 447 | return class == android.Device && ctx.Config().DevicePrefer32BitApps() |
| 448 | }) |
| 449 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 450 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 451 | android.InitDefaultableModule(module) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 452 | android.InitOverridableModule(module, &module.appProperties.Overrides) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 453 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 454 | return module |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 455 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 456 | |
| 457 | type appTestProperties struct { |
| 458 | Instrumentation_for *string |
| 459 | } |
| 460 | |
| 461 | type AndroidTest struct { |
| 462 | AndroidApp |
| 463 | |
| 464 | appTestProperties appTestProperties |
| 465 | |
| 466 | testProperties testProperties |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 467 | |
| 468 | testConfig android.Path |
Colin Cross | d96ca35 | 2018-08-10 16:06:24 -0700 | [diff] [blame] | 469 | data android.Paths |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 473 | // Check if the instrumentation target package is overridden before generating build actions. |
| 474 | if a.appTestProperties.Instrumentation_for != nil { |
| 475 | manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(*a.appTestProperties.Instrumentation_for) |
| 476 | if overridden { |
| 477 | a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName) |
| 478 | } |
| 479 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 480 | a.generateAndroidBuildActions(ctx) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 481 | |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 482 | a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 483 | a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) { |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 487 | a.AndroidApp.DepsMutator(ctx) |
Colin Cross | 4b964c0 | 2018-10-15 16:18:06 -0700 | [diff] [blame] | 488 | if a.appTestProperties.Instrumentation_for != nil { |
| 489 | // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac, |
| 490 | // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so |
| 491 | // use instrumentationForTag instead of libTag. |
| 492 | ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for)) |
| 493 | } |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 496 | // android_test compiles test sources and Android resources into an Android application package `.apk` file and |
| 497 | // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file. |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 498 | func AndroidTestFactory() android.Module { |
| 499 | module := &AndroidTest{} |
| 500 | |
| 501 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
Colin Cross | 5067db9 | 2018-09-17 16:46:35 -0700 | [diff] [blame] | 502 | |
| 503 | module.Module.properties.Instrument = true |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 504 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 505 | module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 506 | module.Module.dexpreopter.isTest = true |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 507 | |
| 508 | module.AddProperties( |
| 509 | &module.Module.properties, |
| 510 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 511 | &module.Module.dexpreoptProperties, |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 512 | &module.Module.protoProperties, |
| 513 | &module.aaptProperties, |
| 514 | &module.appProperties, |
Dan Willemsen | f5531d2 | 2018-07-16 17:21:19 -0700 | [diff] [blame] | 515 | &module.appTestProperties, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 516 | &module.overridableAppProperties, |
Dan Willemsen | f5531d2 | 2018-07-16 17:21:19 -0700 | [diff] [blame] | 517 | &module.testProperties) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 518 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 519 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 520 | android.InitDefaultableModule(module) |
Colin Cross | ae5caf5 | 2018-05-22 11:11:52 -0700 | [diff] [blame] | 521 | return module |
| 522 | } |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 523 | |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 524 | type appTestHelperAppProperties struct { |
| 525 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 526 | // installed into. |
| 527 | Test_suites []string `android:"arch_variant"` |
| 528 | } |
| 529 | |
| 530 | type AndroidTestHelperApp struct { |
| 531 | AndroidApp |
| 532 | |
| 533 | appTestHelperAppProperties appTestHelperAppProperties |
| 534 | } |
| 535 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 536 | // android_test_helper_app compiles sources and Android resources into an Android application package `.apk` file that |
| 537 | // will be used by tests, but does not produce an `AndroidTest.xml` file so the module will not be run directly as a |
| 538 | // test. |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 539 | func AndroidTestHelperAppFactory() android.Module { |
| 540 | module := &AndroidTestHelperApp{} |
| 541 | |
| 542 | module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true) |
| 543 | |
| 544 | module.Module.properties.Installable = proptools.BoolPtr(true) |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 545 | module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 546 | module.Module.dexpreopter.isTest = true |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 547 | |
| 548 | module.AddProperties( |
| 549 | &module.Module.properties, |
| 550 | &module.Module.deviceProperties, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 551 | &module.Module.dexpreoptProperties, |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 552 | &module.Module.protoProperties, |
| 553 | &module.aaptProperties, |
| 554 | &module.appProperties, |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 555 | &module.appTestHelperAppProperties, |
| 556 | &module.overridableAppProperties) |
Colin Cross | 252fc6f | 2018-10-04 15:22:03 -0700 | [diff] [blame] | 557 | |
| 558 | android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 559 | android.InitDefaultableModule(module) |
| 560 | return module |
| 561 | } |
| 562 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 563 | type AndroidAppCertificate struct { |
| 564 | android.ModuleBase |
| 565 | properties AndroidAppCertificateProperties |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 566 | Certificate Certificate |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | type AndroidAppCertificateProperties struct { |
| 570 | // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name. |
| 571 | Certificate *string |
| 572 | } |
| 573 | |
Colin Cross | 1b16b0e | 2019-02-12 14:41:32 -0800 | [diff] [blame] | 574 | // android_app_certificate modules can be referenced by the certificates property of android_app modules to select |
| 575 | // the signing key. |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 576 | func AndroidAppCertificateFactory() android.Module { |
| 577 | module := &AndroidAppCertificate{} |
| 578 | module.AddProperties(&module.properties) |
| 579 | android.InitAndroidModule(module) |
| 580 | return module |
| 581 | } |
| 582 | |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 583 | func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 584 | cert := String(c.properties.Certificate) |
Jiyong Park | c00cbd9 | 2018-10-30 21:20:05 +0900 | [diff] [blame] | 585 | c.Certificate = Certificate{ |
Colin Cross | bd01e2a | 2018-10-04 15:21:03 -0700 | [diff] [blame] | 586 | android.PathForModuleSrc(ctx, cert+".x509.pem"), |
| 587 | android.PathForModuleSrc(ctx, cert+".pk8"), |
| 588 | } |
| 589 | } |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 590 | |
| 591 | type OverrideAndroidApp struct { |
| 592 | android.ModuleBase |
| 593 | android.OverrideModuleBase |
| 594 | } |
| 595 | |
| 596 | func (i *OverrideAndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 597 | // All the overrides happen in the base module. |
| 598 | // TODO(jungjw): Check the base module type. |
| 599 | } |
| 600 | |
| 601 | // override_android_app is used to create an android_app module based on another android_app by overriding |
| 602 | // some of its properties. |
| 603 | func OverrideAndroidAppModuleFactory() android.Module { |
| 604 | m := &OverrideAndroidApp{} |
| 605 | m.AddProperties(&overridableAppProperties{}) |
| 606 | |
| 607 | android.InitAndroidModule(m) |
| 608 | android.InitOverrideModule(m) |
| 609 | return m |
| 610 | } |