blob: 3f12e91c0eee869521a631222e7605e98a898ff9 [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 (
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070020 "path/filepath"
21 "reflect"
Jaewoong Jung5b425e22019-06-17 17:40:56 -070022 "sort"
Sasha Smundak4de27a52020-04-23 09:49:59 -070023 "strconv"
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070024 "strings"
Colin Cross30e076a2015-04-13 13:58:27 -070025
Colin Cross50ddcc42019-05-16 12:28:22 -070026 "github.com/google/blueprint"
27 "github.com/google/blueprint/proptools"
28
Colin Cross635c3b02016-05-18 15:37:25 -070029 "android/soong/android"
Colin Crossa4f08812018-10-02 22:03:40 -070030 "android/soong/cc"
Colin Cross303e21f2018-08-07 16:49:25 -070031 "android/soong/tradefed"
Colin Cross30e076a2015-04-13 13:58:27 -070032)
33
Jaewoong Jung3e18b192019-06-11 12:25:34 -070034var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"}
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070035
Colin Cross3bc7ffa2017-11-22 16:19:37 -080036func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000037 RegisterAppBuildComponents(android.InitRegistrationContext)
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -070038
39 initAndroidAppImportVariantGroupTypes()
Colin Cross3bc7ffa2017-11-22 16:19:37 -080040}
41
Paul Duffinf9b1da02019-12-18 19:51:55 +000042func RegisterAppBuildComponents(ctx android.RegistrationContext) {
43 ctx.RegisterModuleType("android_app", AndroidAppFactory)
44 ctx.RegisterModuleType("android_test", AndroidTestFactory)
45 ctx.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory)
46 ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
47 ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
48 ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
Roshan Piusb8307962020-04-27 09:42:27 -070049 ctx.RegisterModuleType("override_runtime_resource_overlay", OverrideRuntimeResourceOverlayModuleFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +000050 ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
51 ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080052 ctx.RegisterModuleType("runtime_resource_overlay", RuntimeResourceOverlayFactory)
Sasha Smundak4de27a52020-04-23 09:49:59 -070053 ctx.RegisterModuleType("android_app_set", AndroidApkSetFactory)
54}
55
56type AndroidAppSetProperties struct {
57 // APK Set path
58 Set *string
59
60 // Specifies that this app should be installed to the priv-app directory,
61 // where the system will grant it additional privileges not available to
62 // normal apps.
63 Privileged *bool
64
65 // APKs in this set use prerelease SDK version
66 Prerelease *bool
67
68 // Names of modules to be overridden. Listed modules can only be other apps
69 // (in Make or Soong).
70 Overrides []string
71}
72
73type AndroidAppSet struct {
74 android.ModuleBase
75 android.DefaultableModuleBase
76 prebuilt android.Prebuilt
77
78 properties AndroidAppSetProperties
79 packedOutput android.WritablePath
80 masterFile string
Jaewoong Jung8bec0262020-06-29 19:18:44 -070081 apkcertsFile android.ModuleOutPath
Sasha Smundak4de27a52020-04-23 09:49:59 -070082}
83
84func (as *AndroidAppSet) Name() string {
85 return as.prebuilt.Name(as.ModuleBase.Name())
86}
87
88func (as *AndroidAppSet) IsInstallable() bool {
89 return true
90}
91
92func (as *AndroidAppSet) Prebuilt() *android.Prebuilt {
93 return &as.prebuilt
94}
95
96func (as *AndroidAppSet) Privileged() bool {
97 return Bool(as.properties.Privileged)
98}
99
Sasha Smundakc4f0ff12020-05-27 16:36:07 -0700100func (as *AndroidAppSet) OutputFile() android.Path {
101 return as.packedOutput
102}
103
104func (as *AndroidAppSet) MasterFile() string {
105 return as.masterFile
106}
107
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700108var TargetCpuAbi = map[string]string{
Sasha Smundak4de27a52020-04-23 09:49:59 -0700109 "arm": "ARMEABI_V7A",
110 "arm64": "ARM64_V8A",
111 "x86": "X86",
112 "x86_64": "X86_64",
113}
114
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700115func SupportedAbis(ctx android.ModuleContext) []string {
Jaewoong Jung829b7132020-06-10 12:23:32 -0700116 abiName := func(targetIdx int, deviceArch string) string {
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700117 if abi, found := TargetCpuAbi[deviceArch]; found {
Sasha Smundak4de27a52020-04-23 09:49:59 -0700118 return abi
119 }
Jaewoong Jung829b7132020-06-10 12:23:32 -0700120 ctx.ModuleErrorf("Target %d has invalid Arch: %s", targetIdx, deviceArch)
Sasha Smundak4de27a52020-04-23 09:49:59 -0700121 return "BAD_ABI"
122 }
123
Jaewoong Jung829b7132020-06-10 12:23:32 -0700124 var result []string
125 for i, target := range ctx.Config().Targets[android.Android] {
126 result = append(result, abiName(i, target.Arch.ArchType.String()))
Sasha Smundak4de27a52020-04-23 09:49:59 -0700127 }
128 return result
129}
130
131func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sasha Smundakc4f0ff12020-05-27 16:36:07 -0700132 as.packedOutput = android.PathForModuleOut(ctx, ctx.ModuleName()+".zip")
Jaewoong Jung8bec0262020-06-29 19:18:44 -0700133 as.apkcertsFile = android.PathForModuleOut(ctx, "apkcerts.txt")
Sasha Smundak4de27a52020-04-23 09:49:59 -0700134 // We are assuming here that the master file in the APK
135 // set has `.apk` suffix. If it doesn't the build will fail.
136 // APK sets containing APEX files are handled elsewhere.
Sasha Smundak854c14f2020-06-16 10:28:22 -0700137 as.masterFile = as.BaseModuleName() + ".apk"
Sasha Smundak4de27a52020-04-23 09:49:59 -0700138 screenDensities := "all"
139 if dpis := ctx.Config().ProductAAPTPrebuiltDPI(); len(dpis) > 0 {
140 screenDensities = strings.ToUpper(strings.Join(dpis, ","))
141 }
142 // TODO(asmundak): handle locales.
143 // TODO(asmundak): do we support device features
144 ctx.Build(pctx,
145 android.BuildParams{
Jaewoong Jung8bec0262020-06-29 19:18:44 -0700146 Rule: extractMatchingApks,
147 Description: "Extract APKs from APK set",
148 Output: as.packedOutput,
149 ImplicitOutput: as.apkcertsFile,
150 Inputs: android.Paths{as.prebuilt.SingleSourcePath(ctx)},
Sasha Smundak4de27a52020-04-23 09:49:59 -0700151 Args: map[string]string{
Jaewoong Jung8cf307e2020-05-14 14:15:24 -0700152 "abis": strings.Join(SupportedAbis(ctx), ","),
Sasha Smundak4de27a52020-04-23 09:49:59 -0700153 "allow-prereleased": strconv.FormatBool(proptools.Bool(as.properties.Prerelease)),
154 "screen-densities": screenDensities,
155 "sdk-version": ctx.Config().PlatformSdkVersion(),
Sasha Smundak3c904e82020-06-22 16:53:33 -0700156 "stem": as.BaseModuleName(),
Jaewoong Jung8bec0262020-06-29 19:18:44 -0700157 "apkcerts": as.apkcertsFile.String(),
158 "partition": as.PartitionTag(ctx.DeviceConfig()),
Sasha Smundak4de27a52020-04-23 09:49:59 -0700159 },
160 })
Sasha Smundak4de27a52020-04-23 09:49:59 -0700161}
162
163// android_app_set extracts a set of APKs based on the target device
164// configuration and installs this set as "split APKs".
Sasha Smundakc4f0ff12020-05-27 16:36:07 -0700165// The extracted set always contains 'master' APK whose name is
166// _module_name_.apk and every split APK matching target device.
167// The extraction of the density-specific splits depends on
168// PRODUCT_AAPT_PREBUILT_DPI variable. If present (its value should
169// be a list density names: LDPI, MDPI, HDPI, etc.), only listed
170// splits will be extracted. Otherwise all density-specific splits
171// will be extracted.
Sasha Smundak4de27a52020-04-23 09:49:59 -0700172func AndroidApkSetFactory() android.Module {
173 module := &AndroidAppSet{}
174 module.AddProperties(&module.properties)
175 InitJavaModule(module, android.DeviceSupported)
176 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Set")
177 return module
Paul Duffinf9b1da02019-12-18 19:51:55 +0000178}
179
Colin Cross30e076a2015-04-13 13:58:27 -0700180// AndroidManifest.xml merging
181// package splits
182
Colin Crossfabb6082018-02-20 17:22:23 -0800183type appProperties struct {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700184 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
Colin Cross7d5136f2015-05-11 13:39:40 -0700185 Additional_certificates []string
186
187 // If set, create package-export.apk, which other packages can
188 // use to get PRODUCT-agnostic resource data like IDs and type definitions.
Nan Zhangea568a42017-11-08 21:20:04 -0800189 Export_package_resources *bool
Colin Cross7d5136f2015-05-11 13:39:40 -0700190
Colin Cross16056062017-12-13 22:46:28 -0800191 // Specifies that this app should be installed to the priv-app directory,
192 // where the system will grant it additional privileges not available to
193 // normal apps.
194 Privileged *bool
Colin Crossa97c5d32018-03-28 14:58:31 -0700195
196 // list of resource labels to generate individual resource packages
197 Package_splits []string
Jason Monkd4122be2018-08-10 09:33:36 -0400198
199 // Names of modules to be overridden. Listed modules can only be other binaries
200 // (in Make or Soong).
201 // This does not completely prevent installation of the overridden binaries, but if both
202 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
203 // from PRODUCT_PACKAGES.
204 Overrides []string
Colin Crossa4f08812018-10-02 22:03:40 -0700205
206 // list of native libraries that will be provided in or alongside the resulting jar
207 Jni_libs []string `android:"arch_variant"`
208
Colin Cross76583a42020-05-06 17:51:39 -0700209 // if true, use JNI libraries that link against platform APIs even if this module sets
Colin Crossee87c602020-02-19 16:57:15 -0800210 // sdk_version.
211 Jni_uses_platform_apis *bool
212
Colin Cross76583a42020-05-06 17:51:39 -0700213 // if true, use JNI libraries that link against SDK APIs even if this module does not set
214 // sdk_version.
215 Jni_uses_sdk_apis *bool
216
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700217 // STL library to use for JNI libraries.
218 Stl *string `android:"arch_variant"`
219
Colin Crosse4246ab2019-02-05 21:55:21 -0800220 // Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest
221 // flag so that they are used from inside the APK at runtime. Defaults to true for android_test modules unless
Jiyong Park52cd06f2019-11-11 10:14:32 +0900222 // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to true for
223 // android_app modules that are embedded to APEXes, defaults to false for other module types where the native
224 // libraries are generally preinstalled outside the APK.
Colin Crosse4246ab2019-02-05 21:55:21 -0800225 Use_embedded_native_libs *bool
Colin Cross46abdad2019-02-07 13:07:08 -0800226
227 // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that
228 // they are used from inside the APK at runtime.
229 Use_embedded_dex *bool
Colin Cross47fa9d32019-03-26 10:51:39 -0700230
231 // Forces native libraries to always be packaged into the APK,
232 // Use_embedded_native_libs still selects whether they are stored uncompressed and aligned or compressed.
233 // True for android_test* modules.
234 AlwaysPackageNativeLibs bool `blueprint:"mutated"`
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700235
236 // If set, find and merge all NOTICE files that this module and its dependencies have and store
237 // it in the APK as an asset.
238 Embed_notices *bool
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700239
240 // cc.Coverage related properties
241 PreventInstall bool `blueprint:"mutated"`
242 HideFromMake bool `blueprint:"mutated"`
243 IsCoverageVariant bool `blueprint:"mutated"`
Artur Satayeve5ac15a2020-04-08 19:09:30 +0100244
245 // Whether this app is considered mainline updatable or not. When set to true, this will enforce
Artur Satayev11962102020-04-16 13:43:02 +0100246 // additional rules to make sure an app can safely be updated. Default is false.
247 // Prefer using other specific properties if build behaviour must be changed; avoid using this
248 // flag for anything but neverallow rules (unless the behaviour change is invisible to owners).
Artur Satayeve5ac15a2020-04-08 19:09:30 +0100249 Updatable *bool
Colin Cross7d5136f2015-05-11 13:39:40 -0700250}
251
Jaewoong Jung525443a2019-02-28 15:35:54 -0800252// android_app properties that can be overridden by override_android_app
253type overridableAppProperties struct {
254 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
255 // or an android_app_certificate module name in the form ":module".
256 Certificate *string
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700257
Liz Kammer70dd74d2020-05-07 13:24:05 -0700258 // Name of the signing certificate lineage file.
259 Lineage *string
260
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700261 // the package name of this app. The package name in the manifest file is used if one was not given.
262 Package_name *string
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800263
264 // the logging parent of this app.
265 Logging_parent *string
Jaewoong Jung525443a2019-02-28 15:35:54 -0800266}
267
Roshan Piusb8307962020-04-27 09:42:27 -0700268// runtime_resource_overlay properties that can be overridden by override_runtime_resource_overlay
269type OverridableRuntimeResourceOverlayProperties struct {
270 // the package name of this app. The package name in the manifest file is used if one was not given.
271 Package_name *string
272
273 // the target package name of this overlay app. The target package name in the manifest file is used if one was not given.
274 Target_package_name *string
275}
276
Colin Cross30e076a2015-04-13 13:58:27 -0700277type AndroidApp struct {
Colin Crossa97c5d32018-03-28 14:58:31 -0700278 Library
279 aapt
Jaewoong Jung525443a2019-02-28 15:35:54 -0800280 android.OverridableModuleBase
Colin Crossa97c5d32018-03-28 14:58:31 -0700281
Colin Cross50ddcc42019-05-16 12:28:22 -0700282 usesLibrary usesLibrary
283
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900284 certificate Certificate
Colin Cross30e076a2015-04-13 13:58:27 -0700285
Colin Crossfabb6082018-02-20 17:22:23 -0800286 appProperties appProperties
Colin Crossae5caf52018-05-22 11:11:52 -0700287
Jaewoong Jung525443a2019-02-28 15:35:54 -0800288 overridableAppProperties overridableAppProperties
289
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700290 installJniLibs []jniLib
291 jniCoverageOutputs android.Paths
Colin Crossf6237212018-10-29 23:14:58 -0700292
293 bundleFile android.Path
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800294
295 // the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES.
296 installApkName string
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800297
Colin Cross70dda7e2019-10-01 22:05:35 -0700298 installDir android.InstallPath
Jaewoong Jung0949f312019-09-11 10:25:18 -0700299
Jaewoong Jung7dd4ae22019-09-27 17:13:15 -0700300 onDeviceDir string
301
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800302 additionalAaptFlags []string
Jaewoong Jung98772792019-07-01 17:15:13 -0700303
304 noticeOutputs android.NoticeOutputs
Jiyong Parkaf8998c2020-02-28 16:51:07 +0900305
306 overriddenManifestPackageName string
Artur Satayevd9b503a2020-04-27 19:05:28 +0100307
308 android.ApexBundleDepsInfo
Colin Crosse1731a52017-12-14 11:22:55 -0800309}
310
Martin Stjernholm6d415272020-01-31 17:10:36 +0000311func (a *AndroidApp) IsInstallable() bool {
312 return Bool(a.properties.Installable)
313}
314
Colin Cross89c31582018-04-30 15:55:11 -0700315func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
316 return nil
317}
318
Colin Cross66f78822018-05-02 12:58:28 -0700319func (a *AndroidApp) ExportedStaticPackages() android.Paths {
320 return nil
321}
322
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900323func (a *AndroidApp) OutputFile() android.Path {
324 return a.outputFile
325}
326
Colin Cross503c1d02020-01-28 14:00:53 -0800327func (a *AndroidApp) Certificate() Certificate {
328 return a.certificate
329}
330
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700331func (a *AndroidApp) JniCoverageOutputs() android.Paths {
332 return a.jniCoverageOutputs
333}
334
Colin Crossa97c5d32018-03-28 14:58:31 -0700335var _ AndroidLibraryDependency = (*AndroidApp)(nil)
336
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900337type Certificate struct {
Colin Cross503c1d02020-01-28 14:00:53 -0800338 Pem, Key android.Path
339 presigned bool
340}
341
Sasha Smundakc4f0ff12020-05-27 16:36:07 -0700342var PresignedCertificate = Certificate{presigned: true}
Colin Cross503c1d02020-01-28 14:00:53 -0800343
344func (c Certificate) AndroidMkString() string {
345 if c.presigned {
346 return "PRESIGNED"
347 } else {
348 return c.Pem.String()
349 }
Colin Cross30e076a2015-04-13 13:58:27 -0700350}
351
Colin Cross46c9b8b2017-06-22 16:51:17 -0700352func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
353 a.Module.deps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700354
Jiyong Park6a927c42020-01-21 02:03:43 +0900355 if String(a.appProperties.Stl) == "c++_shared" && !a.sdkVersion().specified() {
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700356 ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared")
357 }
358
Paul Duffin250e6192019-06-07 10:44:37 +0100359 sdkDep := decodeSdkDep(ctx, sdkContext(a))
360 if sdkDep.hasFrameworkLibs() {
361 a.aapt.deps(ctx, sdkDep)
Colin Cross30e076a2015-04-13 13:58:27 -0700362 }
Colin Crossa4f08812018-10-02 22:03:40 -0700363
Colin Cross1dd9c442020-05-08 11:20:24 -0700364 usesSDK := a.sdkVersion().specified() && a.sdkVersion().kind != sdkCorePlatform
365
366 if usesSDK && Bool(a.appProperties.Jni_uses_sdk_apis) {
367 ctx.PropertyErrorf("jni_uses_sdk_apis",
368 "can only be set for modules that do not set sdk_version")
369 } else if !usesSDK && Bool(a.appProperties.Jni_uses_platform_apis) {
370 ctx.PropertyErrorf("jni_uses_platform_apis",
371 "can only be set for modules that set sdk_version")
372 }
373
Peter Collingbournead84f972019-12-17 16:46:18 -0800374 tag := &jniDependencyTag{}
Colin Crossa4f08812018-10-02 22:03:40 -0700375 for _, jniTarget := range ctx.MultiTargets() {
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700376 variation := append(jniTarget.Variations(),
377 blueprint.Variation{Mutator: "link", Variation: "shared"})
Colin Cross01fd7cc2020-02-19 16:54:04 -0800378
379 // If the app builds against an Android SDK use the SDK variant of JNI dependencies
380 // unless jni_uses_platform_apis is set.
Colin Crosseb032962020-05-13 11:05:02 -0700381 // Don't require the SDK variant for apps that are shipped on vendor, etc., as they already
382 // have stable APIs through the VNDK.
383 if (usesSDK && !a.RequiresStableAPIs(ctx) &&
384 !Bool(a.appProperties.Jni_uses_platform_apis)) ||
Colin Cross76583a42020-05-06 17:51:39 -0700385 Bool(a.appProperties.Jni_uses_sdk_apis) {
Colin Cross01fd7cc2020-02-19 16:54:04 -0800386 variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
387 }
Colin Crossa4f08812018-10-02 22:03:40 -0700388 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
389 }
Colin Cross50ddcc42019-05-16 12:28:22 -0700390
Paul Duffin250e6192019-06-07 10:44:37 +0100391 a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700392}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700393
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700394func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800395 cert := android.SrcIsModule(a.getCertString(ctx))
Colin Crossbd01e2a2018-10-04 15:21:03 -0700396 if cert != "" {
397 ctx.AddDependency(ctx.Module(), certificateTag, cert)
398 }
399
400 for _, cert := range a.appProperties.Additional_certificates {
401 cert = android.SrcIsModule(cert)
402 if cert != "" {
403 ctx.AddDependency(ctx.Module(), certificateTag, cert)
404 } else {
405 ctx.PropertyErrorf("additional_certificates",
406 `must be names of android_app_certificate modules in the form ":module"`)
407 }
408 }
Colin Cross30e076a2015-04-13 13:58:27 -0700409}
410
Jeongik Cha538c0d02019-07-11 15:54:27 +0900411func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
412 a.generateAndroidBuildActions(ctx)
413}
414
Colin Cross46c9b8b2017-06-22 16:51:17 -0700415func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Artur Satayeve5ac15a2020-04-08 19:09:30 +0100416 a.checkAppSdkVersions(ctx)
Colin Crossae5caf52018-05-22 11:11:52 -0700417 a.generateAndroidBuildActions(ctx)
418}
419
Artur Satayeve5ac15a2020-04-08 19:09:30 +0100420func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
Artur Satayev2b4b7bb2020-04-28 14:57:42 +0100421 if a.Updatable() {
Artur Satayeve5ac15a2020-04-08 19:09:30 +0100422 if !a.sdkVersion().stable() {
423 ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.sdkVersion())
424 }
Artur Satayev11962102020-04-16 13:43:02 +0100425 if String(a.deviceProperties.Min_sdk_version) == "" {
426 ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
427 }
Jooyung Hanaf7f91f2020-04-29 14:01:06 +0900428 if minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx); err == nil {
429 a.checkJniLibsSdkVersion(ctx, minSdkVersion)
430 } else {
431 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
432 }
Artur Satayeve5ac15a2020-04-08 19:09:30 +0100433 }
434
435 a.checkPlatformAPI(ctx)
436 a.checkSdkVersions(ctx)
437}
438
Jooyung Hanaf7f91f2020-04-29 14:01:06 +0900439// If an updatable APK sets min_sdk_version, min_sdk_vesion of JNI libs should match with it.
440// This check is enforced for "updatable" APKs (including APK-in-APEX).
441// b/155209650: until min_sdk_version is properly supported, use sdk_version instead.
442// because, sdk_version is overridden by min_sdk_version (if set as smaller)
443// and linkType is checked with dependencies so we can be sure that the whole dependency tree
444// will meet the requirements.
445func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion sdkVersion) {
446 // It's enough to check direct JNI deps' sdk_version because all transitive deps from JNI deps are checked in cc.checkLinkType()
447 ctx.VisitDirectDeps(func(m android.Module) {
448 if !IsJniDepTag(ctx.OtherModuleDependencyTag(m)) {
449 return
450 }
451 dep, _ := m.(*cc.Module)
Jooyung Han9d2c0f72020-05-20 17:12:13 +0900452 // The domain of cc.sdk_version is "current" and <number>
453 // We can rely on sdkSpec to convert it to <number> so that "current" is handled
454 // properly regardless of sdk finalization.
455 jniSdkVersion, err := sdkSpecFrom(dep.SdkVersion()).effectiveVersion(ctx)
456 if err != nil || minSdkVersion < jniSdkVersion {
Jooyung Hanaf7f91f2020-04-29 14:01:06 +0900457 ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
458 dep.SdkVersion(), minSdkVersion, ctx.ModuleName())
459 return
460 }
461
462 })
463}
464
Sasha Smundak6ad77252019-05-01 13:16:22 -0700465// Returns true if the native libraries should be stored in the APK uncompressed and the
Colin Crosse4246ab2019-02-05 21:55:21 -0800466// extractNativeLibs application flag should be set to false in the manifest.
Sasha Smundak6ad77252019-05-01 13:16:22 -0700467func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
Jiyong Park6a927c42020-01-21 02:03:43 +0900468 minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx)
Colin Crosse4246ab2019-02-05 21:55:21 -0800469 if err != nil {
470 ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
471 }
472
Jiyong Park52cd06f2019-11-11 10:14:32 +0900473 return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
474 !a.IsForPlatform()
Colin Crosse4246ab2019-02-05 21:55:21 -0800475}
476
Colin Cross43f08db2018-11-12 10:13:39 -0800477// Returns whether this module should have the dex file stored uncompressed in the APK.
478func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
Colin Cross46abdad2019-02-07 13:07:08 -0800479 if Bool(a.appProperties.Use_embedded_dex) {
480 return true
481 }
482
Colin Cross53a87f52019-06-25 13:35:30 -0700483 // Uncompress dex in APKs of privileged apps (even for unbundled builds, they may
484 // be preinstalled as prebuilts).
Jiyong Parkf7487312019-10-17 12:54:30 +0900485 if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000486 return true
487 }
488
Colin Cross53a87f52019-06-25 13:35:30 -0700489 if ctx.Config().UnbundledBuild() {
490 return false
491 }
492
Jaewoong Jungacf18d72019-05-02 14:55:29 -0700493 return shouldUncompressDex(ctx, &a.dexpreopter)
Colin Cross5a0dcd52018-10-05 14:20:06 -0700494}
495
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700496func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
497 return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
Jiyong Park52cd06f2019-11-11 10:14:32 +0900498 !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700499}
500
Jiyong Parkaf8998c2020-02-28 16:51:07 +0900501func (a *AndroidApp) OverriddenManifestPackageName() string {
502 return a.overriddenManifestPackageName
503}
504
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800505func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
David Brazdild25060a2019-02-18 18:24:16 +0000506 a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis)
507
Jaewoong Jungc27ab662019-05-30 15:51:14 -0700508 // Ask manifest_fixer to add or update the application element indicating this app has no code.
509 a.aapt.hasNoCode = !a.hasCode(ctx)
510
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800511 aaptLinkFlags := []string{}
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800512
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800513 // Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800514 hasProduct := android.PrefixInList(a.aaptProperties.Aaptflags, "--product")
Colin Crosse78dcd32018-04-19 15:25:19 -0700515 if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800516 aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
Colin Crosse78dcd32018-04-19 15:25:19 -0700517 }
518
Dan Willemsen72be5902018-10-24 20:24:57 -0700519 if !Bool(a.aaptProperties.Aapt_include_all_resources) {
520 // Product AAPT config
521 for _, aaptConfig := range ctx.Config().ProductAAPTConfig() {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800522 aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig)
Dan Willemsen72be5902018-10-24 20:24:57 -0700523 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700524
Dan Willemsen72be5902018-10-24 20:24:57 -0700525 // Product AAPT preferred config
526 if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800527 aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig())
Dan Willemsen72be5902018-10-24 20:24:57 -0700528 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700529 }
530
Jiyong Park7f67f482019-01-05 12:57:48 +0900531 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700532 if overridden || a.overridableAppProperties.Package_name != nil {
533 // The product override variable has a priority over the package_name property.
534 if !overridden {
535 manifestPackageName = *a.overridableAppProperties.Package_name
536 }
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800537 aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName)
Jiyong Parkaf8998c2020-02-28 16:51:07 +0900538 a.overriddenManifestPackageName = manifestPackageName
Jiyong Park7f67f482019-01-05 12:57:48 +0900539 }
540
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800541 aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...)
542
Colin Crosse560c4a2019-03-19 16:03:11 -0700543 a.aapt.splitNames = a.appProperties.Package_splits
Colin Cross50ddcc42019-05-16 12:28:22 -0700544 a.aapt.sdkLibraries = a.exportedSdkLibs
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800545 a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent)
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800546 a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...)
Colin Cross30e076a2015-04-13 13:58:27 -0700547
Colin Cross46c9b8b2017-06-22 16:51:17 -0700548 // apps manifests are handled by aapt, don't let Module see them
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700549 a.properties.Manifest = nil
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800550}
Colin Cross30e076a2015-04-13 13:58:27 -0700551
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800552func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) {
Colin Cross89c31582018-04-30 15:55:11 -0700553 var staticLibProguardFlagFiles android.Paths
554 ctx.VisitDirectDeps(func(m android.Module) {
555 if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
556 staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
557 }
558 })
559
560 staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
561
562 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
563 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800564}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800565
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800566func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
Colin Cross43f08db2018-11-12 10:13:39 -0800567
568 var installDir string
569 if ctx.ModuleName() == "framework-res" {
570 // framework-res.apk is installed as system/framework/framework-res.apk
571 installDir = "framework"
Jiyong Parkf7487312019-10-17 12:54:30 +0900572 } else if a.Privileged() {
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800573 installDir = filepath.Join("priv-app", a.installApkName)
Colin Cross43f08db2018-11-12 10:13:39 -0800574 } else {
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800575 installDir = filepath.Join("app", a.installApkName)
Colin Cross43f08db2018-11-12 10:13:39 -0800576 }
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800577 a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
David Srbecky98c71222020-05-20 22:20:28 +0100578 if a.deviceProperties.Uncompress_dex == nil {
579 // If the value was not force-set by the user, use reasonable default based on the module.
580 a.deviceProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx))
581 }
582 a.dexpreopter.uncompressedDex = *a.deviceProperties.Uncompress_dex
Colin Cross50ddcc42019-05-16 12:28:22 -0700583 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
584 a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
585 a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
586 a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
587 a.dexpreopter.manifestFile = a.mergedManifestFile
588
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800589 if ctx.ModuleName() != "framework-res" {
590 a.Module.compile(ctx, a.aaptSrcJar)
591 }
Colin Cross30e076a2015-04-13 13:58:27 -0700592
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800593 return a.maybeStrippedDexJarFile
594}
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800595
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800596func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath {
Colin Crossa4f08812018-10-02 22:03:40 -0700597 var jniJarFile android.WritablePath
Colin Crossa4f08812018-10-02 22:03:40 -0700598 if len(jniLibs) > 0 {
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700599 if a.shouldEmbedJnis(ctx) {
Colin Crossa4f08812018-10-02 22:03:40 -0700600 jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
Sasha Smundak6ad77252019-05-01 13:16:22 -0700601 TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.useEmbeddedNativeLibs(ctx))
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700602 for _, jni := range jniLibs {
603 if jni.coverageFile.Valid() {
Jaewoong Junge62e5942020-04-07 13:07:55 -0700604 // Only collect coverage for the first target arch if this is a multilib target.
605 // TODO(jungjw): Ideally, we want to collect both reports, but that would cause coverage
606 // data file path collisions since the current coverage file path format doesn't contain
607 // arch-related strings. This is fine for now though; the code coverage team doesn't use
608 // multi-arch targets such as test_suite_* for coverage collections yet.
609 //
610 // Work with the team to come up with a new format that handles multilib modules properly
611 // and change this.
612 if len(ctx.Config().Targets[android.Android]) == 1 ||
613 ctx.Config().Targets[android.Android][0].Arch.ArchType == jni.target.Arch.ArchType {
614 a.jniCoverageOutputs = append(a.jniCoverageOutputs, jni.coverageFile.Path())
615 }
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700616 }
617 }
Colin Crossa4f08812018-10-02 22:03:40 -0700618 } else {
619 a.installJniLibs = jniLibs
620 }
621 }
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800622 return jniJarFile
623}
Colin Crossa4f08812018-10-02 22:03:40 -0700624
Jaewoong Jung0949f312019-09-11 10:25:18 -0700625func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext) {
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700626 // Collect NOTICE files from all dependencies.
627 seenModules := make(map[android.Module]bool)
628 noticePathSet := make(map[android.Path]bool)
629
630 ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
631 // Have we already seen this?
632 if _, ok := seenModules[child]; ok {
633 return false
634 }
635 seenModules[child] = true
636
637 // Skip host modules.
638 if child.Target().Os.Class == android.Host || child.Target().Os.Class == android.HostCross {
639 return false
640 }
641
642 path := child.(android.Module).NoticeFile()
643 if path.Valid() {
644 noticePathSet[path.Path()] = true
645 }
646 return true
647 })
648
649 // If the app has one, add it too.
650 if a.NoticeFile().Valid() {
651 noticePathSet[a.NoticeFile().Path()] = true
652 }
653
654 if len(noticePathSet) == 0 {
Jaewoong Jung98772792019-07-01 17:15:13 -0700655 return
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700656 }
657 var noticePaths []android.Path
658 for path := range noticePathSet {
659 noticePaths = append(noticePaths, path)
660 }
661 sort.Slice(noticePaths, func(i, j int) bool {
662 return noticePaths[i].String() < noticePaths[j].String()
663 })
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700664
Jaewoong Jung0949f312019-09-11 10:25:18 -0700665 a.noticeOutputs = android.BuildNoticeOutput(ctx, a.installDir, a.installApkName+".apk", noticePaths)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700666}
667
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700668// Reads and prepends a main cert from the default cert dir if it hasn't been set already, i.e. it
669// isn't a cert module reference. Also checks and enforces system cert restriction if applicable.
670func processMainCert(m android.ModuleBase, certPropValue string, certificates []Certificate, ctx android.ModuleContext) []Certificate {
671 if android.SrcIsModule(certPropValue) == "" {
672 var mainCert Certificate
673 if certPropValue != "" {
674 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
675 mainCert = Certificate{
Colin Cross503c1d02020-01-28 14:00:53 -0800676 Pem: defaultDir.Join(ctx, certPropValue+".x509.pem"),
677 Key: defaultDir.Join(ctx, certPropValue+".pk8"),
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700678 }
679 } else {
680 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Colin Cross503c1d02020-01-28 14:00:53 -0800681 mainCert = Certificate{
682 Pem: pem,
683 Key: key,
684 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700685 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700686 certificates = append([]Certificate{mainCert}, certificates...)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700687 }
688
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700689 if !m.Platform() {
690 certPath := certificates[0].Pem.String()
Jeongik Chac9464142019-01-07 12:07:27 +0900691 systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String()
692 if strings.HasPrefix(certPath, systemCertPath) {
693 enforceSystemCert := ctx.Config().EnforceSystemCertificate()
Colin Cross95f7b342020-06-11 11:32:11 -0700694 allowed := ctx.Config().EnforceSystemCertificateAllowList()
Jeongik Chac9464142019-01-07 12:07:27 +0900695
Colin Cross95f7b342020-06-11 11:32:11 -0700696 if enforceSystemCert && !inList(m.Name(), allowed) {
Jeongik Chac9464142019-01-07 12:07:27 +0900697 ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.")
698 }
699 }
700 }
701
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700702 return certificates
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800703}
704
Jooyung Han65cd0f02020-03-23 20:21:11 +0900705func (a *AndroidApp) InstallApkName() string {
706 return a.installApkName
707}
708
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800709func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross50ddcc42019-05-16 12:28:22 -0700710 var apkDeps android.Paths
711
Jeongik Cha538c0d02019-07-11 15:54:27 +0900712 a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx)
713 a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
714
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800715 // Check if the install APK name needs to be overridden.
Jaewoong Jung525443a2019-02-28 15:35:54 -0800716 a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Name())
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800717
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700718 if ctx.ModuleName() == "framework-res" {
719 // framework-res.apk is installed as system/framework/framework-res.apk
Jaewoong Jung0949f312019-09-11 10:25:18 -0700720 a.installDir = android.PathForModuleInstall(ctx, "framework")
Jiyong Parkf7487312019-10-17 12:54:30 +0900721 } else if a.Privileged() {
Jaewoong Jung0949f312019-09-11 10:25:18 -0700722 a.installDir = android.PathForModuleInstall(ctx, "priv-app", a.installApkName)
723 } else if ctx.InstallInTestcases() {
Jaewoong Jung326a9412019-11-21 10:41:00 -0800724 a.installDir = android.PathForModuleInstall(ctx, a.installApkName, ctx.DeviceConfig().DeviceArch())
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700725 } else {
Jaewoong Jung0949f312019-09-11 10:25:18 -0700726 a.installDir = android.PathForModuleInstall(ctx, "app", a.installApkName)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700727 }
Jaewoong Jung7dd4ae22019-09-27 17:13:15 -0700728 a.onDeviceDir = android.InstallPathToOnDevicePath(ctx, a.installDir)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700729
Jaewoong Jung0949f312019-09-11 10:25:18 -0700730 a.noticeBuildActions(ctx)
Jaewoong Jung98772792019-07-01 17:15:13 -0700731 if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") {
732 a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput
733 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700734
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800735 // Process all building blocks, from AAPT to certificates.
736 a.aaptBuildActions(ctx)
737
Colin Cross50ddcc42019-05-16 12:28:22 -0700738 if a.usesLibrary.enforceUsesLibraries() {
739 manifestCheckFile := a.usesLibrary.verifyUsesLibrariesManifest(ctx, a.mergedManifestFile)
740 apkDeps = append(apkDeps, manifestCheckFile)
741 }
742
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800743 a.proguardBuildActions(ctx)
744
Colin Cross1e28e3c2020-06-02 20:09:13 -0700745 a.linter.mergedManifest = a.aapt.mergedManifestFile
746 a.linter.manifest = a.aapt.manifestPath
747 a.linter.resources = a.aapt.resourceFiles
748
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800749 dexJarFile := a.dexBuildActions(ctx)
750
Colin Crosseb032962020-05-13 11:05:02 -0700751 jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800752 jniJarFile := a.jniBuildActions(jniLibs, ctx)
753
754 if ctx.Failed() {
755 return
756 }
757
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700758 certificates := processMainCert(a.ModuleBase, a.getCertString(ctx), certificateDeps, ctx)
759 a.certificate = certificates[0]
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800760
761 // Build a final signed app package.
Jaewoong Jung5a498812019-11-07 14:14:38 -0800762 packageFile := android.PathForModuleOut(ctx, a.installApkName+".apk")
Songchun Fan688de9a2020-03-24 20:32:24 -0700763 v4SigningRequested := Bool(a.Module.deviceProperties.V4_signature)
764 var v4SignatureFile android.WritablePath = nil
765 if v4SigningRequested {
766 v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+".apk.idsig")
767 }
Liz Kammer70dd74d2020-05-07 13:24:05 -0700768 var lineageFile android.Path
769 if lineage := String(a.overridableAppProperties.Lineage); lineage != "" {
770 lineageFile = android.PathForModuleSrc(ctx, lineage)
771 }
772 CreateAndSignAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile, lineageFile)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800773 a.outputFile = packageFile
Songchun Fan688de9a2020-03-24 20:32:24 -0700774 if v4SigningRequested {
775 a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile)
776 }
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800777
Colin Crosse560c4a2019-03-19 16:03:11 -0700778 for _, split := range a.aapt.splits {
779 // Sign the split APKs
Jaewoong Jung5a498812019-11-07 14:14:38 -0800780 packageFile := android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk")
Songchun Fan688de9a2020-03-24 20:32:24 -0700781 if v4SigningRequested {
782 v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk.idsig")
783 }
Liz Kammer70dd74d2020-05-07 13:24:05 -0700784 CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile, lineageFile)
Colin Crosse560c4a2019-03-19 16:03:11 -0700785 a.extraOutputFiles = append(a.extraOutputFiles, packageFile)
Songchun Fan688de9a2020-03-24 20:32:24 -0700786 if v4SigningRequested {
787 a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile)
788 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700789 }
790
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800791 // Build an app bundle.
Colin Crossf6237212018-10-29 23:14:58 -0700792 bundleFile := android.PathForModuleOut(ctx, "base.zip")
793 BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
794 a.bundleFile = bundleFile
795
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800796 // Install the app package.
Jiyong Park8ba50f92019-11-13 15:01:01 +0900797 if (Bool(a.Module.properties.Installable) || ctx.Host()) && a.IsForPlatform() {
798 ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
799 for _, extra := range a.extraOutputFiles {
800 ctx.InstallFile(a.installDir, extra.Base(), extra)
801 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800802 }
Artur Satayevd9b503a2020-04-27 19:05:28 +0100803
804 a.buildAppDependencyInfo(ctx)
Colin Cross30e076a2015-04-13 13:58:27 -0700805}
806
Colin Crosseb032962020-05-13 11:05:02 -0700807type appDepsInterface interface {
808 sdkVersion() sdkSpec
809 minSdkVersion() sdkSpec
810 RequiresStableAPIs(ctx android.BaseModuleContext) bool
811}
812
813func collectAppDeps(ctx android.ModuleContext, app appDepsInterface,
814 shouldCollectRecursiveNativeDeps bool,
Colin Cross1c93c292020-02-15 10:38:00 -0800815 checkNativeSdkVersion bool) ([]jniLib, []Certificate) {
Colin Crosseb032962020-05-13 11:05:02 -0700816
Colin Crossa4f08812018-10-02 22:03:40 -0700817 var jniLibs []jniLib
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900818 var certificates []Certificate
Peter Collingbournead84f972019-12-17 16:46:18 -0800819 seenModulePaths := make(map[string]bool)
Colin Crossa4f08812018-10-02 22:03:40 -0700820
Colin Crosseb032962020-05-13 11:05:02 -0700821 if checkNativeSdkVersion {
822 checkNativeSdkVersion = app.sdkVersion().specified() &&
823 app.sdkVersion().kind != sdkCorePlatform && !app.RequiresStableAPIs(ctx)
824 }
825
Peter Collingbournead84f972019-12-17 16:46:18 -0800826 ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
Colin Crossa4f08812018-10-02 22:03:40 -0700827 otherName := ctx.OtherModuleName(module)
828 tag := ctx.OtherModuleDependencyTag(module)
829
Peter Collingbournead84f972019-12-17 16:46:18 -0800830 if IsJniDepTag(tag) || tag == cc.SharedDepTag {
Colin Crossa4f08812018-10-02 22:03:40 -0700831 if dep, ok := module.(*cc.Module); ok {
Peter Collingbournead84f972019-12-17 16:46:18 -0800832 if dep.IsNdk() || dep.IsStubs() {
833 return false
834 }
835
Colin Crossa4f08812018-10-02 22:03:40 -0700836 lib := dep.OutputFile()
Peter Collingbournead84f972019-12-17 16:46:18 -0800837 path := lib.Path()
838 if seenModulePaths[path.String()] {
839 return false
840 }
841 seenModulePaths[path.String()] = true
842
Colin Crosseb032962020-05-13 11:05:02 -0700843 if checkNativeSdkVersion && dep.SdkVersion() == "" {
844 ctx.PropertyErrorf("jni_libs", "JNI dependency %q uses platform APIs, but this module does not",
845 otherName)
Colin Cross1c93c292020-02-15 10:38:00 -0800846 }
847
Colin Crossa4f08812018-10-02 22:03:40 -0700848 if lib.Valid() {
849 jniLibs = append(jniLibs, jniLib{
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700850 name: ctx.OtherModuleName(module),
851 path: path,
852 target: module.Target(),
853 coverageFile: dep.CoverageOutputFile(),
Colin Crossa4f08812018-10-02 22:03:40 -0700854 })
855 } else {
856 ctx.ModuleErrorf("dependency %q missing output file", otherName)
857 }
858 } else {
859 ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName)
Colin Crossa4f08812018-10-02 22:03:40 -0700860 }
Peter Collingbournead84f972019-12-17 16:46:18 -0800861
862 return shouldCollectRecursiveNativeDeps
863 }
864
865 if tag == certificateTag {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700866 if dep, ok := module.(*AndroidAppCertificate); ok {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900867 certificates = append(certificates, dep.Certificate)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700868 } else {
869 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName)
870 }
Colin Crossa4f08812018-10-02 22:03:40 -0700871 }
Peter Collingbournead84f972019-12-17 16:46:18 -0800872
873 return false
Colin Crossa4f08812018-10-02 22:03:40 -0700874 })
875
Colin Crossbd01e2a2018-10-04 15:21:03 -0700876 return jniLibs, certificates
Colin Crossa4f08812018-10-02 22:03:40 -0700877}
878
Artur Satayevd9b503a2020-04-27 19:05:28 +0100879func (a *AndroidApp) walkPayloadDeps(ctx android.ModuleContext,
880 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
881
882 ctx.WalkDeps(func(child, parent android.Module) bool {
883 isExternal := !a.DepIsInSameApex(ctx, child)
884 if am, ok := child.(android.ApexModule); ok {
885 do(ctx, parent, am, isExternal)
886 }
887 return !isExternal
888 })
889}
890
891func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
892 if ctx.Host() {
893 return
894 }
895
896 depsInfo := android.DepNameToDepInfoMap{}
897 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
898 depName := to.Name()
899 if info, exist := depsInfo[depName]; exist {
900 info.From = append(info.From, from.Name())
901 info.IsExternal = info.IsExternal && externalDep
902 depsInfo[depName] = info
903 } else {
904 toMinSdkVersion := "(no version)"
905 if m, ok := to.(interface{ MinSdkVersion() string }); ok {
906 if v := m.MinSdkVersion(); v != "" {
907 toMinSdkVersion = v
908 }
909 }
910 depsInfo[depName] = android.ApexModuleDepInfo{
911 To: depName,
912 From: []string{from.Name()},
913 IsExternal: externalDep,
914 MinSdkVersion: toMinSdkVersion,
915 }
916 }
917 })
918
919 a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(), depsInfo)
920}
921
Artur Satayev2b4b7bb2020-04-28 14:57:42 +0100922func (a *AndroidApp) Updatable() bool {
923 return Bool(a.appProperties.Updatable) || a.ApexModuleBase.Updatable()
924}
925
Colin Cross0ea8ba82019-06-06 14:33:29 -0700926func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800927 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
928 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000929 return ":" + certificate
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800930 }
Jaewoong Jung525443a2019-02-28 15:35:54 -0800931 return String(a.overridableAppProperties.Certificate)
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800932}
933
Jiyong Park0f80c182020-01-31 02:49:53 +0900934func (a *AndroidApp) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
935 if IsJniDepTag(ctx.OtherModuleDependencyTag(dep)) {
936 return true
937 }
938 return a.Library.DepIsInSameApex(ctx, dep)
939}
940
Jiyong Parkb7c639e2019-08-19 14:56:02 +0900941// For OutputFileProducer interface
942func (a *AndroidApp) OutputFiles(tag string) (android.Paths, error) {
943 switch tag {
944 case ".aapt.srcjar":
945 return []android.Path{a.aaptSrcJar}, nil
946 }
947 return a.Library.OutputFiles(tag)
948}
949
Jiyong Parkf7487312019-10-17 12:54:30 +0900950func (a *AndroidApp) Privileged() bool {
951 return Bool(a.appProperties.Privileged)
952}
953
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700954func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
955 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
956}
957
958func (a *AndroidApp) PreventInstall() {
959 a.appProperties.PreventInstall = true
960}
961
962func (a *AndroidApp) HideFromMake() {
963 a.appProperties.HideFromMake = true
964}
965
966func (a *AndroidApp) MarkAsCoverageVariant(coverage bool) {
967 a.appProperties.IsCoverageVariant = coverage
968}
969
970var _ cc.Coverage = (*AndroidApp)(nil)
971
Colin Cross1b16b0e2019-02-12 14:41:32 -0800972// android_app compiles sources and Android resources into an Android application package `.apk` file.
Colin Cross36242852017-06-23 15:06:31 -0700973func AndroidAppFactory() android.Module {
Colin Cross30e076a2015-04-13 13:58:27 -0700974 module := &AndroidApp{}
975
Sasha Smundak2057f822019-04-16 17:16:58 -0700976 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross66dbc0b2017-12-28 12:23:20 -0800977 module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
978
Colin Crossae5caf52018-05-22 11:11:52 -0700979 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700980 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossae5caf52018-05-22 11:11:52 -0700981
Colin Cross1c14b4e2020-06-15 16:09:53 -0700982 module.addHostAndDeviceProperties()
Colin Cross36242852017-06-23 15:06:31 -0700983 module.AddProperties(
Colin Crossa97c5d32018-03-28 14:58:31 -0700984 &module.aaptProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -0800985 &module.appProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -0700986 &module.overridableAppProperties,
987 &module.usesLibrary.usesLibraryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700988
Colin Crossa9d8bee2018-10-02 13:59:46 -0700989 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
990 return class == android.Device && ctx.Config().DevicePrefer32BitApps()
991 })
992
Colin Crossa4f08812018-10-02 22:03:40 -0700993 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
994 android.InitDefaultableModule(module)
Jaewoong Jung525443a2019-02-28 15:35:54 -0800995 android.InitOverridableModule(module, &module.appProperties.Overrides)
Jiyong Park52cd06f2019-11-11 10:14:32 +0900996 android.InitApexModule(module)
Colin Crossa4f08812018-10-02 22:03:40 -0700997
Colin Cross36242852017-06-23 15:06:31 -0700998 return module
Colin Cross30e076a2015-04-13 13:58:27 -0700999}
Colin Crossae5caf52018-05-22 11:11:52 -07001000
1001type appTestProperties struct {
1002 Instrumentation_for *string
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001003
1004 // if specified, the instrumentation target package name in the manifest is overwritten by it.
1005 Instrumentation_target_package *string
Colin Crossae5caf52018-05-22 11:11:52 -07001006}
1007
1008type AndroidTest struct {
1009 AndroidApp
1010
1011 appTestProperties appTestProperties
1012
1013 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001014
1015 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001016 data android.Paths
Colin Crossae5caf52018-05-22 11:11:52 -07001017}
1018
Jaewoong Jung0949f312019-09-11 10:25:18 -07001019func (a *AndroidTest) InstallInTestcases() bool {
1020 return true
1021}
1022
Colin Crossae5caf52018-05-22 11:11:52 -07001023func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
easoncyleeba606252020-04-30 14:57:06 +08001024 var configs []tradefed.Config
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001025 if a.appTestProperties.Instrumentation_target_package != nil {
1026 a.additionalAaptFlags = append(a.additionalAaptFlags,
1027 "--rename-instrumentation-target-package "+*a.appTestProperties.Instrumentation_target_package)
1028 } else if a.appTestProperties.Instrumentation_for != nil {
1029 // Check if the instrumentation target package is overridden.
Jaewoong Jung4102e5d2019-02-27 16:26:28 -08001030 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(*a.appTestProperties.Instrumentation_for)
1031 if overridden {
1032 a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName)
1033 }
1034 }
Colin Crossae5caf52018-05-22 11:11:52 -07001035 a.generateAndroidBuildActions(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -07001036
easoncyleeba606252020-04-30 14:57:06 +08001037 for _, module := range a.testProperties.Test_mainline_modules {
1038 configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module})
1039 }
1040
Jaewoong Jung39982342020-01-14 10:27:18 -08001041 testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config,
easoncyleeba606252020-04-30 14:57:06 +08001042 a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config, configs)
Jaewoong Jung39982342020-01-14 10:27:18 -08001043 a.testConfig = a.FixTestConfig(ctx, testConfig)
Colin Cross8a497952019-03-05 22:25:09 -08001044 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07001045}
1046
Jaewoong Jung39982342020-01-14 10:27:18 -08001047func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
1048 if testConfig == nil {
1049 return nil
1050 }
1051
1052 fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml")
1053 rule := android.NewRuleBuilder()
1054 command := rule.Command().BuiltTool(ctx, "test_config_fixer").Input(testConfig).Output(fixedConfig)
1055 fixNeeded := false
1056
1057 if ctx.ModuleName() != a.installApkName {
1058 fixNeeded = true
1059 command.FlagWithArg("--test-file-name ", a.installApkName+".apk")
1060 }
1061
1062 if a.overridableAppProperties.Package_name != nil {
1063 fixNeeded = true
1064 command.FlagWithInput("--manifest ", a.manifestPath).
1065 FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name)
1066 }
1067
1068 if fixNeeded {
1069 rule.Build(pctx, ctx, "fix_test_config", "fix test config")
1070 return fixedConfig
1071 }
1072 return testConfig
1073}
1074
Colin Cross303e21f2018-08-07 16:49:25 -07001075func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross303e21f2018-08-07 16:49:25 -07001076 a.AndroidApp.DepsMutator(ctx)
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001077}
1078
1079func (a *AndroidTest) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1080 a.AndroidApp.OverridablePropertiesDepsMutator(ctx)
Colin Cross4b964c02018-10-15 16:18:06 -07001081 if a.appTestProperties.Instrumentation_for != nil {
1082 // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac,
1083 // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so
1084 // use instrumentationForTag instead of libTag.
1085 ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for))
1086 }
Colin Crossae5caf52018-05-22 11:11:52 -07001087}
1088
Colin Cross1b16b0e2019-02-12 14:41:32 -08001089// android_test compiles test sources and Android resources into an Android application package `.apk` file and
1090// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
Colin Crossae5caf52018-05-22 11:11:52 -07001091func AndroidTestFactory() android.Module {
1092 module := &AndroidTest{}
1093
Sasha Smundak2057f822019-04-16 17:16:58 -07001094 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross5067db92018-09-17 16:46:35 -07001095
1096 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001097 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse4246ab2019-02-05 21:55:21 -08001098 module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
Colin Cross47fa9d32019-03-26 10:51:39 -07001099 module.appProperties.AlwaysPackageNativeLibs = true
Colin Cross43f08db2018-11-12 10:13:39 -08001100 module.Module.dexpreopter.isTest = true
Colin Cross1e28e3c2020-06-02 20:09:13 -07001101 module.Module.linter.test = true
Colin Crossae5caf52018-05-22 11:11:52 -07001102
Colin Cross1c14b4e2020-06-15 16:09:53 -07001103 module.addHostAndDeviceProperties()
Colin Crossae5caf52018-05-22 11:11:52 -07001104 module.AddProperties(
Colin Crossae5caf52018-05-22 11:11:52 -07001105 &module.aaptProperties,
1106 &module.appProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -07001107 &module.appTestProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -08001108 &module.overridableAppProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -07001109 &module.usesLibrary.usesLibraryProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -07001110 &module.testProperties)
Colin Crossae5caf52018-05-22 11:11:52 -07001111
Colin Crossa4f08812018-10-02 22:03:40 -07001112 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1113 android.InitDefaultableModule(module)
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001114 android.InitOverridableModule(module, &module.appProperties.Overrides)
Colin Crossae5caf52018-05-22 11:11:52 -07001115 return module
1116}
Colin Crossbd01e2a2018-10-04 15:21:03 -07001117
Colin Cross252fc6f2018-10-04 15:22:03 -07001118type appTestHelperAppProperties struct {
1119 // list of compatibility suites (for example "cts", "vts") that the module should be
1120 // installed into.
1121 Test_suites []string `android:"arch_variant"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07001122
1123 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
1124 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
1125 // explicitly.
1126 Auto_gen_config *bool
Colin Cross252fc6f2018-10-04 15:22:03 -07001127}
1128
1129type AndroidTestHelperApp struct {
1130 AndroidApp
1131
1132 appTestHelperAppProperties appTestHelperAppProperties
1133}
1134
Jaewoong Jung326a9412019-11-21 10:41:00 -08001135func (a *AndroidTestHelperApp) InstallInTestcases() bool {
1136 return true
1137}
1138
Colin Cross1b16b0e2019-02-12 14:41:32 -08001139// android_test_helper_app compiles sources and Android resources into an Android application package `.apk` file that
1140// will be used by tests, but does not produce an `AndroidTest.xml` file so the module will not be run directly as a
1141// test.
Colin Cross252fc6f2018-10-04 15:22:03 -07001142func AndroidTestHelperAppFactory() android.Module {
1143 module := &AndroidTestHelperApp{}
1144
Sasha Smundak2057f822019-04-16 17:16:58 -07001145 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross252fc6f2018-10-04 15:22:03 -07001146
1147 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse4246ab2019-02-05 21:55:21 -08001148 module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
Colin Cross47fa9d32019-03-26 10:51:39 -07001149 module.appProperties.AlwaysPackageNativeLibs = true
Colin Cross43f08db2018-11-12 10:13:39 -08001150 module.Module.dexpreopter.isTest = true
Colin Cross1e28e3c2020-06-02 20:09:13 -07001151 module.Module.linter.test = true
Colin Cross252fc6f2018-10-04 15:22:03 -07001152
Colin Cross1c14b4e2020-06-15 16:09:53 -07001153 module.addHostAndDeviceProperties()
Colin Cross252fc6f2018-10-04 15:22:03 -07001154 module.AddProperties(
Colin Cross252fc6f2018-10-04 15:22:03 -07001155 &module.aaptProperties,
1156 &module.appProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -08001157 &module.appTestHelperAppProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -07001158 &module.overridableAppProperties,
1159 &module.usesLibrary.usesLibraryProperties)
Colin Cross252fc6f2018-10-04 15:22:03 -07001160
1161 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1162 android.InitDefaultableModule(module)
Anton Hansson3d2b6b42020-01-10 15:06:01 +00001163 android.InitApexModule(module)
Colin Cross252fc6f2018-10-04 15:22:03 -07001164 return module
1165}
1166
Colin Crossbd01e2a2018-10-04 15:21:03 -07001167type AndroidAppCertificate struct {
1168 android.ModuleBase
1169 properties AndroidAppCertificateProperties
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001170 Certificate Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -07001171}
1172
1173type AndroidAppCertificateProperties struct {
1174 // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name.
1175 Certificate *string
1176}
1177
Colin Cross1b16b0e2019-02-12 14:41:32 -08001178// android_app_certificate modules can be referenced by the certificates property of android_app modules to select
1179// the signing key.
Colin Crossbd01e2a2018-10-04 15:21:03 -07001180func AndroidAppCertificateFactory() android.Module {
1181 module := &AndroidAppCertificate{}
1182 module.AddProperties(&module.properties)
1183 android.InitAndroidModule(module)
1184 return module
1185}
1186
Colin Crossbd01e2a2018-10-04 15:21:03 -07001187func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1188 cert := String(c.properties.Certificate)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001189 c.Certificate = Certificate{
Colin Cross503c1d02020-01-28 14:00:53 -08001190 Pem: android.PathForModuleSrc(ctx, cert+".x509.pem"),
1191 Key: android.PathForModuleSrc(ctx, cert+".pk8"),
Colin Crossbd01e2a2018-10-04 15:21:03 -07001192 }
1193}
Jaewoong Jung525443a2019-02-28 15:35:54 -08001194
1195type OverrideAndroidApp struct {
1196 android.ModuleBase
1197 android.OverrideModuleBase
1198}
1199
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001200func (i *OverrideAndroidApp) GenerateAndroidBuildActions(_ android.ModuleContext) {
Jaewoong Jung525443a2019-02-28 15:35:54 -08001201 // All the overrides happen in the base module.
1202 // TODO(jungjw): Check the base module type.
1203}
1204
1205// override_android_app is used to create an android_app module based on another android_app by overriding
1206// some of its properties.
1207func OverrideAndroidAppModuleFactory() android.Module {
1208 m := &OverrideAndroidApp{}
1209 m.AddProperties(&overridableAppProperties{})
1210
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001211 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung525443a2019-02-28 15:35:54 -08001212 android.InitOverrideModule(m)
1213 return m
1214}
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001215
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001216type OverrideAndroidTest struct {
1217 android.ModuleBase
1218 android.OverrideModuleBase
1219}
1220
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001221func (i *OverrideAndroidTest) GenerateAndroidBuildActions(_ android.ModuleContext) {
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001222 // All the overrides happen in the base module.
1223 // TODO(jungjw): Check the base module type.
1224}
1225
1226// override_android_test is used to create an android_app module based on another android_test by overriding
1227// some of its properties.
1228func OverrideAndroidTestModuleFactory() android.Module {
1229 m := &OverrideAndroidTest{}
1230 m.AddProperties(&overridableAppProperties{})
1231 m.AddProperties(&appTestProperties{})
1232
1233 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1234 android.InitOverrideModule(m)
1235 return m
1236}
1237
Roshan Piusb8307962020-04-27 09:42:27 -07001238type OverrideRuntimeResourceOverlay struct {
1239 android.ModuleBase
1240 android.OverrideModuleBase
1241}
1242
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001243func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(_ android.ModuleContext) {
Roshan Piusb8307962020-04-27 09:42:27 -07001244 // All the overrides happen in the base module.
1245 // TODO(jungjw): Check the base module type.
1246}
1247
1248// override_runtime_resource_overlay is used to create a module based on another
1249// runtime_resource_overlay module by overriding some of its properties.
1250func OverrideRuntimeResourceOverlayModuleFactory() android.Module {
1251 m := &OverrideRuntimeResourceOverlay{}
1252 m.AddProperties(&OverridableRuntimeResourceOverlayProperties{})
1253
1254 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1255 android.InitOverrideModule(m)
1256 return m
1257}
1258
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001259type AndroidAppImport struct {
1260 android.ModuleBase
1261 android.DefaultableModuleBase
1262 prebuilt android.Prebuilt
1263
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001264 properties AndroidAppImportProperties
1265 dpiVariants interface{}
1266 archVariants interface{}
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001267
1268 outputFile android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001269 certificate Certificate
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001270
1271 dexpreopter
Colin Cross50ddcc42019-05-16 12:28:22 -07001272
1273 usesLibrary usesLibrary
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001274
Liz Kammer7e20dda2020-05-20 14:36:30 -07001275 preprocessed bool
1276
Colin Cross70dda7e2019-10-01 22:05:35 -07001277 installPath android.InstallPath
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001278}
1279
1280type AndroidAppImportProperties struct {
1281 // A prebuilt apk to import
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001282 Apk *string
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001283
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001284 // The name of a certificate in the default certificate directory or an android_app_certificate
1285 // module name in the form ":module". Should be empty if presigned or default_dev_cert is set.
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001286 Certificate *string
1287
1288 // Set this flag to true if the prebuilt apk is already signed. The certificate property must not
1289 // be set for presigned modules.
1290 Presigned *bool
1291
Liz Kammer2bc57f62020-05-13 15:49:21 -07001292 // Name of the signing certificate lineage file.
1293 Lineage *string
1294
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001295 // Sign with the default system dev certificate. Must be used judiciously. Most imported apps
1296 // need to either specify a specific certificate or be presigned.
1297 Default_dev_cert *bool
1298
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001299 // Specifies that this app should be installed to the priv-app directory,
1300 // where the system will grant it additional privileges not available to
1301 // normal apps.
1302 Privileged *bool
1303
1304 // Names of modules to be overridden. Listed modules can only be other binaries
1305 // (in Make or Soong).
1306 // This does not completely prevent installation of the overridden binaries, but if both
1307 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1308 // from PRODUCT_PACKAGES.
1309 Overrides []string
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001310
1311 // Optional name for the installed app. If unspecified, it is derived from the module name.
1312 Filename *string
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001313}
1314
Martin Stjernholm6d415272020-01-31 17:10:36 +00001315func (a *AndroidAppImport) IsInstallable() bool {
1316 return true
1317}
1318
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001319// Updates properties with variant-specific values.
1320func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) {
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001321 config := ctx.Config()
1322
1323 dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName("Dpi_variants")
1324 // Try DPI variant matches in the reverse-priority order so that the highest priority match
1325 // overwrites everything else.
1326 // TODO(jungjw): Can we optimize this by making it priority order?
1327 for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001328 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i])
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001329 }
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001330 if config.ProductAAPTPreferredConfig() != "" {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001331 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig())
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001332 }
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001333
1334 archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName("Arch")
1335 archType := ctx.Config().Targets[android.Android][0].Arch.ArchType
1336 MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name)
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001337}
1338
Colin Cross1184b642019-12-30 18:43:07 -08001339func MergePropertiesFromVariant(ctx android.EarlyModuleContext,
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001340 dst interface{}, variantGroup reflect.Value, variant string) {
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001341 src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant))
1342 if !src.IsValid() {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001343 return
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001344 }
1345
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001346 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend)
1347 if err != nil {
1348 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
1349 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
1350 } else {
1351 panic(err)
1352 }
1353 }
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001354}
1355
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001356func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) {
1357 cert := android.SrcIsModule(String(a.properties.Certificate))
1358 if cert != "" {
1359 ctx.AddDependency(ctx.Module(), certificateTag, cert)
1360 }
Colin Cross50ddcc42019-05-16 12:28:22 -07001361
Paul Duffin250e6192019-06-07 10:44:37 +01001362 a.usesLibrary.deps(ctx, true)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001363}
1364
1365func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
1366 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001367 // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
1368 // with them may invalidate pre-existing signature data.
Liz Kammer7e20dda2020-05-20 14:36:30 -07001369 if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || a.preprocessed) {
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001370 ctx.Build(pctx, android.BuildParams{
1371 Rule: android.Cp,
1372 Output: outputPath,
1373 Input: inputPath,
1374 })
1375 return
1376 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001377 rule := android.NewRuleBuilder()
1378 rule.Command().
1379 Textf(`if (zipinfo %s 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
Colin Crossee94d6a2019-07-08 17:08:34 -07001380 BuiltTool(ctx, "zip2zip").
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001381 FlagWithInput("-i ", inputPath).
1382 FlagWithOutput("-o ", outputPath).
1383 FlagWithArg("-0 ", "'lib/**/*.so'").
1384 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
1385 rule.Build(pctx, ctx, "uncompress-embedded-jni-libs", "Uncompress embedded JIN libs")
1386}
1387
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001388// Returns whether this module should have the dex file stored uncompressed in the APK.
1389func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
Liz Kammer7e20dda2020-05-20 14:36:30 -07001390 if ctx.Config().UnbundledBuild() || a.preprocessed {
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001391 return false
1392 }
1393
1394 // Uncompress dex in APKs of privileged apps
Jiyong Parkf7487312019-10-17 12:54:30 +09001395 if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001396 return true
1397 }
1398
1399 return shouldUncompressDex(ctx, &a.dexpreopter)
1400}
1401
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001402func (a *AndroidAppImport) uncompressDex(
1403 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
1404 rule := android.NewRuleBuilder()
1405 rule.Command().
1406 Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
Colin Crossee94d6a2019-07-08 17:08:34 -07001407 BuiltTool(ctx, "zip2zip").
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001408 FlagWithInput("-i ", inputPath).
1409 FlagWithOutput("-o ", outputPath).
1410 FlagWithArg("-0 ", "'classes*.dex'").
1411 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
1412 rule.Build(pctx, ctx, "uncompress-dex", "Uncompress dex files")
1413}
1414
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001415func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001416 a.generateAndroidBuildActions(ctx)
1417}
1418
Jooyung Han65cd0f02020-03-23 20:21:11 +09001419func (a *AndroidAppImport) InstallApkName() string {
1420 return a.BaseModuleName()
1421}
1422
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001423func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001424 numCertPropsSet := 0
1425 if String(a.properties.Certificate) != "" {
1426 numCertPropsSet++
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001427 }
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001428 if Bool(a.properties.Presigned) {
1429 numCertPropsSet++
1430 }
1431 if Bool(a.properties.Default_dev_cert) {
1432 numCertPropsSet++
1433 }
1434 if numCertPropsSet != 1 {
1435 ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001436 }
1437
Colin Crosseb032962020-05-13 11:05:02 -07001438 _, certificates := collectAppDeps(ctx, a, false, false)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001439
1440 // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001441 // TODO: LOCAL_PACKAGE_SPLITS
1442
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001443 srcApk := a.prebuilt.SingleSourcePath(ctx)
Colin Cross50ddcc42019-05-16 12:28:22 -07001444
1445 if a.usesLibrary.enforceUsesLibraries() {
1446 srcApk = a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk)
1447 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001448
1449 // TODO: Install or embed JNI libraries
1450
1451 // Uncompress JNI libraries in the apk
1452 jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk")
1453 a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed.OutputPath)
1454
Kyeongkab.Namc4997142019-11-22 11:38:16 +09001455 var installDir android.InstallPath
1456 if Bool(a.properties.Privileged) {
1457 installDir = android.PathForModuleInstall(ctx, "priv-app", a.BaseModuleName())
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001458 } else if ctx.InstallInTestcases() {
1459 installDir = android.PathForModuleInstall(ctx, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch())
Kyeongkab.Namc4997142019-11-22 11:38:16 +09001460 } else {
1461 installDir = android.PathForModuleInstall(ctx, "app", a.BaseModuleName())
1462 }
1463
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001464 a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001465 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001466 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
Colin Cross50ddcc42019-05-16 12:28:22 -07001467
1468 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
1469 a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
1470 a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
1471 a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
1472
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001473 dexOutput := a.dexpreopter.dexpreopt(ctx, jnisUncompressed)
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001474 if a.dexpreopter.uncompressedDex {
1475 dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk")
1476 a.uncompressDex(ctx, dexOutput, dexUncompressed.OutputPath)
1477 dexOutput = dexUncompressed
1478 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001479
Jooyung Han65cd0f02020-03-23 20:21:11 +09001480 apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk")
1481
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001482 // TODO: Handle EXTERNAL
Liz Kammer7e20dda2020-05-20 14:36:30 -07001483
1484 // Sign or align the package if package has not been preprocessed
1485 if a.preprocessed {
1486 a.outputFile = srcApk
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001487 a.certificate = PresignedCertificate
Liz Kammer7e20dda2020-05-20 14:36:30 -07001488 } else if !Bool(a.properties.Presigned) {
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001489 // If the certificate property is empty at this point, default_dev_cert must be set to true.
1490 // Which makes processMainCert's behavior for the empty cert string WAI.
1491 certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001492 if len(certificates) != 1 {
1493 ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
1494 }
Colin Cross503c1d02020-01-28 14:00:53 -08001495 a.certificate = certificates[0]
Jooyung Han65cd0f02020-03-23 20:21:11 +09001496 signed := android.PathForModuleOut(ctx, "signed", apkFilename)
Liz Kammer2bc57f62020-05-13 15:49:21 -07001497 var lineageFile android.Path
1498 if lineage := String(a.properties.Lineage); lineage != "" {
1499 lineageFile = android.PathForModuleSrc(ctx, lineage)
1500 }
1501 SignAppPackage(ctx, signed, dexOutput, certificates, nil, lineageFile)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001502 a.outputFile = signed
1503 } else {
Jooyung Han65cd0f02020-03-23 20:21:11 +09001504 alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001505 TransformZipAlign(ctx, alignedApk, dexOutput)
1506 a.outputFile = alignedApk
Sasha Smundakc4f0ff12020-05-27 16:36:07 -07001507 a.certificate = PresignedCertificate
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001508 }
1509
1510 // TODO: Optionally compress the output apk.
1511
Jooyung Han65cd0f02020-03-23 20:21:11 +09001512 a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001513
1514 // TODO: androidmk converter jni libs
1515}
1516
1517func (a *AndroidAppImport) Prebuilt() *android.Prebuilt {
1518 return &a.prebuilt
1519}
1520
1521func (a *AndroidAppImport) Name() string {
1522 return a.prebuilt.Name(a.ModuleBase.Name())
1523}
1524
Dario Frenicde2a032019-10-27 00:29:22 +01001525func (a *AndroidAppImport) OutputFile() android.Path {
1526 return a.outputFile
1527}
1528
Jiyong Park618922e2020-01-08 13:35:43 +09001529func (a *AndroidAppImport) JacocoReportClassesFile() android.Path {
1530 return nil
1531}
1532
Colin Cross503c1d02020-01-28 14:00:53 -08001533func (a *AndroidAppImport) Certificate() Certificate {
1534 return a.certificate
1535}
1536
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001537var dpiVariantGroupType reflect.Type
1538var archVariantGroupType reflect.Type
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001539
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001540func initAndroidAppImportVariantGroupTypes() {
1541 dpiVariantGroupType = createVariantGroupType(supportedDpis, "Dpi_variants")
1542
1543 archNames := make([]string, len(android.ArchTypeList()))
1544 for i, archType := range android.ArchTypeList() {
1545 archNames[i] = archType.Name
1546 }
1547 archVariantGroupType = createVariantGroupType(archNames, "Arch")
1548}
1549
1550// Populates all variant struct properties at creation time.
1551func (a *AndroidAppImport) populateAllVariantStructs() {
1552 a.dpiVariants = reflect.New(dpiVariantGroupType).Interface()
1553 a.AddProperties(a.dpiVariants)
1554
1555 a.archVariants = reflect.New(archVariantGroupType).Interface()
1556 a.AddProperties(a.archVariants)
1557}
1558
Jiyong Parkf7487312019-10-17 12:54:30 +09001559func (a *AndroidAppImport) Privileged() bool {
1560 return Bool(a.properties.Privileged)
1561}
1562
Colin Crosseb032962020-05-13 11:05:02 -07001563func (a *AndroidAppImport) sdkVersion() sdkSpec {
1564 return sdkSpecFrom("")
1565}
1566
1567func (a *AndroidAppImport) minSdkVersion() sdkSpec {
1568 return sdkSpecFrom("")
1569}
1570
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001571func createVariantGroupType(variants []string, variantGroupName string) reflect.Type {
1572 props := reflect.TypeOf((*AndroidAppImportProperties)(nil))
1573
1574 variantFields := make([]reflect.StructField, len(variants))
1575 for i, variant := range variants {
1576 variantFields[i] = reflect.StructField{
1577 Name: proptools.FieldNameForProperty(variant),
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001578 Type: props,
1579 }
1580 }
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001581
1582 variantGroupStruct := reflect.StructOf(variantFields)
1583 return reflect.StructOf([]reflect.StructField{
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001584 {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001585 Name: variantGroupName,
1586 Type: variantGroupStruct,
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001587 },
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001588 })
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001589}
1590
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001591// android_app_import imports a prebuilt apk with additional processing specified in the module.
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001592// DPI-specific apk source files can be specified using dpi_variants. Example:
1593//
1594// android_app_import {
1595// name: "example_import",
1596// apk: "prebuilts/example.apk",
1597// dpi_variants: {
1598// mdpi: {
1599// apk: "prebuilts/example_mdpi.apk",
1600// },
1601// xhdpi: {
1602// apk: "prebuilts/example_xhdpi.apk",
1603// },
1604// },
1605// certificate: "PRESIGNED",
1606// }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001607func AndroidAppImportFactory() android.Module {
1608 module := &AndroidAppImport{}
1609 module.AddProperties(&module.properties)
1610 module.AddProperties(&module.dexpreoptProperties)
Colin Cross50ddcc42019-05-16 12:28:22 -07001611 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001612 module.populateAllVariantStructs()
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001613 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001614 module.processVariants(ctx)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001615 })
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001616
Jaewoong Jung0feed892020-05-26 20:10:08 -07001617 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1618 android.InitDefaultableModule(module)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001619 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001620
1621 return module
1622}
Colin Cross50ddcc42019-05-16 12:28:22 -07001623
Liz Kammer7e20dda2020-05-20 14:36:30 -07001624type androidTestImportProperties struct {
1625 // Whether the prebuilt apk can be installed without additional processing. Default is false.
1626 Preprocessed *bool
1627}
1628
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001629type AndroidTestImport struct {
1630 AndroidAppImport
1631
1632 testProperties testProperties
1633
Liz Kammer7e20dda2020-05-20 14:36:30 -07001634 testImportProperties androidTestImportProperties
1635
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001636 data android.Paths
1637}
1638
1639func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Liz Kammer7e20dda2020-05-20 14:36:30 -07001640 a.preprocessed = Bool(a.testImportProperties.Preprocessed)
1641
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001642 a.generateAndroidBuildActions(ctx)
1643
1644 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
1645}
1646
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001647func (a *AndroidTestImport) InstallInTestcases() bool {
1648 return true
1649}
1650
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001651// android_test_import imports a prebuilt test apk with additional processing specified in the
1652// module. DPI or arch variant configurations can be made as with android_app_import.
1653func AndroidTestImportFactory() android.Module {
1654 module := &AndroidTestImport{}
1655 module.AddProperties(&module.properties)
1656 module.AddProperties(&module.dexpreoptProperties)
1657 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
1658 module.AddProperties(&module.testProperties)
Liz Kammer7e20dda2020-05-20 14:36:30 -07001659 module.AddProperties(&module.testImportProperties)
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001660 module.populateAllVariantStructs()
1661 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
1662 module.processVariants(ctx)
1663 })
1664
Colin Crossf30c4532020-05-06 22:29:10 -07001665 module.dexpreopter.isTest = true
1666
Jaewoong Junga689ffe2020-05-01 15:50:08 -07001667 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1668 android.InitDefaultableModule(module)
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001669 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
1670
1671 return module
1672}
1673
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001674type RuntimeResourceOverlay struct {
1675 android.ModuleBase
1676 android.DefaultableModuleBase
Roshan Piusb8307962020-04-27 09:42:27 -07001677 android.OverridableModuleBase
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001678 aapt
1679
Roshan Piusb8307962020-04-27 09:42:27 -07001680 properties RuntimeResourceOverlayProperties
1681 overridableProperties OverridableRuntimeResourceOverlayProperties
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001682
Jaewoong Jung78ec5d82020-01-31 10:11:47 -08001683 certificate Certificate
1684
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001685 outputFile android.Path
1686 installDir android.InstallPath
1687}
1688
1689type RuntimeResourceOverlayProperties struct {
1690 // the name of a certificate in the default certificate directory or an android_app_certificate
1691 // module name in the form ":module".
1692 Certificate *string
1693
Liz Kammer7fe241f2020-05-19 16:15:25 -07001694 // Name of the signing certificate lineage file.
1695 Lineage *string
1696
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001697 // optional theme name. If specified, the overlay package will be applied
1698 // only when the ro.boot.vendor.overlay.theme system property is set to the same value.
1699 Theme *string
1700
1701 // if not blank, set to the version of the sdk to compile against.
1702 // Defaults to compiling against the current platform.
1703 Sdk_version *string
1704
1705 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
1706 // Defaults to sdk_version if not set.
1707 Min_sdk_version *string
Jaewoong Jungca095d72020-04-09 16:15:30 -07001708
1709 // list of android_library modules whose resources are extracted and linked against statically
1710 Static_libs []string
1711
1712 // list of android_app modules whose resources are extracted and linked against
1713 Resource_libs []string
Jaewoong Jungbfc6ac02020-04-24 15:22:40 -07001714
1715 // Names of modules to be overridden. Listed modules can only be other overlays
1716 // (in Make or Soong).
1717 // This does not completely prevent installation of the overridden overlays, but if both
1718 // overlays would be installed by default (in PRODUCT_PACKAGES) the other overlay will be removed
1719 // from PRODUCT_PACKAGES.
1720 Overrides []string
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001721}
1722
1723func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) {
1724 sdkDep := decodeSdkDep(ctx, sdkContext(r))
1725 if sdkDep.hasFrameworkLibs() {
1726 r.aapt.deps(ctx, sdkDep)
1727 }
1728
1729 cert := android.SrcIsModule(String(r.properties.Certificate))
1730 if cert != "" {
1731 ctx.AddDependency(ctx.Module(), certificateTag, cert)
1732 }
Jaewoong Jungca095d72020-04-09 16:15:30 -07001733
1734 ctx.AddVariationDependencies(nil, staticLibTag, r.properties.Static_libs...)
1735 ctx.AddVariationDependencies(nil, libTag, r.properties.Resource_libs...)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001736}
1737
1738func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1739 // Compile and link resources
1740 r.aapt.hasNoCode = true
Jaewoong Jungf0f747c2020-01-24 10:30:02 -08001741 // Do not remove resources without default values nor dedupe resource configurations with the same value
Roshan Piusb8307962020-04-27 09:42:27 -07001742 aaptLinkFlags := []string{"--no-resource-deduping", "--no-resource-removal"}
1743 // Allow the override of "package name" and "overlay target package name"
1744 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1745 if overridden || r.overridableProperties.Package_name != nil {
1746 // The product override variable has a priority over the package_name property.
1747 if !overridden {
1748 manifestPackageName = *r.overridableProperties.Package_name
1749 }
1750 aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName)
1751 }
1752 if r.overridableProperties.Target_package_name != nil {
1753 aaptLinkFlags = append(aaptLinkFlags,
1754 "--rename-overlay-target-package "+*r.overridableProperties.Target_package_name)
1755 }
1756 r.aapt.buildActions(ctx, r, aaptLinkFlags...)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001757
1758 // Sign the built package
Colin Crosseb032962020-05-13 11:05:02 -07001759 _, certificates := collectAppDeps(ctx, r, false, false)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001760 certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
1761 signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
Liz Kammer7fe241f2020-05-19 16:15:25 -07001762 var lineageFile android.Path
1763 if lineage := String(r.properties.Lineage); lineage != "" {
1764 lineageFile = android.PathForModuleSrc(ctx, lineage)
1765 }
1766 SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, nil, lineageFile)
Jaewoong Jung78ec5d82020-01-31 10:11:47 -08001767 r.certificate = certificates[0]
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001768
1769 r.outputFile = signed
1770 r.installDir = android.PathForModuleInstall(ctx, "overlay", String(r.properties.Theme))
1771 ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
1772}
1773
Jiyong Park6a927c42020-01-21 02:03:43 +09001774func (r *RuntimeResourceOverlay) sdkVersion() sdkSpec {
1775 return sdkSpecFrom(String(r.properties.Sdk_version))
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001776}
1777
1778func (r *RuntimeResourceOverlay) systemModules() string {
1779 return ""
1780}
1781
Jiyong Park6a927c42020-01-21 02:03:43 +09001782func (r *RuntimeResourceOverlay) minSdkVersion() sdkSpec {
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001783 if r.properties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +09001784 return sdkSpecFrom(*r.properties.Min_sdk_version)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001785 }
1786 return r.sdkVersion()
1787}
1788
Jiyong Park6a927c42020-01-21 02:03:43 +09001789func (r *RuntimeResourceOverlay) targetSdkVersion() sdkSpec {
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001790 return r.sdkVersion()
1791}
1792
1793// runtime_resource_overlay generates a resource-only apk file that can overlay application and
1794// system resources at run time.
1795func RuntimeResourceOverlayFactory() android.Module {
1796 module := &RuntimeResourceOverlay{}
1797 module.AddProperties(
1798 &module.properties,
Roshan Piusb8307962020-04-27 09:42:27 -07001799 &module.aaptProperties,
1800 &module.overridableProperties)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001801
Roshan Piusb8307962020-04-27 09:42:27 -07001802 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1803 android.InitDefaultableModule(module)
1804 android.InitOverridableModule(module, &module.properties.Overrides)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001805 return module
1806}
1807
Colin Cross50ddcc42019-05-16 12:28:22 -07001808type UsesLibraryProperties struct {
1809 // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file.
1810 Uses_libs []string
1811
1812 // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file with
1813 // required=false.
1814 Optional_uses_libs []string
1815
1816 // If true, the list of uses_libs and optional_uses_libs modules must match the AndroidManifest.xml file. Defaults
1817 // to true if either uses_libs or optional_uses_libs is set. Will unconditionally default to true in the future.
1818 Enforce_uses_libs *bool
1819}
1820
1821// usesLibrary provides properties and helper functions for AndroidApp and AndroidAppImport to verify that the
1822// <uses-library> tags that end up in the manifest of an APK match the ones known to the build system through the
1823// uses_libs and optional_uses_libs properties. The build system's values are used by dexpreopt to preopt apps
1824// with knowledge of their shared libraries.
1825type usesLibrary struct {
1826 usesLibraryProperties UsesLibraryProperties
1827}
1828
Paul Duffin250e6192019-06-07 10:44:37 +01001829func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs bool) {
Colin Cross3245b2c2019-06-07 13:18:09 -07001830 if !ctx.Config().UnbundledBuild() {
1831 ctx.AddVariationDependencies(nil, usesLibTag, u.usesLibraryProperties.Uses_libs...)
1832 ctx.AddVariationDependencies(nil, usesLibTag, u.presentOptionalUsesLibs(ctx)...)
Paul Duffin250e6192019-06-07 10:44:37 +01001833 // Only add these extra dependencies if the module depends on framework libs. This avoids
1834 // creating a cyclic dependency:
1835 // e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res.
1836 if hasFrameworkLibs {
Colin Cross3245b2c2019-06-07 13:18:09 -07001837 // dexpreopt/dexpreopt.go needs the paths to the dex jars of these libraries in case construct_context.sh needs
1838 // to pass them to dex2oat. Add them as a dependency so we can determine the path to the dex jar of each
1839 // library to dexpreopt.
1840 ctx.AddVariationDependencies(nil, usesLibTag,
1841 "org.apache.http.legacy",
1842 "android.hidl.base-V1.0-java",
1843 "android.hidl.manager-V1.0-java")
1844 }
Colin Cross50ddcc42019-05-16 12:28:22 -07001845 }
1846}
1847
1848// presentOptionalUsesLibs returns optional_uses_libs after filtering out MissingUsesLibraries, which don't exist in the
1849// build.
1850func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []string {
1851 optionalUsesLibs, _ := android.FilterList(u.usesLibraryProperties.Optional_uses_libs, ctx.Config().MissingUsesLibraries())
1852 return optionalUsesLibs
1853}
1854
1855// usesLibraryPaths returns a map of module names of shared library dependencies to the paths to their dex jars.
1856func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) map[string]android.Path {
1857 usesLibPaths := make(map[string]android.Path)
1858
1859 if !ctx.Config().UnbundledBuild() {
1860 ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
1861 if lib, ok := m.(Dependency); ok {
1862 if dexJar := lib.DexJar(); dexJar != nil {
1863 usesLibPaths[ctx.OtherModuleName(m)] = dexJar
1864 } else {
1865 ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must produce a dex jar, does it have installable: true?",
1866 ctx.OtherModuleName(m))
1867 }
1868 } else if ctx.Config().AllowMissingDependencies() {
1869 ctx.AddMissingDependencies([]string{ctx.OtherModuleName(m)})
1870 } else {
1871 ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library",
1872 ctx.OtherModuleName(m))
1873 }
1874 })
1875 }
1876
1877 return usesLibPaths
1878}
1879
1880// enforceUsesLibraries returns true of <uses-library> tags should be checked against uses_libs and optional_uses_libs
1881// properties. Defaults to true if either of uses_libs or optional_uses_libs is specified. Will default to true
1882// unconditionally in the future.
1883func (u *usesLibrary) enforceUsesLibraries() bool {
1884 defaultEnforceUsesLibs := len(u.usesLibraryProperties.Uses_libs) > 0 ||
1885 len(u.usesLibraryProperties.Optional_uses_libs) > 0
1886 return BoolDefault(u.usesLibraryProperties.Enforce_uses_libs, defaultEnforceUsesLibs)
1887}
1888
1889// verifyUsesLibrariesManifest checks the <uses-library> tags in an AndroidManifest.xml against the ones specified
1890// in the uses_libs and optional_uses_libs properties. It returns the path to a copy of the manifest.
1891func (u *usesLibrary) verifyUsesLibrariesManifest(ctx android.ModuleContext, manifest android.Path) android.Path {
1892 outputFile := android.PathForModuleOut(ctx, "manifest_check", "AndroidManifest.xml")
1893
1894 rule := android.NewRuleBuilder()
Colin Crossee94d6a2019-07-08 17:08:34 -07001895 cmd := rule.Command().BuiltTool(ctx, "manifest_check").
Colin Cross50ddcc42019-05-16 12:28:22 -07001896 Flag("--enforce-uses-libraries").
1897 Input(manifest).
1898 FlagWithOutput("-o ", outputFile)
1899
1900 for _, lib := range u.usesLibraryProperties.Uses_libs {
1901 cmd.FlagWithArg("--uses-library ", lib)
1902 }
1903
1904 for _, lib := range u.usesLibraryProperties.Optional_uses_libs {
1905 cmd.FlagWithArg("--optional-uses-library ", lib)
1906 }
1907
1908 rule.Build(pctx, ctx, "verify_uses_libraries", "verify <uses-library>")
1909
1910 return outputFile
1911}
1912
1913// verifyUsesLibrariesAPK checks the <uses-library> tags in the manifest of an APK against the ones specified
1914// in the uses_libs and optional_uses_libs properties. It returns the path to a copy of the APK.
1915func (u *usesLibrary) verifyUsesLibrariesAPK(ctx android.ModuleContext, apk android.Path) android.Path {
1916 outputFile := android.PathForModuleOut(ctx, "verify_uses_libraries", apk.Base())
1917
1918 rule := android.NewRuleBuilder()
1919 aapt := ctx.Config().HostToolPath(ctx, "aapt")
1920 rule.Command().
1921 Textf("aapt_binary=%s", aapt.String()).Implicit(aapt).
1922 Textf(`uses_library_names="%s"`, strings.Join(u.usesLibraryProperties.Uses_libs, " ")).
1923 Textf(`optional_uses_library_names="%s"`, strings.Join(u.usesLibraryProperties.Optional_uses_libs, " ")).
1924 Tool(android.PathForSource(ctx, "build/make/core/verify_uses_libraries.sh")).Input(apk)
1925 rule.Command().Text("cp -f").Input(apk).Output(outputFile)
1926
1927 rule.Build(pctx, ctx, "verify_uses_libraries", "verify <uses-library>")
1928
1929 return outputFile
1930}