blob: 392ad3fc8f4a495671b91c7ca2c48eb342804810 [file] [log] [blame]
Colin Cross30e076a2015-04-13 13:58:27 -07001// 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
15package java
16
17// This file contains the module types for compiling Android apps.
18
19import (
Colin Cross30e076a2015-04-13 13:58:27 -070020 "strings"
21
Colin Crossa4f08812018-10-02 22:03:40 -070022 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070023 "github.com/google/blueprint/proptools"
Colin Cross30e076a2015-04-13 13:58:27 -070024
Colin Cross635c3b02016-05-18 15:37:25 -070025 "android/soong/android"
Colin Crossa4f08812018-10-02 22:03:40 -070026 "android/soong/cc"
Colin Cross303e21f2018-08-07 16:49:25 -070027 "android/soong/tradefed"
Colin Cross30e076a2015-04-13 13:58:27 -070028)
29
Colin Cross3bc7ffa2017-11-22 16:19:37 -080030func init() {
Colin Cross5ab4e6d2017-11-22 16:20:45 -080031 android.RegisterModuleType("android_app", AndroidAppFactory)
Colin Crossae5caf52018-05-22 11:11:52 -070032 android.RegisterModuleType("android_test", AndroidTestFactory)
Colin Cross252fc6f2018-10-04 15:22:03 -070033 android.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory)
Colin Crossbd01e2a2018-10-04 15:21:03 -070034 android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
Colin Cross3bc7ffa2017-11-22 16:19:37 -080035}
36
Colin Cross30e076a2015-04-13 13:58:27 -070037// AndroidManifest.xml merging
38// package splits
39
Colin Crossfabb6082018-02-20 17:22:23 -080040type appProperties struct {
Colin Crossbd01e2a2018-10-04 15:21:03 -070041 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
42 // or an android_app_certificate module name in the form ":module".
Nan Zhangea568a42017-11-08 21:20:04 -080043 Certificate *string
Colin Cross7d5136f2015-05-11 13:39:40 -070044
Colin Crossbd01e2a2018-10-04 15:21:03 -070045 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
Colin Cross7d5136f2015-05-11 13:39:40 -070046 Additional_certificates []string
47
48 // If set, create package-export.apk, which other packages can
49 // use to get PRODUCT-agnostic resource data like IDs and type definitions.
Nan Zhangea568a42017-11-08 21:20:04 -080050 Export_package_resources *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070051
Colin Cross16056062017-12-13 22:46:28 -080052 // Specifies that this app should be installed to the priv-app directory,
53 // where the system will grant it additional privileges not available to
54 // normal apps.
55 Privileged *bool
Colin Crossa97c5d32018-03-28 14:58:31 -070056
57 // list of resource labels to generate individual resource packages
58 Package_splits []string
Jason Monkd4122be2018-08-10 09:33:36 -040059
60 // Names of modules to be overridden. Listed modules can only be other binaries
61 // (in Make or Soong).
62 // This does not completely prevent installation of the overridden binaries, but if both
63 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
64 // from PRODUCT_PACKAGES.
65 Overrides []string
Colin Crossa4f08812018-10-02 22:03:40 -070066
67 // list of native libraries that will be provided in or alongside the resulting jar
68 Jni_libs []string `android:"arch_variant"`
69
Colin Cross5a0dcd52018-10-05 14:20:06 -070070 AllowDexPreopt bool `blueprint:"mutated"`
71 EmbedJNI bool `blueprint:"mutated"`
72 StripDex bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -070073}
74
Colin Cross30e076a2015-04-13 13:58:27 -070075type AndroidApp struct {
Colin Crossa97c5d32018-03-28 14:58:31 -070076 Library
77 aapt
78
Jiyong Parkc00cbd92018-10-30 21:20:05 +090079 certificate Certificate
Colin Cross30e076a2015-04-13 13:58:27 -070080
Colin Crossfabb6082018-02-20 17:22:23 -080081 appProperties appProperties
Colin Crossae5caf52018-05-22 11:11:52 -070082
83 extraLinkFlags []string
Colin Crossa4f08812018-10-02 22:03:40 -070084
85 installJniLibs []jniLib
Colin Crossf6237212018-10-29 23:14:58 -070086
87 bundleFile android.Path
Colin Crosse1731a52017-12-14 11:22:55 -080088}
89
Colin Cross89c31582018-04-30 15:55:11 -070090func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
91 return nil
92}
93
Colin Cross66f78822018-05-02 12:58:28 -070094func (a *AndroidApp) ExportedStaticPackages() android.Paths {
95 return nil
96}
97
Colin Cross31656952018-05-24 16:11:20 -070098func (a *AndroidApp) ExportedManifest() android.Path {
99 return a.manifestPath
100}
101
Colin Crossa97c5d32018-03-28 14:58:31 -0700102var _ AndroidLibraryDependency = (*AndroidApp)(nil)
103
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900104type Certificate struct {
105 Pem, Key android.Path
Colin Cross30e076a2015-04-13 13:58:27 -0700106}
107
Colin Cross46c9b8b2017-06-22 16:51:17 -0700108func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
109 a.Module.deps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700110
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800111 if !Bool(a.properties.No_framework_libs) && !Bool(a.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700112 a.aapt.deps(ctx, sdkContext(a))
Colin Cross30e076a2015-04-13 13:58:27 -0700113 }
Colin Crossa4f08812018-10-02 22:03:40 -0700114
115 for _, jniTarget := range ctx.MultiTargets() {
116 variation := []blueprint.Variation{
117 {Mutator: "arch", Variation: jniTarget.String()},
118 {Mutator: "link", Variation: "shared"},
119 }
120 tag := &jniDependencyTag{
121 target: jniTarget,
122 }
123 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
124 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700125
126 cert := android.SrcIsModule(String(a.appProperties.Certificate))
127 if cert != "" {
128 ctx.AddDependency(ctx.Module(), certificateTag, cert)
129 }
130
131 for _, cert := range a.appProperties.Additional_certificates {
132 cert = android.SrcIsModule(cert)
133 if cert != "" {
134 ctx.AddDependency(ctx.Module(), certificateTag, cert)
135 } else {
136 ctx.PropertyErrorf("additional_certificates",
137 `must be names of android_app_certificate modules in the form ":module"`)
138 }
139 }
Colin Cross30e076a2015-04-13 13:58:27 -0700140}
141
Colin Cross46c9b8b2017-06-22 16:51:17 -0700142func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossae5caf52018-05-22 11:11:52 -0700143 a.generateAndroidBuildActions(ctx)
144}
145
Colin Cross5a0dcd52018-10-05 14:20:06 -0700146// Returns whether this module should have the dex file stored uncompressed in the APK, or stripped completely. If
147// stripped, the code will still be present on the device in the dexpreopted files.
148// This is only necessary for APKs, and not jars, because APKs are signed and the dex file should not be uncompressed
149// or removed after the signature has been generated. For jars, which are not signed, the dex file is uncompressed
150// or removed at installation time in Make.
151func (a *AndroidApp) uncompressOrStripDex(ctx android.ModuleContext) (uncompress, strip bool) {
152 if ctx.Config().UnbundledBuild() {
153 return false, false
154 }
155
156 strip = ctx.Config().DefaultStripDex()
157 // TODO(ccross): don't strip dex installed on partitions that may be updated separately (like vendor)
158 // TODO(ccross): don't strip dex on modules with LOCAL_APK_LIBRARIES equivalent
Colin Cross5a0dcd52018-10-05 14:20:06 -0700159
160 // Uncompress dex in APKs of privileged apps, and modules used by privileged apps.
161 if ctx.Config().UncompressPrivAppDex() &&
162 (Bool(a.appProperties.Privileged) ||
163 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) {
164
165 uncompress = true
166 // If the dex files is store uncompressed, don't strip it, we will reuse the uncompressed dex from the APK
167 // instead of copying it into the odex file.
168 strip = false
169 }
170
171 // If dexpreopt is disabled, don't strip the dex file
172 if !a.appProperties.AllowDexPreopt ||
173 !BoolDefault(a.deviceProperties.Dex_preopt.Enabled, true) ||
174 ctx.Config().DisableDexPreopt(ctx.ModuleName()) {
175 strip = false
176 }
177
Colin Cross762fbfb2018-10-29 12:58:06 -0700178 // TODO(ccross): strip dexpropted modules that are not propted to system_other
179 strip = false
180
Colin Cross5a0dcd52018-10-05 14:20:06 -0700181 return uncompress, strip
182}
183
Colin Crossae5caf52018-05-22 11:11:52 -0700184func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
185 linkFlags := append([]string(nil), a.extraLinkFlags...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800186
Colin Crosse78dcd32018-04-19 15:25:19 -0700187 hasProduct := false
188 for _, f := range a.aaptProperties.Aaptflags {
189 if strings.HasPrefix(f, "--product") {
190 hasProduct = true
191 }
192 }
193
194 // Product characteristics
195 if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
196 linkFlags = append(linkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
197 }
198
Dan Willemsen72be5902018-10-24 20:24:57 -0700199 if !Bool(a.aaptProperties.Aapt_include_all_resources) {
200 // Product AAPT config
201 for _, aaptConfig := range ctx.Config().ProductAAPTConfig() {
202 linkFlags = append(linkFlags, "-c", aaptConfig)
203 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700204
Dan Willemsen72be5902018-10-24 20:24:57 -0700205 // Product AAPT preferred config
206 if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 {
207 linkFlags = append(linkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig())
208 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700209 }
210
Colin Crossa97c5d32018-03-28 14:58:31 -0700211 // TODO: LOCAL_PACKAGE_OVERRIDES
212 // $(addprefix --rename-manifest-package , $(PRIVATE_MANIFEST_PACKAGE_NAME)) \
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800213
Colin Cross83bb3162018-06-25 15:48:06 -0700214 a.aapt.buildActions(ctx, sdkContext(a), linkFlags...)
Colin Cross30e076a2015-04-13 13:58:27 -0700215
Colin Cross46c9b8b2017-06-22 16:51:17 -0700216 // apps manifests are handled by aapt, don't let Module see them
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700217 a.properties.Manifest = nil
Colin Cross30e076a2015-04-13 13:58:27 -0700218
Colin Cross89c31582018-04-30 15:55:11 -0700219 var staticLibProguardFlagFiles android.Paths
220 ctx.VisitDirectDeps(func(m android.Module) {
221 if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
222 staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
223 }
224 })
225
226 staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
227
228 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
229 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800230
Colin Cross5a0dcd52018-10-05 14:20:06 -0700231 a.deviceProperties.UncompressDex, a.appProperties.StripDex = a.uncompressOrStripDex(ctx)
232
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800233 if ctx.ModuleName() != "framework-res" {
234 a.Module.compile(ctx, a.aaptSrcJar)
235 }
Colin Cross5a0dcd52018-10-05 14:20:06 -0700236 dexJarFile := a.dexJarFile
Colin Cross30e076a2015-04-13 13:58:27 -0700237
Colin Cross5a0dcd52018-10-05 14:20:06 -0700238 if a.appProperties.StripDex {
239 dexJarFile = nil
240 }
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800241
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900242 var certificates []Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -0700243
Colin Crossa4f08812018-10-02 22:03:40 -0700244 var jniJarFile android.WritablePath
Colin Crossbd01e2a2018-10-04 15:21:03 -0700245 jniLibs, certificateDeps := a.collectAppDeps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700246 if len(jniLibs) > 0 {
247 embedJni := ctx.Config().UnbundledBuild() || a.appProperties.EmbedJNI
248 if embedJni {
249 jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
250 TransformJniLibsToJar(ctx, jniJarFile, jniLibs)
251 } else {
252 a.installJniLibs = jniLibs
253 }
254 }
255
Colin Crossbd01e2a2018-10-04 15:21:03 -0700256 if ctx.Failed() {
257 return
258 }
259
260 cert := String(a.appProperties.Certificate)
261 certModule := android.SrcIsModule(cert)
262 if certModule != "" {
263 a.certificate = certificateDeps[0]
264 certificateDeps = certificateDeps[1:]
265 } else if cert != "" {
266 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900267 a.certificate = Certificate{
Colin Crossbd01e2a2018-10-04 15:21:03 -0700268 defaultDir.Join(ctx, cert+".x509.pem"),
269 defaultDir.Join(ctx, cert+".pk8"),
270 }
271 } else {
272 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900273 a.certificate = Certificate{pem, key}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700274 }
275
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900276 certificates = append([]Certificate{a.certificate}, certificateDeps...)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700277
Colin Cross5a0dcd52018-10-05 14:20:06 -0700278 packageFile := android.PathForModuleOut(ctx, "package.apk")
279 CreateAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800280 a.outputFile = packageFile
281
Colin Crossf6237212018-10-29 23:14:58 -0700282 bundleFile := android.PathForModuleOut(ctx, "base.zip")
283 BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
284 a.bundleFile = bundleFile
285
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800286 if ctx.ModuleName() == "framework-res" {
287 // framework-res.apk is installed as system/framework/framework-res.apk
288 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross16056062017-12-13 22:46:28 -0800289 } else if Bool(a.appProperties.Privileged) {
290 ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app"), ctx.ModuleName()+".apk", a.outputFile)
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800291 } else {
292 ctx.InstallFile(android.PathForModuleInstall(ctx, "app"), ctx.ModuleName()+".apk", a.outputFile)
293 }
Colin Cross30e076a2015-04-13 13:58:27 -0700294}
295
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900296func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Certificate) {
Colin Crossa4f08812018-10-02 22:03:40 -0700297 var jniLibs []jniLib
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900298 var certificates []Certificate
Colin Crossa4f08812018-10-02 22:03:40 -0700299
300 ctx.VisitDirectDeps(func(module android.Module) {
301 otherName := ctx.OtherModuleName(module)
302 tag := ctx.OtherModuleDependencyTag(module)
303
304 if jniTag, ok := tag.(*jniDependencyTag); ok {
305 if dep, ok := module.(*cc.Module); ok {
306 lib := dep.OutputFile()
307 if lib.Valid() {
308 jniLibs = append(jniLibs, jniLib{
309 name: ctx.OtherModuleName(module),
310 path: lib.Path(),
311 target: jniTag.target,
312 })
313 } else {
314 ctx.ModuleErrorf("dependency %q missing output file", otherName)
315 }
316 } else {
317 ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName)
318
319 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700320 } else if tag == certificateTag {
321 if dep, ok := module.(*AndroidAppCertificate); ok {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900322 certificates = append(certificates, dep.Certificate)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700323 } else {
324 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName)
325 }
Colin Crossa4f08812018-10-02 22:03:40 -0700326 }
327 })
328
Colin Crossbd01e2a2018-10-04 15:21:03 -0700329 return jniLibs, certificates
Colin Crossa4f08812018-10-02 22:03:40 -0700330}
331
Colin Cross36242852017-06-23 15:06:31 -0700332func AndroidAppFactory() android.Module {
Colin Cross30e076a2015-04-13 13:58:27 -0700333 module := &AndroidApp{}
334
Colin Cross66dbc0b2017-12-28 12:23:20 -0800335 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
336 module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
337
Colin Crossae5caf52018-05-22 11:11:52 -0700338 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700339 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Cross5a0dcd52018-10-05 14:20:06 -0700340 module.appProperties.AllowDexPreopt = true
Colin Crossae5caf52018-05-22 11:11:52 -0700341
Colin Cross36242852017-06-23 15:06:31 -0700342 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700343 &module.Module.properties,
344 &module.Module.deviceProperties,
Colin Crossa97c5d32018-03-28 14:58:31 -0700345 &module.Module.protoProperties,
346 &module.aaptProperties,
Colin Cross540eff82017-06-22 17:01:52 -0700347 &module.appProperties)
Colin Cross36242852017-06-23 15:06:31 -0700348
Colin Crossa9d8bee2018-10-02 13:59:46 -0700349 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
350 return class == android.Device && ctx.Config().DevicePrefer32BitApps()
351 })
352
Colin Crossa4f08812018-10-02 22:03:40 -0700353 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
354 android.InitDefaultableModule(module)
355
Colin Cross36242852017-06-23 15:06:31 -0700356 return module
Colin Cross30e076a2015-04-13 13:58:27 -0700357}
Colin Crossae5caf52018-05-22 11:11:52 -0700358
359type appTestProperties struct {
360 Instrumentation_for *string
361}
362
363type AndroidTest struct {
364 AndroidApp
365
366 appTestProperties appTestProperties
367
368 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -0700369
370 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -0700371 data android.Paths
Colin Crossae5caf52018-05-22 11:11:52 -0700372}
373
374func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crossae5caf52018-05-22 11:11:52 -0700375 a.generateAndroidBuildActions(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -0700376
Jack He33338892018-09-19 02:21:28 -0700377 a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath)
Colin Crossd96ca352018-08-10 16:06:24 -0700378 a.data = ctx.ExpandSources(a.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -0700379}
380
381func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
382 android.ExtractSourceDeps(ctx, a.testProperties.Test_config)
Jack He33338892018-09-19 02:21:28 -0700383 android.ExtractSourceDeps(ctx, a.testProperties.Test_config_template)
Colin Crossd96ca352018-08-10 16:06:24 -0700384 android.ExtractSourcesDeps(ctx, a.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -0700385 a.AndroidApp.DepsMutator(ctx)
Colin Cross4b964c02018-10-15 16:18:06 -0700386 if a.appTestProperties.Instrumentation_for != nil {
387 // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac,
388 // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so
389 // use instrumentationForTag instead of libTag.
390 ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for))
391 }
Colin Crossae5caf52018-05-22 11:11:52 -0700392}
393
394func AndroidTestFactory() android.Module {
395 module := &AndroidTest{}
396
397 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
Colin Cross5067db92018-09-17 16:46:35 -0700398
399 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700400 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossa4f08812018-10-02 22:03:40 -0700401 module.appProperties.EmbedJNI = true
Colin Cross5a0dcd52018-10-05 14:20:06 -0700402 module.appProperties.AllowDexPreopt = false
Colin Crossae5caf52018-05-22 11:11:52 -0700403
404 module.AddProperties(
405 &module.Module.properties,
406 &module.Module.deviceProperties,
407 &module.Module.protoProperties,
408 &module.aaptProperties,
409 &module.appProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -0700410 &module.appTestProperties,
411 &module.testProperties)
Colin Crossae5caf52018-05-22 11:11:52 -0700412
Colin Crossa4f08812018-10-02 22:03:40 -0700413 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
414 android.InitDefaultableModule(module)
Colin Crossae5caf52018-05-22 11:11:52 -0700415 return module
416}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700417
Colin Cross252fc6f2018-10-04 15:22:03 -0700418type appTestHelperAppProperties struct {
419 // list of compatibility suites (for example "cts", "vts") that the module should be
420 // installed into.
421 Test_suites []string `android:"arch_variant"`
422}
423
424type AndroidTestHelperApp struct {
425 AndroidApp
426
427 appTestHelperAppProperties appTestHelperAppProperties
428}
429
430func AndroidTestHelperAppFactory() android.Module {
431 module := &AndroidTestHelperApp{}
432
433 module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
434
435 module.Module.properties.Installable = proptools.BoolPtr(true)
436 module.appProperties.EmbedJNI = true
Colin Cross5a0dcd52018-10-05 14:20:06 -0700437 module.appProperties.AllowDexPreopt = false
Colin Cross252fc6f2018-10-04 15:22:03 -0700438
439 module.AddProperties(
440 &module.Module.properties,
441 &module.Module.deviceProperties,
442 &module.Module.protoProperties,
443 &module.aaptProperties,
444 &module.appProperties,
445 &module.appTestHelperAppProperties)
446
447 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
448 android.InitDefaultableModule(module)
449 return module
450}
451
Colin Crossbd01e2a2018-10-04 15:21:03 -0700452type AndroidAppCertificate struct {
453 android.ModuleBase
454 properties AndroidAppCertificateProperties
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900455 Certificate Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -0700456}
457
458type AndroidAppCertificateProperties struct {
459 // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name.
460 Certificate *string
461}
462
463func AndroidAppCertificateFactory() android.Module {
464 module := &AndroidAppCertificate{}
465 module.AddProperties(&module.properties)
466 android.InitAndroidModule(module)
467 return module
468}
469
470func (c *AndroidAppCertificate) DepsMutator(ctx android.BottomUpMutatorContext) {
471}
472
473func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
474 cert := String(c.properties.Certificate)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900475 c.Certificate = Certificate{
Colin Crossbd01e2a2018-10-04 15:21:03 -0700476 android.PathForModuleSrc(ctx, cert+".x509.pem"),
477 android.PathForModuleSrc(ctx, cert+".pk8"),
478 }
479}