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