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