blob: 05c7581403097653e1584636e84f29cc02880e97 [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 Smundaka7856c02020-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"
Ulya Trafimovichd4bcea42020-06-03 14:57:22 +010031 "android/soong/dexpreopt"
Colin Cross303e21f2018-08-07 16:49:25 -070032 "android/soong/tradefed"
Colin Cross30e076a2015-04-13 13:58:27 -070033)
34
Jaewoong Jung3e18b192019-06-11 12:25:34 -070035var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"}
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070036
Colin Cross3bc7ffa2017-11-22 16:19:37 -080037func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000038 RegisterAppBuildComponents(android.InitRegistrationContext)
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -070039
40 initAndroidAppImportVariantGroupTypes()
Colin Cross3bc7ffa2017-11-22 16:19:37 -080041}
42
Paul Duffinf9b1da02019-12-18 19:51:55 +000043func RegisterAppBuildComponents(ctx android.RegistrationContext) {
44 ctx.RegisterModuleType("android_app", AndroidAppFactory)
45 ctx.RegisterModuleType("android_test", AndroidTestFactory)
46 ctx.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory)
47 ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
48 ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
49 ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
Roshan Pius4df2bc72020-04-27 09:42:27 -070050 ctx.RegisterModuleType("override_runtime_resource_overlay", OverrideRuntimeResourceOverlayModuleFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +000051 ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
52 ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080053 ctx.RegisterModuleType("runtime_resource_overlay", RuntimeResourceOverlayFactory)
Sasha Smundaka7856c02020-04-23 09:49:59 -070054 ctx.RegisterModuleType("android_app_set", AndroidApkSetFactory)
55}
56
57type AndroidAppSetProperties struct {
58 // APK Set path
59 Set *string
60
61 // Specifies that this app should be installed to the priv-app directory,
62 // where the system will grant it additional privileges not available to
63 // normal apps.
64 Privileged *bool
65
66 // APKs in this set use prerelease SDK version
67 Prerelease *bool
68
69 // Names of modules to be overridden. Listed modules can only be other apps
70 // (in Make or Soong).
71 Overrides []string
72}
73
74type AndroidAppSet struct {
75 android.ModuleBase
76 android.DefaultableModuleBase
77 prebuilt android.Prebuilt
78
79 properties AndroidAppSetProperties
80 packedOutput android.WritablePath
81 masterFile string
82}
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
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700100var TargetCpuAbi = map[string]string{
Sasha Smundaka7856c02020-04-23 09:49:59 -0700101 "arm": "ARMEABI_V7A",
102 "arm64": "ARM64_V8A",
103 "x86": "X86",
104 "x86_64": "X86_64",
105}
106
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700107func SupportedAbis(ctx android.ModuleContext) []string {
Sasha Smundaka7856c02020-04-23 09:49:59 -0700108 abiName := func(archVar string, deviceArch string) string {
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700109 if abi, found := TargetCpuAbi[deviceArch]; found {
Sasha Smundaka7856c02020-04-23 09:49:59 -0700110 return abi
111 }
112 ctx.ModuleErrorf("Invalid %s: %s", archVar, deviceArch)
113 return "BAD_ABI"
114 }
115
116 result := []string{abiName("TARGET_ARCH", ctx.DeviceConfig().DeviceArch())}
117 if s := ctx.DeviceConfig().DeviceSecondaryArch(); s != "" {
118 result = append(result, abiName("TARGET_2ND_ARCH", s))
119 }
120 return result
121}
122
123func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) {
124 as.packedOutput = android.PathForModuleOut(ctx, "extracted.zip")
125 // We are assuming here that the master file in the APK
126 // set has `.apk` suffix. If it doesn't the build will fail.
127 // APK sets containing APEX files are handled elsewhere.
128 as.masterFile = ctx.ModuleName() + ".apk"
129 screenDensities := "all"
130 if dpis := ctx.Config().ProductAAPTPrebuiltDPI(); len(dpis) > 0 {
131 screenDensities = strings.ToUpper(strings.Join(dpis, ","))
132 }
133 // TODO(asmundak): handle locales.
134 // TODO(asmundak): do we support device features
135 ctx.Build(pctx,
136 android.BuildParams{
137 Rule: extractMatchingApks,
138 Description: "Extract APKs from APK set",
139 Output: as.packedOutput,
140 Inputs: android.Paths{as.prebuilt.SingleSourcePath(ctx)},
141 Args: map[string]string{
Jaewoong Jungfa00c062020-05-14 14:15:24 -0700142 "abis": strings.Join(SupportedAbis(ctx), ","),
Sasha Smundaka7856c02020-04-23 09:49:59 -0700143 "allow-prereleased": strconv.FormatBool(proptools.Bool(as.properties.Prerelease)),
144 "screen-densities": screenDensities,
145 "sdk-version": ctx.Config().PlatformSdkVersion(),
146 "stem": ctx.ModuleName(),
147 },
148 })
149 // TODO(asmundak): add this (it's wrong now, will cause copying extracted.zip)
150 /*
151 var installDir android.InstallPath
152 if Bool(as.properties.Privileged) {
153 installDir = android.PathForModuleInstall(ctx, "priv-app", as.BaseModuleName())
154 } else if ctx.InstallInTestcases() {
155 installDir = android.PathForModuleInstall(ctx, as.BaseModuleName(), ctx.DeviceConfig().DeviceArch())
156 } else {
157 installDir = android.PathForModuleInstall(ctx, "app", as.BaseModuleName())
158 }
159 ctx.InstallFile(installDir, as.masterFile", as.packedOutput)
160 */
161}
162
163// android_app_set extracts a set of APKs based on the target device
164// configuration and installs this set as "split APKs".
165// The set will always contain `base-master.apk` and every APK built
166// to the target device. All density-specific APK will be included, too,
167// unless PRODUCT_APPT_PREBUILT_DPI is defined (should contain comma-sepearated
168// list of density names (LDPI, MDPI, HDPI, etc.)
169func AndroidApkSetFactory() android.Module {
170 module := &AndroidAppSet{}
171 module.AddProperties(&module.properties)
172 InitJavaModule(module, android.DeviceSupported)
173 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Set")
174 return module
Paul Duffinf9b1da02019-12-18 19:51:55 +0000175}
176
Colin Cross30e076a2015-04-13 13:58:27 -0700177// AndroidManifest.xml merging
178// package splits
179
Colin Crossfabb6082018-02-20 17:22:23 -0800180type appProperties struct {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700181 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
Colin Cross7d5136f2015-05-11 13:39:40 -0700182 Additional_certificates []string
183
184 // If set, create package-export.apk, which other packages can
185 // use to get PRODUCT-agnostic resource data like IDs and type definitions.
Nan Zhangea568a42017-11-08 21:20:04 -0800186 Export_package_resources *bool
Colin Cross7d5136f2015-05-11 13:39:40 -0700187
Colin Cross16056062017-12-13 22:46:28 -0800188 // Specifies that this app should be installed to the priv-app directory,
189 // where the system will grant it additional privileges not available to
190 // normal apps.
191 Privileged *bool
Colin Crossa97c5d32018-03-28 14:58:31 -0700192
193 // list of resource labels to generate individual resource packages
194 Package_splits []string
Jason Monkd4122be2018-08-10 09:33:36 -0400195
196 // Names of modules to be overridden. Listed modules can only be other binaries
197 // (in Make or Soong).
198 // This does not completely prevent installation of the overridden binaries, but if both
199 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
200 // from PRODUCT_PACKAGES.
201 Overrides []string
Colin Crossa4f08812018-10-02 22:03:40 -0700202
203 // list of native libraries that will be provided in or alongside the resulting jar
204 Jni_libs []string `android:"arch_variant"`
205
Colin Cross7204cf02020-05-06 17:51:39 -0700206 // if true, use JNI libraries that link against platform APIs even if this module sets
Colin Crossee87c602020-02-19 16:57:15 -0800207 // sdk_version.
208 Jni_uses_platform_apis *bool
209
Colin Cross7204cf02020-05-06 17:51:39 -0700210 // if true, use JNI libraries that link against SDK APIs even if this module does not set
211 // sdk_version.
212 Jni_uses_sdk_apis *bool
213
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700214 // STL library to use for JNI libraries.
215 Stl *string `android:"arch_variant"`
216
Colin Crosse4246ab2019-02-05 21:55:21 -0800217 // Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest
218 // 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 +0900219 // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to true for
220 // android_app modules that are embedded to APEXes, defaults to false for other module types where the native
221 // libraries are generally preinstalled outside the APK.
Colin Crosse4246ab2019-02-05 21:55:21 -0800222 Use_embedded_native_libs *bool
Colin Cross46abdad2019-02-07 13:07:08 -0800223
224 // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that
225 // they are used from inside the APK at runtime.
226 Use_embedded_dex *bool
Colin Cross47fa9d32019-03-26 10:51:39 -0700227
228 // Forces native libraries to always be packaged into the APK,
229 // Use_embedded_native_libs still selects whether they are stored uncompressed and aligned or compressed.
230 // True for android_test* modules.
231 AlwaysPackageNativeLibs bool `blueprint:"mutated"`
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700232
233 // If set, find and merge all NOTICE files that this module and its dependencies have and store
234 // it in the APK as an asset.
235 Embed_notices *bool
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700236
237 // cc.Coverage related properties
238 PreventInstall bool `blueprint:"mutated"`
239 HideFromMake bool `blueprint:"mutated"`
240 IsCoverageVariant bool `blueprint:"mutated"`
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100241
242 // Whether this app is considered mainline updatable or not. When set to true, this will enforce
Artur Satayevf40fc852020-04-16 13:43:02 +0100243 // additional rules to make sure an app can safely be updated. Default is false.
244 // Prefer using other specific properties if build behaviour must be changed; avoid using this
245 // flag for anything but neverallow rules (unless the behaviour change is invisible to owners).
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100246 Updatable *bool
Colin Cross7d5136f2015-05-11 13:39:40 -0700247}
248
Jaewoong Jung525443a2019-02-28 15:35:54 -0800249// android_app properties that can be overridden by override_android_app
250type overridableAppProperties struct {
251 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
252 // or an android_app_certificate module name in the form ":module".
253 Certificate *string
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700254
Liz Kammere2b27f42020-05-07 13:24:05 -0700255 // Name of the signing certificate lineage file.
256 Lineage *string
257
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700258 // the package name of this app. The package name in the manifest file is used if one was not given.
259 Package_name *string
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800260
261 // the logging parent of this app.
262 Logging_parent *string
Jaewoong Jung525443a2019-02-28 15:35:54 -0800263}
264
Roshan Pius4df2bc72020-04-27 09:42:27 -0700265// runtime_resource_overlay properties that can be overridden by override_runtime_resource_overlay
266type OverridableRuntimeResourceOverlayProperties struct {
267 // the package name of this app. The package name in the manifest file is used if one was not given.
268 Package_name *string
269
270 // the target package name of this overlay app. The target package name in the manifest file is used if one was not given.
271 Target_package_name *string
272}
273
Colin Cross30e076a2015-04-13 13:58:27 -0700274type AndroidApp struct {
Colin Crossa97c5d32018-03-28 14:58:31 -0700275 Library
276 aapt
Jaewoong Jung525443a2019-02-28 15:35:54 -0800277 android.OverridableModuleBase
Colin Crossa97c5d32018-03-28 14:58:31 -0700278
Colin Cross50ddcc42019-05-16 12:28:22 -0700279 usesLibrary usesLibrary
280
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900281 certificate Certificate
Colin Cross30e076a2015-04-13 13:58:27 -0700282
Colin Crossfabb6082018-02-20 17:22:23 -0800283 appProperties appProperties
Colin Crossae5caf52018-05-22 11:11:52 -0700284
Jaewoong Jung525443a2019-02-28 15:35:54 -0800285 overridableAppProperties overridableAppProperties
286
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700287 installJniLibs []jniLib
288 jniCoverageOutputs android.Paths
Colin Crossf6237212018-10-29 23:14:58 -0700289
290 bundleFile android.Path
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800291
292 // the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES.
293 installApkName string
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800294
Colin Cross70dda7e2019-10-01 22:05:35 -0700295 installDir android.InstallPath
Jaewoong Jung0949f312019-09-11 10:25:18 -0700296
Jaewoong Jung7dd4ae22019-09-27 17:13:15 -0700297 onDeviceDir string
298
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800299 additionalAaptFlags []string
Jaewoong Jung98772792019-07-01 17:15:13 -0700300
301 noticeOutputs android.NoticeOutputs
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900302
303 overriddenManifestPackageName string
Artur Satayev1111b842020-04-27 19:05:28 +0100304
305 android.ApexBundleDepsInfo
Colin Crosse1731a52017-12-14 11:22:55 -0800306}
307
Martin Stjernholm6d415272020-01-31 17:10:36 +0000308func (a *AndroidApp) IsInstallable() bool {
309 return Bool(a.properties.Installable)
310}
311
Colin Cross89c31582018-04-30 15:55:11 -0700312func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
313 return nil
314}
315
Colin Cross66f78822018-05-02 12:58:28 -0700316func (a *AndroidApp) ExportedStaticPackages() android.Paths {
317 return nil
318}
319
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900320func (a *AndroidApp) OutputFile() android.Path {
321 return a.outputFile
322}
323
Colin Cross503c1d02020-01-28 14:00:53 -0800324func (a *AndroidApp) Certificate() Certificate {
325 return a.certificate
326}
327
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700328func (a *AndroidApp) JniCoverageOutputs() android.Paths {
329 return a.jniCoverageOutputs
330}
331
Colin Crossa97c5d32018-03-28 14:58:31 -0700332var _ AndroidLibraryDependency = (*AndroidApp)(nil)
333
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900334type Certificate struct {
Colin Cross503c1d02020-01-28 14:00:53 -0800335 Pem, Key android.Path
336 presigned bool
337}
338
339var presignedCertificate = Certificate{presigned: true}
340
341func (c Certificate) AndroidMkString() string {
342 if c.presigned {
343 return "PRESIGNED"
344 } else {
345 return c.Pem.String()
346 }
Colin Cross30e076a2015-04-13 13:58:27 -0700347}
348
Colin Cross46c9b8b2017-06-22 16:51:17 -0700349func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
350 a.Module.deps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700351
Jiyong Park6a927c42020-01-21 02:03:43 +0900352 if String(a.appProperties.Stl) == "c++_shared" && !a.sdkVersion().specified() {
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700353 ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared")
354 }
355
Paul Duffin250e6192019-06-07 10:44:37 +0100356 sdkDep := decodeSdkDep(ctx, sdkContext(a))
357 if sdkDep.hasFrameworkLibs() {
358 a.aapt.deps(ctx, sdkDep)
Colin Cross30e076a2015-04-13 13:58:27 -0700359 }
Colin Crossa4f08812018-10-02 22:03:40 -0700360
Colin Cross3c007702020-05-08 11:20:24 -0700361 usesSDK := a.sdkVersion().specified() && a.sdkVersion().kind != sdkCorePlatform
362
363 if usesSDK && Bool(a.appProperties.Jni_uses_sdk_apis) {
364 ctx.PropertyErrorf("jni_uses_sdk_apis",
365 "can only be set for modules that do not set sdk_version")
366 } else if !usesSDK && Bool(a.appProperties.Jni_uses_platform_apis) {
367 ctx.PropertyErrorf("jni_uses_platform_apis",
368 "can only be set for modules that set sdk_version")
369 }
370
Peter Collingbournead84f972019-12-17 16:46:18 -0800371 tag := &jniDependencyTag{}
Colin Crossa4f08812018-10-02 22:03:40 -0700372 for _, jniTarget := range ctx.MultiTargets() {
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700373 variation := append(jniTarget.Variations(),
374 blueprint.Variation{Mutator: "link", Variation: "shared"})
Colin Crossc511bc52020-04-07 16:50:32 +0000375
376 // If the app builds against an Android SDK use the SDK variant of JNI dependencies
377 // unless jni_uses_platform_apis is set.
Colin Crossc2d24052020-05-13 11:05:02 -0700378 // Don't require the SDK variant for apps that are shipped on vendor, etc., as they already
379 // have stable APIs through the VNDK.
380 if (usesSDK && !a.RequiresStableAPIs(ctx) &&
381 !Bool(a.appProperties.Jni_uses_platform_apis)) ||
Colin Cross7204cf02020-05-06 17:51:39 -0700382 Bool(a.appProperties.Jni_uses_sdk_apis) {
Colin Crossc511bc52020-04-07 16:50:32 +0000383 variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
384 }
Colin Crossa4f08812018-10-02 22:03:40 -0700385 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
386 }
Colin Cross50ddcc42019-05-16 12:28:22 -0700387
Paul Duffin250e6192019-06-07 10:44:37 +0100388 a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700389}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700390
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700391func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800392 cert := android.SrcIsModule(a.getCertString(ctx))
Colin Crossbd01e2a2018-10-04 15:21:03 -0700393 if cert != "" {
394 ctx.AddDependency(ctx.Module(), certificateTag, cert)
395 }
396
397 for _, cert := range a.appProperties.Additional_certificates {
398 cert = android.SrcIsModule(cert)
399 if cert != "" {
400 ctx.AddDependency(ctx.Module(), certificateTag, cert)
401 } else {
402 ctx.PropertyErrorf("additional_certificates",
403 `must be names of android_app_certificate modules in the form ":module"`)
404 }
405 }
Colin Cross30e076a2015-04-13 13:58:27 -0700406}
407
Jeongik Cha538c0d02019-07-11 15:54:27 +0900408func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
409 a.generateAndroidBuildActions(ctx)
410}
411
Colin Cross46c9b8b2017-06-22 16:51:17 -0700412func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100413 a.checkAppSdkVersions(ctx)
Colin Crossae5caf52018-05-22 11:11:52 -0700414 a.generateAndroidBuildActions(ctx)
415}
416
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100417func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
Artur Satayev849f8442020-04-28 14:57:42 +0100418 if a.Updatable() {
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100419 if !a.sdkVersion().stable() {
420 ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.sdkVersion())
421 }
Artur Satayevf40fc852020-04-16 13:43:02 +0100422 if String(a.deviceProperties.Min_sdk_version) == "" {
423 ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
424 }
Jooyung Hanbbc3fb72020-04-29 14:01:06 +0900425 if minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx); err == nil {
426 a.checkJniLibsSdkVersion(ctx, minSdkVersion)
427 } else {
428 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
429 }
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100430 }
431
432 a.checkPlatformAPI(ctx)
433 a.checkSdkVersions(ctx)
434}
435
Jooyung Hanbbc3fb72020-04-29 14:01:06 +0900436// If an updatable APK sets min_sdk_version, min_sdk_vesion of JNI libs should match with it.
437// This check is enforced for "updatable" APKs (including APK-in-APEX).
438// b/155209650: until min_sdk_version is properly supported, use sdk_version instead.
439// because, sdk_version is overridden by min_sdk_version (if set as smaller)
440// and linkType is checked with dependencies so we can be sure that the whole dependency tree
441// will meet the requirements.
442func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVersion sdkVersion) {
443 // It's enough to check direct JNI deps' sdk_version because all transitive deps from JNI deps are checked in cc.checkLinkType()
444 ctx.VisitDirectDeps(func(m android.Module) {
445 if !IsJniDepTag(ctx.OtherModuleDependencyTag(m)) {
446 return
447 }
448 dep, _ := m.(*cc.Module)
449 jniSdkVersion, err := android.ApiStrToNum(ctx, dep.SdkVersion())
450 if err != nil || int(minSdkVersion) < jniSdkVersion {
451 ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)",
452 dep.SdkVersion(), minSdkVersion, ctx.ModuleName())
453 return
454 }
455
456 })
457}
458
Sasha Smundak6ad77252019-05-01 13:16:22 -0700459// Returns true if the native libraries should be stored in the APK uncompressed and the
Colin Crosse4246ab2019-02-05 21:55:21 -0800460// extractNativeLibs application flag should be set to false in the manifest.
Sasha Smundak6ad77252019-05-01 13:16:22 -0700461func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
Jiyong Park6a927c42020-01-21 02:03:43 +0900462 minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx)
Colin Crosse4246ab2019-02-05 21:55:21 -0800463 if err != nil {
464 ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
465 }
466
Jiyong Park52cd06f2019-11-11 10:14:32 +0900467 return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
468 !a.IsForPlatform()
Colin Crosse4246ab2019-02-05 21:55:21 -0800469}
470
Colin Cross43f08db2018-11-12 10:13:39 -0800471// Returns whether this module should have the dex file stored uncompressed in the APK.
472func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
Colin Cross46abdad2019-02-07 13:07:08 -0800473 if Bool(a.appProperties.Use_embedded_dex) {
474 return true
475 }
476
Colin Cross53a87f52019-06-25 13:35:30 -0700477 // Uncompress dex in APKs of privileged apps (even for unbundled builds, they may
478 // be preinstalled as prebuilts).
Jiyong Parkf7487312019-10-17 12:54:30 +0900479 if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000480 return true
481 }
482
Colin Cross53a87f52019-06-25 13:35:30 -0700483 if ctx.Config().UnbundledBuild() {
484 return false
485 }
486
Jaewoong Jungacf18d72019-05-02 14:55:29 -0700487 return shouldUncompressDex(ctx, &a.dexpreopter)
Colin Cross5a0dcd52018-10-05 14:20:06 -0700488}
489
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700490func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
491 return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
Jiyong Park52cd06f2019-11-11 10:14:32 +0900492 !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700493}
494
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900495func (a *AndroidApp) OverriddenManifestPackageName() string {
496 return a.overriddenManifestPackageName
497}
498
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800499func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
David Brazdild25060a2019-02-18 18:24:16 +0000500 a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis)
501
Jaewoong Jungc27ab662019-05-30 15:51:14 -0700502 // Ask manifest_fixer to add or update the application element indicating this app has no code.
503 a.aapt.hasNoCode = !a.hasCode(ctx)
504
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800505 aaptLinkFlags := []string{}
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800506
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800507 // 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 -0800508 hasProduct := android.PrefixInList(a.aaptProperties.Aaptflags, "--product")
Colin Crosse78dcd32018-04-19 15:25:19 -0700509 if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800510 aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
Colin Crosse78dcd32018-04-19 15:25:19 -0700511 }
512
Dan Willemsen72be5902018-10-24 20:24:57 -0700513 if !Bool(a.aaptProperties.Aapt_include_all_resources) {
514 // Product AAPT config
515 for _, aaptConfig := range ctx.Config().ProductAAPTConfig() {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800516 aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig)
Dan Willemsen72be5902018-10-24 20:24:57 -0700517 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700518
Dan Willemsen72be5902018-10-24 20:24:57 -0700519 // Product AAPT preferred config
520 if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800521 aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig())
Dan Willemsen72be5902018-10-24 20:24:57 -0700522 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700523 }
524
Jiyong Park7f67f482019-01-05 12:57:48 +0900525 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700526 if overridden || a.overridableAppProperties.Package_name != nil {
527 // The product override variable has a priority over the package_name property.
528 if !overridden {
529 manifestPackageName = *a.overridableAppProperties.Package_name
530 }
Liz Kammer1d5983b2020-05-19 19:15:37 +0000531 aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName)
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900532 a.overriddenManifestPackageName = manifestPackageName
Jiyong Park7f67f482019-01-05 12:57:48 +0900533 }
534
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800535 aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...)
536
Colin Crosse560c4a2019-03-19 16:03:11 -0700537 a.aapt.splitNames = a.appProperties.Package_splits
Colin Cross50ddcc42019-05-16 12:28:22 -0700538 a.aapt.sdkLibraries = a.exportedSdkLibs
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800539 a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent)
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800540 a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...)
Colin Cross30e076a2015-04-13 13:58:27 -0700541
Colin Cross46c9b8b2017-06-22 16:51:17 -0700542 // apps manifests are handled by aapt, don't let Module see them
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700543 a.properties.Manifest = nil
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800544}
Colin Cross30e076a2015-04-13 13:58:27 -0700545
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800546func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) {
Colin Cross89c31582018-04-30 15:55:11 -0700547 var staticLibProguardFlagFiles android.Paths
548 ctx.VisitDirectDeps(func(m android.Module) {
549 if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
550 staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
551 }
552 })
553
554 staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
555
556 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
557 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800558}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800559
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800560func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
Colin Cross43f08db2018-11-12 10:13:39 -0800561
562 var installDir string
563 if ctx.ModuleName() == "framework-res" {
564 // framework-res.apk is installed as system/framework/framework-res.apk
565 installDir = "framework"
Jiyong Parkf7487312019-10-17 12:54:30 +0900566 } else if a.Privileged() {
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800567 installDir = filepath.Join("priv-app", a.installApkName)
Colin Cross43f08db2018-11-12 10:13:39 -0800568 } else {
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800569 installDir = filepath.Join("app", a.installApkName)
Colin Cross43f08db2018-11-12 10:13:39 -0800570 }
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800571 a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
David Srbeckye033cba2020-05-20 22:20:28 +0100572 if a.deviceProperties.Uncompress_dex == nil {
573 // If the value was not force-set by the user, use reasonable default based on the module.
574 a.deviceProperties.Uncompress_dex = proptools.BoolPtr(a.shouldUncompressDex(ctx))
575 }
576 a.dexpreopter.uncompressedDex = *a.deviceProperties.Uncompress_dex
Colin Cross50ddcc42019-05-16 12:28:22 -0700577 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
578 a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
579 a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
580 a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
581 a.dexpreopter.manifestFile = a.mergedManifestFile
582
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800583 if ctx.ModuleName() != "framework-res" {
584 a.Module.compile(ctx, a.aaptSrcJar)
585 }
Colin Cross30e076a2015-04-13 13:58:27 -0700586
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800587 return a.maybeStrippedDexJarFile
588}
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800589
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800590func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath {
Colin Crossa4f08812018-10-02 22:03:40 -0700591 var jniJarFile android.WritablePath
Colin Crossa4f08812018-10-02 22:03:40 -0700592 if len(jniLibs) > 0 {
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700593 if a.shouldEmbedJnis(ctx) {
Colin Crossa4f08812018-10-02 22:03:40 -0700594 jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
Sasha Smundak6ad77252019-05-01 13:16:22 -0700595 TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.useEmbeddedNativeLibs(ctx))
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700596 for _, jni := range jniLibs {
597 if jni.coverageFile.Valid() {
Jaewoong Jung46984ee2020-04-07 13:07:55 -0700598 // Only collect coverage for the first target arch if this is a multilib target.
599 // TODO(jungjw): Ideally, we want to collect both reports, but that would cause coverage
600 // data file path collisions since the current coverage file path format doesn't contain
601 // arch-related strings. This is fine for now though; the code coverage team doesn't use
602 // multi-arch targets such as test_suite_* for coverage collections yet.
603 //
604 // Work with the team to come up with a new format that handles multilib modules properly
605 // and change this.
606 if len(ctx.Config().Targets[android.Android]) == 1 ||
607 ctx.Config().Targets[android.Android][0].Arch.ArchType == jni.target.Arch.ArchType {
608 a.jniCoverageOutputs = append(a.jniCoverageOutputs, jni.coverageFile.Path())
609 }
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700610 }
611 }
Colin Crossa4f08812018-10-02 22:03:40 -0700612 } else {
613 a.installJniLibs = jniLibs
614 }
615 }
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800616 return jniJarFile
617}
Colin Crossa4f08812018-10-02 22:03:40 -0700618
Jaewoong Jung0949f312019-09-11 10:25:18 -0700619func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext) {
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700620 // Collect NOTICE files from all dependencies.
621 seenModules := make(map[android.Module]bool)
622 noticePathSet := make(map[android.Path]bool)
623
624 ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
625 // Have we already seen this?
626 if _, ok := seenModules[child]; ok {
627 return false
628 }
629 seenModules[child] = true
630
631 // Skip host modules.
632 if child.Target().Os.Class == android.Host || child.Target().Os.Class == android.HostCross {
633 return false
634 }
635
Bob Badoura75b0572020-02-18 20:21:55 -0800636 paths := child.(android.Module).NoticeFiles()
637 if len(paths) > 0 {
638 for _, path := range paths {
639 noticePathSet[path] = true
640 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700641 }
642 return true
643 })
644
645 // If the app has one, add it too.
Bob Badoura75b0572020-02-18 20:21:55 -0800646 if len(a.NoticeFiles()) > 0 {
647 for _, path := range a.NoticeFiles() {
648 noticePathSet[path] = true
649 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700650 }
651
652 if len(noticePathSet) == 0 {
Jaewoong Jung98772792019-07-01 17:15:13 -0700653 return
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700654 }
655 var noticePaths []android.Path
656 for path := range noticePathSet {
657 noticePaths = append(noticePaths, path)
658 }
659 sort.Slice(noticePaths, func(i, j int) bool {
660 return noticePaths[i].String() < noticePaths[j].String()
661 })
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700662
Jaewoong Jung0949f312019-09-11 10:25:18 -0700663 a.noticeOutputs = android.BuildNoticeOutput(ctx, a.installDir, a.installApkName+".apk", noticePaths)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700664}
665
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700666// Reads and prepends a main cert from the default cert dir if it hasn't been set already, i.e. it
667// isn't a cert module reference. Also checks and enforces system cert restriction if applicable.
668func processMainCert(m android.ModuleBase, certPropValue string, certificates []Certificate, ctx android.ModuleContext) []Certificate {
669 if android.SrcIsModule(certPropValue) == "" {
670 var mainCert Certificate
671 if certPropValue != "" {
672 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
673 mainCert = Certificate{
Colin Cross503c1d02020-01-28 14:00:53 -0800674 Pem: defaultDir.Join(ctx, certPropValue+".x509.pem"),
675 Key: defaultDir.Join(ctx, certPropValue+".pk8"),
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700676 }
677 } else {
678 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Colin Cross503c1d02020-01-28 14:00:53 -0800679 mainCert = Certificate{
680 Pem: pem,
681 Key: key,
682 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700683 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700684 certificates = append([]Certificate{mainCert}, certificates...)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700685 }
686
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700687 if !m.Platform() {
688 certPath := certificates[0].Pem.String()
Jeongik Chac9464142019-01-07 12:07:27 +0900689 systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String()
690 if strings.HasPrefix(certPath, systemCertPath) {
691 enforceSystemCert := ctx.Config().EnforceSystemCertificate()
692 whitelist := ctx.Config().EnforceSystemCertificateWhitelist()
693
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700694 if enforceSystemCert && !inList(m.Name(), whitelist) {
Jeongik Chac9464142019-01-07 12:07:27 +0900695 ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.")
696 }
697 }
698 }
699
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700700 return certificates
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800701}
702
Jooyung Han39ee1192020-03-23 20:21:11 +0900703func (a *AndroidApp) InstallApkName() string {
704 return a.installApkName
705}
706
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800707func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross50ddcc42019-05-16 12:28:22 -0700708 var apkDeps android.Paths
709
Jeongik Cha538c0d02019-07-11 15:54:27 +0900710 a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx)
711 a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
712
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800713 // Check if the install APK name needs to be overridden.
Jaewoong Jung525443a2019-02-28 15:35:54 -0800714 a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Name())
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800715
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700716 if ctx.ModuleName() == "framework-res" {
717 // framework-res.apk is installed as system/framework/framework-res.apk
Jaewoong Jung0949f312019-09-11 10:25:18 -0700718 a.installDir = android.PathForModuleInstall(ctx, "framework")
Jiyong Parkf7487312019-10-17 12:54:30 +0900719 } else if a.Privileged() {
Jaewoong Jung0949f312019-09-11 10:25:18 -0700720 a.installDir = android.PathForModuleInstall(ctx, "priv-app", a.installApkName)
721 } else if ctx.InstallInTestcases() {
Jaewoong Jung326a9412019-11-21 10:41:00 -0800722 a.installDir = android.PathForModuleInstall(ctx, a.installApkName, ctx.DeviceConfig().DeviceArch())
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700723 } else {
Jaewoong Jung0949f312019-09-11 10:25:18 -0700724 a.installDir = android.PathForModuleInstall(ctx, "app", a.installApkName)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700725 }
Jaewoong Jung7dd4ae22019-09-27 17:13:15 -0700726 a.onDeviceDir = android.InstallPathToOnDevicePath(ctx, a.installDir)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700727
Jaewoong Jung0949f312019-09-11 10:25:18 -0700728 a.noticeBuildActions(ctx)
Jaewoong Jung98772792019-07-01 17:15:13 -0700729 if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") {
730 a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput
731 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700732
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800733 // Process all building blocks, from AAPT to certificates.
734 a.aaptBuildActions(ctx)
735
Colin Cross50ddcc42019-05-16 12:28:22 -0700736 if a.usesLibrary.enforceUsesLibraries() {
737 manifestCheckFile := a.usesLibrary.verifyUsesLibrariesManifest(ctx, a.mergedManifestFile)
738 apkDeps = append(apkDeps, manifestCheckFile)
739 }
740
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800741 a.proguardBuildActions(ctx)
742
743 dexJarFile := a.dexBuildActions(ctx)
744
Colin Crossc2d24052020-05-13 11:05:02 -0700745 jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800746 jniJarFile := a.jniBuildActions(jniLibs, ctx)
747
748 if ctx.Failed() {
749 return
750 }
751
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700752 certificates := processMainCert(a.ModuleBase, a.getCertString(ctx), certificateDeps, ctx)
753 a.certificate = certificates[0]
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800754
755 // Build a final signed app package.
Jaewoong Jung5a498812019-11-07 14:14:38 -0800756 packageFile := android.PathForModuleOut(ctx, a.installApkName+".apk")
Liz Kammere2b27f42020-05-07 13:24:05 -0700757 var lineageFile android.Path
758 if lineage := String(a.overridableAppProperties.Lineage); lineage != "" {
759 lineageFile = android.PathForModuleSrc(ctx, lineage)
760 }
761 CreateAndSignAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates, apkDeps, lineageFile)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800762 a.outputFile = packageFile
763
Colin Crosse560c4a2019-03-19 16:03:11 -0700764 for _, split := range a.aapt.splits {
765 // Sign the split APKs
Jaewoong Jung5a498812019-11-07 14:14:38 -0800766 packageFile := android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk")
Liz Kammere2b27f42020-05-07 13:24:05 -0700767 CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, lineageFile)
Colin Crosse560c4a2019-03-19 16:03:11 -0700768 a.extraOutputFiles = append(a.extraOutputFiles, packageFile)
769 }
770
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800771 // Build an app bundle.
Colin Crossf6237212018-10-29 23:14:58 -0700772 bundleFile := android.PathForModuleOut(ctx, "base.zip")
773 BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
774 a.bundleFile = bundleFile
775
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800776 // Install the app package.
Jiyong Park8ba50f92019-11-13 15:01:01 +0900777 if (Bool(a.Module.properties.Installable) || ctx.Host()) && a.IsForPlatform() {
778 ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
779 for _, extra := range a.extraOutputFiles {
780 ctx.InstallFile(a.installDir, extra.Base(), extra)
781 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800782 }
Artur Satayev1111b842020-04-27 19:05:28 +0100783
784 a.buildAppDependencyInfo(ctx)
Colin Cross30e076a2015-04-13 13:58:27 -0700785}
786
Colin Crossc2d24052020-05-13 11:05:02 -0700787type appDepsInterface interface {
788 sdkVersion() sdkSpec
789 minSdkVersion() sdkSpec
790 RequiresStableAPIs(ctx android.BaseModuleContext) bool
791}
792
793func collectAppDeps(ctx android.ModuleContext, app appDepsInterface,
794 shouldCollectRecursiveNativeDeps bool,
Colin Cross094cde42020-02-15 10:38:00 -0800795 checkNativeSdkVersion bool) ([]jniLib, []Certificate) {
Colin Crossc2d24052020-05-13 11:05:02 -0700796
Colin Crossa4f08812018-10-02 22:03:40 -0700797 var jniLibs []jniLib
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900798 var certificates []Certificate
Peter Collingbournead84f972019-12-17 16:46:18 -0800799 seenModulePaths := make(map[string]bool)
Colin Crossa4f08812018-10-02 22:03:40 -0700800
Colin Crossc2d24052020-05-13 11:05:02 -0700801 if checkNativeSdkVersion {
802 checkNativeSdkVersion = app.sdkVersion().specified() &&
803 app.sdkVersion().kind != sdkCorePlatform && !app.RequiresStableAPIs(ctx)
804 }
805
Peter Collingbournead84f972019-12-17 16:46:18 -0800806 ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
Colin Crossa4f08812018-10-02 22:03:40 -0700807 otherName := ctx.OtherModuleName(module)
808 tag := ctx.OtherModuleDependencyTag(module)
809
Peter Collingbournead84f972019-12-17 16:46:18 -0800810 if IsJniDepTag(tag) || tag == cc.SharedDepTag {
Colin Crossa4f08812018-10-02 22:03:40 -0700811 if dep, ok := module.(*cc.Module); ok {
Peter Collingbournead84f972019-12-17 16:46:18 -0800812 if dep.IsNdk() || dep.IsStubs() {
813 return false
814 }
815
Colin Crossa4f08812018-10-02 22:03:40 -0700816 lib := dep.OutputFile()
Peter Collingbournead84f972019-12-17 16:46:18 -0800817 path := lib.Path()
818 if seenModulePaths[path.String()] {
819 return false
820 }
821 seenModulePaths[path.String()] = true
822
Colin Crossc2d24052020-05-13 11:05:02 -0700823 if checkNativeSdkVersion && dep.SdkVersion() == "" {
824 ctx.PropertyErrorf("jni_libs", "JNI dependency %q uses platform APIs, but this module does not",
825 otherName)
Colin Cross094cde42020-02-15 10:38:00 -0800826 }
827
Colin Crossa4f08812018-10-02 22:03:40 -0700828 if lib.Valid() {
829 jniLibs = append(jniLibs, jniLib{
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700830 name: ctx.OtherModuleName(module),
831 path: path,
832 target: module.Target(),
833 coverageFile: dep.CoverageOutputFile(),
Colin Crossa4f08812018-10-02 22:03:40 -0700834 })
835 } else {
836 ctx.ModuleErrorf("dependency %q missing output file", otherName)
837 }
838 } else {
839 ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName)
Colin Crossa4f08812018-10-02 22:03:40 -0700840 }
Peter Collingbournead84f972019-12-17 16:46:18 -0800841
842 return shouldCollectRecursiveNativeDeps
843 }
844
845 if tag == certificateTag {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700846 if dep, ok := module.(*AndroidAppCertificate); ok {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900847 certificates = append(certificates, dep.Certificate)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700848 } else {
849 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName)
850 }
Colin Crossa4f08812018-10-02 22:03:40 -0700851 }
Peter Collingbournead84f972019-12-17 16:46:18 -0800852
853 return false
Colin Crossa4f08812018-10-02 22:03:40 -0700854 })
855
Colin Crossbd01e2a2018-10-04 15:21:03 -0700856 return jniLibs, certificates
Colin Crossa4f08812018-10-02 22:03:40 -0700857}
858
Artur Satayev1111b842020-04-27 19:05:28 +0100859func (a *AndroidApp) walkPayloadDeps(ctx android.ModuleContext,
860 do func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool)) {
861
862 ctx.WalkDeps(func(child, parent android.Module) bool {
863 isExternal := !a.DepIsInSameApex(ctx, child)
864 if am, ok := child.(android.ApexModule); ok {
865 do(ctx, parent, am, isExternal)
866 }
867 return !isExternal
868 })
869}
870
871func (a *AndroidApp) buildAppDependencyInfo(ctx android.ModuleContext) {
872 if ctx.Host() {
873 return
874 }
875
876 depsInfo := android.DepNameToDepInfoMap{}
877 a.walkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) {
878 depName := to.Name()
879 if info, exist := depsInfo[depName]; exist {
880 info.From = append(info.From, from.Name())
881 info.IsExternal = info.IsExternal && externalDep
882 depsInfo[depName] = info
883 } else {
884 toMinSdkVersion := "(no version)"
885 if m, ok := to.(interface{ MinSdkVersion() string }); ok {
886 if v := m.MinSdkVersion(); v != "" {
887 toMinSdkVersion = v
888 }
889 }
890 depsInfo[depName] = android.ApexModuleDepInfo{
891 To: depName,
892 From: []string{from.Name()},
893 IsExternal: externalDep,
894 MinSdkVersion: toMinSdkVersion,
895 }
896 }
897 })
898
899 a.ApexBundleDepsInfo.BuildDepsInfoLists(ctx, a.MinSdkVersion(), depsInfo)
900}
901
Artur Satayev849f8442020-04-28 14:57:42 +0100902func (a *AndroidApp) Updatable() bool {
903 return Bool(a.appProperties.Updatable) || a.ApexModuleBase.Updatable()
904}
905
Colin Cross0ea8ba82019-06-06 14:33:29 -0700906func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800907 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
908 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000909 return ":" + certificate
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800910 }
Jaewoong Jung525443a2019-02-28 15:35:54 -0800911 return String(a.overridableAppProperties.Certificate)
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800912}
913
Jiyong Park0f80c182020-01-31 02:49:53 +0900914func (a *AndroidApp) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
915 if IsJniDepTag(ctx.OtherModuleDependencyTag(dep)) {
916 return true
917 }
918 return a.Library.DepIsInSameApex(ctx, dep)
919}
920
Jiyong Parkb7c639e2019-08-19 14:56:02 +0900921// For OutputFileProducer interface
922func (a *AndroidApp) OutputFiles(tag string) (android.Paths, error) {
923 switch tag {
924 case ".aapt.srcjar":
925 return []android.Path{a.aaptSrcJar}, nil
926 }
927 return a.Library.OutputFiles(tag)
928}
929
Jiyong Parkf7487312019-10-17 12:54:30 +0900930func (a *AndroidApp) Privileged() bool {
931 return Bool(a.appProperties.Privileged)
932}
933
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700934func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
935 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
936}
937
938func (a *AndroidApp) PreventInstall() {
939 a.appProperties.PreventInstall = true
940}
941
942func (a *AndroidApp) HideFromMake() {
943 a.appProperties.HideFromMake = true
944}
945
946func (a *AndroidApp) MarkAsCoverageVariant(coverage bool) {
947 a.appProperties.IsCoverageVariant = coverage
948}
949
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400950func (a *AndroidApp) EnableCoverageIfNeeded() {}
951
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700952var _ cc.Coverage = (*AndroidApp)(nil)
953
Colin Cross1b16b0e2019-02-12 14:41:32 -0800954// android_app compiles sources and Android resources into an Android application package `.apk` file.
Colin Cross36242852017-06-23 15:06:31 -0700955func AndroidAppFactory() android.Module {
Colin Cross30e076a2015-04-13 13:58:27 -0700956 module := &AndroidApp{}
957
Sasha Smundak2057f822019-04-16 17:16:58 -0700958 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross66dbc0b2017-12-28 12:23:20 -0800959 module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
960
Colin Crossae5caf52018-05-22 11:11:52 -0700961 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700962 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossae5caf52018-05-22 11:11:52 -0700963
Colin Cross36242852017-06-23 15:06:31 -0700964 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700965 &module.Module.properties,
966 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800967 &module.Module.dexpreoptProperties,
Colin Crossa97c5d32018-03-28 14:58:31 -0700968 &module.Module.protoProperties,
969 &module.aaptProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -0800970 &module.appProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -0700971 &module.overridableAppProperties,
972 &module.usesLibrary.usesLibraryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700973
Colin Crossa9d8bee2018-10-02 13:59:46 -0700974 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
975 return class == android.Device && ctx.Config().DevicePrefer32BitApps()
976 })
977
Colin Crossa4f08812018-10-02 22:03:40 -0700978 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
979 android.InitDefaultableModule(module)
Jaewoong Jung525443a2019-02-28 15:35:54 -0800980 android.InitOverridableModule(module, &module.appProperties.Overrides)
Jiyong Park52cd06f2019-11-11 10:14:32 +0900981 android.InitApexModule(module)
Colin Crossa4f08812018-10-02 22:03:40 -0700982
Colin Cross36242852017-06-23 15:06:31 -0700983 return module
Colin Cross30e076a2015-04-13 13:58:27 -0700984}
Colin Crossae5caf52018-05-22 11:11:52 -0700985
986type appTestProperties struct {
Liz Kammer6b0c5522020-04-28 16:10:55 -0700987 // The name of the android_app module that the tests will run against.
Colin Crossae5caf52018-05-22 11:11:52 -0700988 Instrumentation_for *string
Jaewoong Jung26dedd32019-06-06 08:45:58 -0700989
990 // if specified, the instrumentation target package name in the manifest is overwritten by it.
991 Instrumentation_target_package *string
Colin Crossae5caf52018-05-22 11:11:52 -0700992}
993
994type AndroidTest struct {
995 AndroidApp
996
997 appTestProperties appTestProperties
998
999 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001000
1001 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001002 data android.Paths
Colin Crossae5caf52018-05-22 11:11:52 -07001003}
1004
Jaewoong Jung0949f312019-09-11 10:25:18 -07001005func (a *AndroidTest) InstallInTestcases() bool {
1006 return true
1007}
1008
Colin Crossae5caf52018-05-22 11:11:52 -07001009func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
easoncylee5bcff5d2020-04-30 14:57:06 +08001010 var configs []tradefed.Config
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001011 if a.appTestProperties.Instrumentation_target_package != nil {
1012 a.additionalAaptFlags = append(a.additionalAaptFlags,
1013 "--rename-instrumentation-target-package "+*a.appTestProperties.Instrumentation_target_package)
1014 } else if a.appTestProperties.Instrumentation_for != nil {
1015 // Check if the instrumentation target package is overridden.
Jaewoong Jung4102e5d2019-02-27 16:26:28 -08001016 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(*a.appTestProperties.Instrumentation_for)
1017 if overridden {
1018 a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName)
1019 }
1020 }
Colin Crossae5caf52018-05-22 11:11:52 -07001021 a.generateAndroidBuildActions(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -07001022
easoncylee5bcff5d2020-04-30 14:57:06 +08001023 for _, module := range a.testProperties.Test_mainline_modules {
1024 configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module})
1025 }
1026
Jaewoong Jung39982342020-01-14 10:27:18 -08001027 testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config,
easoncylee5bcff5d2020-04-30 14:57:06 +08001028 a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config, configs)
Jaewoong Jung39982342020-01-14 10:27:18 -08001029 a.testConfig = a.FixTestConfig(ctx, testConfig)
Colin Cross8a497952019-03-05 22:25:09 -08001030 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07001031}
1032
Jaewoong Jung39982342020-01-14 10:27:18 -08001033func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
1034 if testConfig == nil {
1035 return nil
1036 }
1037
1038 fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml")
1039 rule := android.NewRuleBuilder()
1040 command := rule.Command().BuiltTool(ctx, "test_config_fixer").Input(testConfig).Output(fixedConfig)
1041 fixNeeded := false
1042
1043 if ctx.ModuleName() != a.installApkName {
1044 fixNeeded = true
1045 command.FlagWithArg("--test-file-name ", a.installApkName+".apk")
1046 }
1047
1048 if a.overridableAppProperties.Package_name != nil {
1049 fixNeeded = true
1050 command.FlagWithInput("--manifest ", a.manifestPath).
1051 FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name)
1052 }
1053
1054 if fixNeeded {
1055 rule.Build(pctx, ctx, "fix_test_config", "fix test config")
1056 return fixedConfig
1057 }
1058 return testConfig
1059}
1060
Colin Cross303e21f2018-08-07 16:49:25 -07001061func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross303e21f2018-08-07 16:49:25 -07001062 a.AndroidApp.DepsMutator(ctx)
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001063}
1064
1065func (a *AndroidTest) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
1066 a.AndroidApp.OverridablePropertiesDepsMutator(ctx)
Colin Cross4b964c02018-10-15 16:18:06 -07001067 if a.appTestProperties.Instrumentation_for != nil {
1068 // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac,
1069 // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so
1070 // use instrumentationForTag instead of libTag.
1071 ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for))
1072 }
Colin Crossae5caf52018-05-22 11:11:52 -07001073}
1074
Colin Cross1b16b0e2019-02-12 14:41:32 -08001075// android_test compiles test sources and Android resources into an Android application package `.apk` file and
1076// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
Colin Crossae5caf52018-05-22 11:11:52 -07001077func AndroidTestFactory() android.Module {
1078 module := &AndroidTest{}
1079
Sasha Smundak2057f822019-04-16 17:16:58 -07001080 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross5067db92018-09-17 16:46:35 -07001081
1082 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001083 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse4246ab2019-02-05 21:55:21 -08001084 module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
Colin Cross47fa9d32019-03-26 10:51:39 -07001085 module.appProperties.AlwaysPackageNativeLibs = true
Colin Cross43f08db2018-11-12 10:13:39 -08001086 module.Module.dexpreopter.isTest = true
Colin Crossae5caf52018-05-22 11:11:52 -07001087
1088 module.AddProperties(
1089 &module.Module.properties,
1090 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001091 &module.Module.dexpreoptProperties,
Colin Crossae5caf52018-05-22 11:11:52 -07001092 &module.Module.protoProperties,
1093 &module.aaptProperties,
1094 &module.appProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -07001095 &module.appTestProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -08001096 &module.overridableAppProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -07001097 &module.usesLibrary.usesLibraryProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -07001098 &module.testProperties)
Colin Crossae5caf52018-05-22 11:11:52 -07001099
Colin Crossa4f08812018-10-02 22:03:40 -07001100 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1101 android.InitDefaultableModule(module)
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001102 android.InitOverridableModule(module, &module.appProperties.Overrides)
Colin Crossae5caf52018-05-22 11:11:52 -07001103 return module
1104}
Colin Crossbd01e2a2018-10-04 15:21:03 -07001105
Colin Cross252fc6f2018-10-04 15:22:03 -07001106type appTestHelperAppProperties struct {
1107 // list of compatibility suites (for example "cts", "vts") that the module should be
1108 // installed into.
1109 Test_suites []string `android:"arch_variant"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07001110
1111 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
1112 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
1113 // explicitly.
1114 Auto_gen_config *bool
Colin Cross252fc6f2018-10-04 15:22:03 -07001115}
1116
1117type AndroidTestHelperApp struct {
1118 AndroidApp
1119
1120 appTestHelperAppProperties appTestHelperAppProperties
1121}
1122
Jaewoong Jung326a9412019-11-21 10:41:00 -08001123func (a *AndroidTestHelperApp) InstallInTestcases() bool {
1124 return true
1125}
1126
Colin Cross1b16b0e2019-02-12 14:41:32 -08001127// android_test_helper_app compiles sources and Android resources into an Android application package `.apk` file that
1128// will be used by tests, but does not produce an `AndroidTest.xml` file so the module will not be run directly as a
1129// test.
Colin Cross252fc6f2018-10-04 15:22:03 -07001130func AndroidTestHelperAppFactory() android.Module {
1131 module := &AndroidTestHelperApp{}
1132
Sasha Smundak2057f822019-04-16 17:16:58 -07001133 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross252fc6f2018-10-04 15:22:03 -07001134
1135 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse4246ab2019-02-05 21:55:21 -08001136 module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
Colin Cross47fa9d32019-03-26 10:51:39 -07001137 module.appProperties.AlwaysPackageNativeLibs = true
Colin Cross43f08db2018-11-12 10:13:39 -08001138 module.Module.dexpreopter.isTest = true
Colin Cross252fc6f2018-10-04 15:22:03 -07001139
1140 module.AddProperties(
1141 &module.Module.properties,
1142 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001143 &module.Module.dexpreoptProperties,
Colin Cross252fc6f2018-10-04 15:22:03 -07001144 &module.Module.protoProperties,
1145 &module.aaptProperties,
1146 &module.appProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -08001147 &module.appTestHelperAppProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -07001148 &module.overridableAppProperties,
1149 &module.usesLibrary.usesLibraryProperties)
Colin Cross252fc6f2018-10-04 15:22:03 -07001150
1151 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1152 android.InitDefaultableModule(module)
Anton Hansson3d2b6b42020-01-10 15:06:01 +00001153 android.InitApexModule(module)
Colin Cross252fc6f2018-10-04 15:22:03 -07001154 return module
1155}
1156
Colin Crossbd01e2a2018-10-04 15:21:03 -07001157type AndroidAppCertificate struct {
1158 android.ModuleBase
1159 properties AndroidAppCertificateProperties
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001160 Certificate Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -07001161}
1162
1163type AndroidAppCertificateProperties struct {
1164 // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name.
1165 Certificate *string
1166}
1167
Colin Cross1b16b0e2019-02-12 14:41:32 -08001168// android_app_certificate modules can be referenced by the certificates property of android_app modules to select
1169// the signing key.
Colin Crossbd01e2a2018-10-04 15:21:03 -07001170func AndroidAppCertificateFactory() android.Module {
1171 module := &AndroidAppCertificate{}
1172 module.AddProperties(&module.properties)
1173 android.InitAndroidModule(module)
1174 return module
1175}
1176
Colin Crossbd01e2a2018-10-04 15:21:03 -07001177func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1178 cert := String(c.properties.Certificate)
Jiyong Parkc00cbd92018-10-30 21:20:05 +09001179 c.Certificate = Certificate{
Colin Cross503c1d02020-01-28 14:00:53 -08001180 Pem: android.PathForModuleSrc(ctx, cert+".x509.pem"),
1181 Key: android.PathForModuleSrc(ctx, cert+".pk8"),
Colin Crossbd01e2a2018-10-04 15:21:03 -07001182 }
1183}
Jaewoong Jung525443a2019-02-28 15:35:54 -08001184
1185type OverrideAndroidApp struct {
1186 android.ModuleBase
1187 android.OverrideModuleBase
1188}
1189
1190func (i *OverrideAndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1191 // All the overrides happen in the base module.
1192 // TODO(jungjw): Check the base module type.
1193}
1194
1195// override_android_app is used to create an android_app module based on another android_app by overriding
1196// some of its properties.
1197func OverrideAndroidAppModuleFactory() android.Module {
1198 m := &OverrideAndroidApp{}
1199 m.AddProperties(&overridableAppProperties{})
1200
Jaewoong Jungb639a6a2019-05-10 15:16:29 -07001201 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung525443a2019-02-28 15:35:54 -08001202 android.InitOverrideModule(m)
1203 return m
1204}
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001205
Jaewoong Jung26dedd32019-06-06 08:45:58 -07001206type OverrideAndroidTest struct {
1207 android.ModuleBase
1208 android.OverrideModuleBase
1209}
1210
1211func (i *OverrideAndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1212 // All the overrides happen in the base module.
1213 // TODO(jungjw): Check the base module type.
1214}
1215
1216// override_android_test is used to create an android_app module based on another android_test by overriding
1217// some of its properties.
1218func OverrideAndroidTestModuleFactory() android.Module {
1219 m := &OverrideAndroidTest{}
1220 m.AddProperties(&overridableAppProperties{})
1221 m.AddProperties(&appTestProperties{})
1222
1223 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1224 android.InitOverrideModule(m)
1225 return m
1226}
1227
Roshan Pius4df2bc72020-04-27 09:42:27 -07001228type OverrideRuntimeResourceOverlay struct {
1229 android.ModuleBase
1230 android.OverrideModuleBase
1231}
1232
1233func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1234 // All the overrides happen in the base module.
1235 // TODO(jungjw): Check the base module type.
1236}
1237
1238// override_runtime_resource_overlay is used to create a module based on another
1239// runtime_resource_overlay module by overriding some of its properties.
1240func OverrideRuntimeResourceOverlayModuleFactory() android.Module {
1241 m := &OverrideRuntimeResourceOverlay{}
1242 m.AddProperties(&OverridableRuntimeResourceOverlayProperties{})
1243
1244 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
1245 android.InitOverrideModule(m)
1246 return m
1247}
1248
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001249type AndroidAppImport struct {
1250 android.ModuleBase
1251 android.DefaultableModuleBase
Jiyong Park592a6a42020-04-21 22:34:28 +09001252 android.ApexModuleBase
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001253 prebuilt android.Prebuilt
1254
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001255 properties AndroidAppImportProperties
1256 dpiVariants interface{}
1257 archVariants interface{}
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001258
1259 outputFile android.Path
Colin Cross503c1d02020-01-28 14:00:53 -08001260 certificate Certificate
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001261
1262 dexpreopter
Colin Cross50ddcc42019-05-16 12:28:22 -07001263
1264 usesLibrary usesLibrary
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001265
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001266 preprocessed bool
1267
Colin Cross70dda7e2019-10-01 22:05:35 -07001268 installPath android.InstallPath
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001269}
1270
1271type AndroidAppImportProperties struct {
1272 // A prebuilt apk to import
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001273 Apk *string
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001274
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001275 // The name of a certificate in the default certificate directory or an android_app_certificate
1276 // module name in the form ":module". Should be empty if presigned or default_dev_cert is set.
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001277 Certificate *string
1278
1279 // Set this flag to true if the prebuilt apk is already signed. The certificate property must not
1280 // be set for presigned modules.
1281 Presigned *bool
1282
Liz Kammer24978992020-05-13 15:49:21 -07001283 // Name of the signing certificate lineage file.
1284 Lineage *string
1285
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001286 // Sign with the default system dev certificate. Must be used judiciously. Most imported apps
1287 // need to either specify a specific certificate or be presigned.
1288 Default_dev_cert *bool
1289
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001290 // Specifies that this app should be installed to the priv-app directory,
1291 // where the system will grant it additional privileges not available to
1292 // normal apps.
1293 Privileged *bool
1294
1295 // Names of modules to be overridden. Listed modules can only be other binaries
1296 // (in Make or Soong).
1297 // This does not completely prevent installation of the overridden binaries, but if both
1298 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1299 // from PRODUCT_PACKAGES.
1300 Overrides []string
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001301
1302 // Optional name for the installed app. If unspecified, it is derived from the module name.
1303 Filename *string
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001304}
1305
Martin Stjernholm6d415272020-01-31 17:10:36 +00001306func (a *AndroidAppImport) IsInstallable() bool {
1307 return true
1308}
1309
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001310// Updates properties with variant-specific values.
1311func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) {
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001312 config := ctx.Config()
1313
1314 dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName("Dpi_variants")
1315 // Try DPI variant matches in the reverse-priority order so that the highest priority match
1316 // overwrites everything else.
1317 // TODO(jungjw): Can we optimize this by making it priority order?
1318 for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001319 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i])
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001320 }
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001321 if config.ProductAAPTPreferredConfig() != "" {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001322 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig())
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001323 }
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001324
1325 archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName("Arch")
1326 archType := ctx.Config().Targets[android.Android][0].Arch.ArchType
1327 MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name)
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001328}
1329
Colin Cross1184b642019-12-30 18:43:07 -08001330func MergePropertiesFromVariant(ctx android.EarlyModuleContext,
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001331 dst interface{}, variantGroup reflect.Value, variant string) {
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001332 src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant))
1333 if !src.IsValid() {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001334 return
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001335 }
1336
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001337 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend)
1338 if err != nil {
1339 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
1340 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
1341 } else {
1342 panic(err)
1343 }
1344 }
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001345}
1346
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001347func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) {
1348 cert := android.SrcIsModule(String(a.properties.Certificate))
1349 if cert != "" {
1350 ctx.AddDependency(ctx.Module(), certificateTag, cert)
1351 }
Colin Cross50ddcc42019-05-16 12:28:22 -07001352
Paul Duffin250e6192019-06-07 10:44:37 +01001353 a.usesLibrary.deps(ctx, true)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001354}
1355
1356func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
1357 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001358 // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
1359 // with them may invalidate pre-existing signature data.
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001360 if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || a.preprocessed) {
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001361 ctx.Build(pctx, android.BuildParams{
1362 Rule: android.Cp,
1363 Output: outputPath,
1364 Input: inputPath,
1365 })
1366 return
1367 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001368 rule := android.NewRuleBuilder()
1369 rule.Command().
1370 Textf(`if (zipinfo %s 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
Colin Crossee94d6a2019-07-08 17:08:34 -07001371 BuiltTool(ctx, "zip2zip").
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001372 FlagWithInput("-i ", inputPath).
1373 FlagWithOutput("-o ", outputPath).
1374 FlagWithArg("-0 ", "'lib/**/*.so'").
1375 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
1376 rule.Build(pctx, ctx, "uncompress-embedded-jni-libs", "Uncompress embedded JIN libs")
1377}
1378
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001379// Returns whether this module should have the dex file stored uncompressed in the APK.
1380func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001381 if ctx.Config().UnbundledBuild() || a.preprocessed {
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001382 return false
1383 }
1384
1385 // Uncompress dex in APKs of privileged apps
Jiyong Parkf7487312019-10-17 12:54:30 +09001386 if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001387 return true
1388 }
1389
1390 return shouldUncompressDex(ctx, &a.dexpreopter)
1391}
1392
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001393func (a *AndroidAppImport) uncompressDex(
1394 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
1395 rule := android.NewRuleBuilder()
1396 rule.Command().
1397 Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
Colin Crossee94d6a2019-07-08 17:08:34 -07001398 BuiltTool(ctx, "zip2zip").
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001399 FlagWithInput("-i ", inputPath).
1400 FlagWithOutput("-o ", outputPath).
1401 FlagWithArg("-0 ", "'classes*.dex'").
1402 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
1403 rule.Build(pctx, ctx, "uncompress-dex", "Uncompress dex files")
1404}
1405
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001406func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001407 a.generateAndroidBuildActions(ctx)
1408}
1409
Jooyung Han39ee1192020-03-23 20:21:11 +09001410func (a *AndroidAppImport) InstallApkName() string {
1411 return a.BaseModuleName()
1412}
1413
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001414func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001415 numCertPropsSet := 0
1416 if String(a.properties.Certificate) != "" {
1417 numCertPropsSet++
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001418 }
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001419 if Bool(a.properties.Presigned) {
1420 numCertPropsSet++
1421 }
1422 if Bool(a.properties.Default_dev_cert) {
1423 numCertPropsSet++
1424 }
1425 if numCertPropsSet != 1 {
1426 ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001427 }
1428
Colin Crossc2d24052020-05-13 11:05:02 -07001429 _, certificates := collectAppDeps(ctx, a, false, false)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001430
1431 // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001432 // TODO: LOCAL_PACKAGE_SPLITS
1433
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001434 srcApk := a.prebuilt.SingleSourcePath(ctx)
Colin Cross50ddcc42019-05-16 12:28:22 -07001435
1436 if a.usesLibrary.enforceUsesLibraries() {
1437 srcApk = a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk)
1438 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001439
1440 // TODO: Install or embed JNI libraries
1441
1442 // Uncompress JNI libraries in the apk
1443 jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk")
1444 a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed.OutputPath)
1445
Kyeongkab.Namc4997142019-11-22 11:38:16 +09001446 var installDir android.InstallPath
1447 if Bool(a.properties.Privileged) {
1448 installDir = android.PathForModuleInstall(ctx, "priv-app", a.BaseModuleName())
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001449 } else if ctx.InstallInTestcases() {
1450 installDir = android.PathForModuleInstall(ctx, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch())
Kyeongkab.Namc4997142019-11-22 11:38:16 +09001451 } else {
1452 installDir = android.PathForModuleInstall(ctx, "app", a.BaseModuleName())
1453 }
1454
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001455 a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001456 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001457 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
Colin Cross50ddcc42019-05-16 12:28:22 -07001458
1459 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
1460 a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
1461 a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
1462 a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
1463
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001464 dexOutput := a.dexpreopter.dexpreopt(ctx, jnisUncompressed)
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001465 if a.dexpreopter.uncompressedDex {
1466 dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk")
1467 a.uncompressDex(ctx, dexOutput, dexUncompressed.OutputPath)
1468 dexOutput = dexUncompressed
1469 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001470
Jooyung Han39ee1192020-03-23 20:21:11 +09001471 apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk")
1472
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001473 // TODO: Handle EXTERNAL
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001474
1475 // Sign or align the package if package has not been preprocessed
1476 if a.preprocessed {
1477 a.outputFile = srcApk
1478 a.certificate = presignedCertificate
1479 } else if !Bool(a.properties.Presigned) {
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001480 // If the certificate property is empty at this point, default_dev_cert must be set to true.
1481 // Which makes processMainCert's behavior for the empty cert string WAI.
1482 certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001483 if len(certificates) != 1 {
1484 ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
1485 }
Colin Cross503c1d02020-01-28 14:00:53 -08001486 a.certificate = certificates[0]
Jooyung Han39ee1192020-03-23 20:21:11 +09001487 signed := android.PathForModuleOut(ctx, "signed", apkFilename)
Liz Kammer24978992020-05-13 15:49:21 -07001488 var lineageFile android.Path
1489 if lineage := String(a.properties.Lineage); lineage != "" {
1490 lineageFile = android.PathForModuleSrc(ctx, lineage)
1491 }
1492 SignAppPackage(ctx, signed, dexOutput, certificates, lineageFile)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001493 a.outputFile = signed
1494 } else {
Jooyung Han39ee1192020-03-23 20:21:11 +09001495 alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001496 TransformZipAlign(ctx, alignedApk, dexOutput)
1497 a.outputFile = alignedApk
Colin Cross503c1d02020-01-28 14:00:53 -08001498 a.certificate = presignedCertificate
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001499 }
1500
1501 // TODO: Optionally compress the output apk.
1502
Jiyong Park592a6a42020-04-21 22:34:28 +09001503 if a.IsForPlatform() {
1504 a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile)
1505 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001506
1507 // TODO: androidmk converter jni libs
1508}
1509
1510func (a *AndroidAppImport) Prebuilt() *android.Prebuilt {
1511 return &a.prebuilt
1512}
1513
1514func (a *AndroidAppImport) Name() string {
1515 return a.prebuilt.Name(a.ModuleBase.Name())
1516}
1517
Dario Frenicde2a032019-10-27 00:29:22 +01001518func (a *AndroidAppImport) OutputFile() android.Path {
1519 return a.outputFile
1520}
1521
Jiyong Park618922e2020-01-08 13:35:43 +09001522func (a *AndroidAppImport) JacocoReportClassesFile() android.Path {
1523 return nil
1524}
1525
Colin Cross503c1d02020-01-28 14:00:53 -08001526func (a *AndroidAppImport) Certificate() Certificate {
1527 return a.certificate
1528}
1529
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001530var dpiVariantGroupType reflect.Type
1531var archVariantGroupType reflect.Type
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001532
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001533func initAndroidAppImportVariantGroupTypes() {
1534 dpiVariantGroupType = createVariantGroupType(supportedDpis, "Dpi_variants")
1535
1536 archNames := make([]string, len(android.ArchTypeList()))
1537 for i, archType := range android.ArchTypeList() {
1538 archNames[i] = archType.Name
1539 }
1540 archVariantGroupType = createVariantGroupType(archNames, "Arch")
1541}
1542
1543// Populates all variant struct properties at creation time.
1544func (a *AndroidAppImport) populateAllVariantStructs() {
1545 a.dpiVariants = reflect.New(dpiVariantGroupType).Interface()
1546 a.AddProperties(a.dpiVariants)
1547
1548 a.archVariants = reflect.New(archVariantGroupType).Interface()
1549 a.AddProperties(a.archVariants)
1550}
1551
Jiyong Parkf7487312019-10-17 12:54:30 +09001552func (a *AndroidAppImport) Privileged() bool {
1553 return Bool(a.properties.Privileged)
1554}
1555
Jiyong Park592a6a42020-04-21 22:34:28 +09001556func (a *AndroidAppImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1557 // android_app_import might have extra dependencies via uses_libs property.
1558 // Don't track the dependency as we don't automatically add those libraries
1559 // to the classpath. It should be explicitly added to java_libs property of APEX
1560 return false
1561}
1562
Colin Crossc2d24052020-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
Jiyong Park592a6a42020-04-21 22:34:28 +09001617 android.InitApexModule(module)
Jaewoong Jung6abfbf72020-05-26 20:10:08 -07001618 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1619 android.InitDefaultableModule(module)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001620 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001621
1622 return module
1623}
Colin Cross50ddcc42019-05-16 12:28:22 -07001624
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001625type androidTestImportProperties struct {
1626 // Whether the prebuilt apk can be installed without additional processing. Default is false.
1627 Preprocessed *bool
1628}
1629
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001630type AndroidTestImport struct {
1631 AndroidAppImport
1632
1633 testProperties testProperties
1634
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001635 testImportProperties androidTestImportProperties
1636
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001637 data android.Paths
1638}
1639
1640func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001641 a.preprocessed = Bool(a.testImportProperties.Preprocessed)
1642
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001643 a.generateAndroidBuildActions(ctx)
1644
1645 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
1646}
1647
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001648func (a *AndroidTestImport) InstallInTestcases() bool {
1649 return true
1650}
1651
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001652// android_test_import imports a prebuilt test apk with additional processing specified in the
1653// module. DPI or arch variant configurations can be made as with android_app_import.
1654func AndroidTestImportFactory() android.Module {
1655 module := &AndroidTestImport{}
1656 module.AddProperties(&module.properties)
1657 module.AddProperties(&module.dexpreoptProperties)
1658 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
1659 module.AddProperties(&module.testProperties)
Liz Kammer3b70b3f2020-05-20 14:36:30 -07001660 module.AddProperties(&module.testImportProperties)
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001661 module.populateAllVariantStructs()
1662 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
1663 module.processVariants(ctx)
1664 })
1665
Colin Crossc80828d2020-05-06 22:29:10 -07001666 module.dexpreopter.isTest = true
1667
Jiyong Park592a6a42020-04-21 22:34:28 +09001668 android.InitApexModule(module)
Jaewoong Jung243688e2020-05-01 15:50:08 -07001669 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1670 android.InitDefaultableModule(module)
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001671 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
1672
1673 return module
1674}
1675
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001676type RuntimeResourceOverlay struct {
1677 android.ModuleBase
1678 android.DefaultableModuleBase
Roshan Pius4df2bc72020-04-27 09:42:27 -07001679 android.OverridableModuleBase
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001680 aapt
1681
Roshan Pius4df2bc72020-04-27 09:42:27 -07001682 properties RuntimeResourceOverlayProperties
1683 overridableProperties OverridableRuntimeResourceOverlayProperties
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001684
Jaewoong Jung78ec5d82020-01-31 10:11:47 -08001685 certificate Certificate
1686
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001687 outputFile android.Path
1688 installDir android.InstallPath
1689}
1690
1691type RuntimeResourceOverlayProperties struct {
1692 // the name of a certificate in the default certificate directory or an android_app_certificate
1693 // module name in the form ":module".
1694 Certificate *string
1695
Liz Kammer966b2f02020-05-19 16:15:25 -07001696 // Name of the signing certificate lineage file.
1697 Lineage *string
1698
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001699 // optional theme name. If specified, the overlay package will be applied
1700 // only when the ro.boot.vendor.overlay.theme system property is set to the same value.
1701 Theme *string
1702
1703 // if not blank, set to the version of the sdk to compile against.
1704 // Defaults to compiling against the current platform.
1705 Sdk_version *string
1706
1707 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
1708 // Defaults to sdk_version if not set.
1709 Min_sdk_version *string
Jaewoong Jungfe3c7f62020-04-09 16:15:30 -07001710
1711 // list of android_library modules whose resources are extracted and linked against statically
1712 Static_libs []string
1713
1714 // list of android_app modules whose resources are extracted and linked against
1715 Resource_libs []string
Jaewoong Jungad0177b2020-04-24 15:22:40 -07001716
1717 // Names of modules to be overridden. Listed modules can only be other overlays
1718 // (in Make or Soong).
1719 // This does not completely prevent installation of the overridden overlays, but if both
1720 // overlays would be installed by default (in PRODUCT_PACKAGES) the other overlay will be removed
1721 // from PRODUCT_PACKAGES.
1722 Overrides []string
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001723}
1724
Jiyong Park69aeba92020-04-24 21:16:36 +09001725// RuntimeResourceOverlayModule interface is used by the apex package to gather information from
1726// a RuntimeResourceOverlay module.
1727type RuntimeResourceOverlayModule interface {
1728 android.Module
1729 OutputFile() android.Path
1730 Certificate() Certificate
1731 Theme() string
1732}
1733
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001734func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) {
1735 sdkDep := decodeSdkDep(ctx, sdkContext(r))
1736 if sdkDep.hasFrameworkLibs() {
1737 r.aapt.deps(ctx, sdkDep)
1738 }
1739
1740 cert := android.SrcIsModule(String(r.properties.Certificate))
1741 if cert != "" {
1742 ctx.AddDependency(ctx.Module(), certificateTag, cert)
1743 }
Jaewoong Jungfe3c7f62020-04-09 16:15:30 -07001744
1745 ctx.AddVariationDependencies(nil, staticLibTag, r.properties.Static_libs...)
1746 ctx.AddVariationDependencies(nil, libTag, r.properties.Resource_libs...)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001747}
1748
1749func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1750 // Compile and link resources
1751 r.aapt.hasNoCode = true
Jaewoong Jungf0f747c2020-01-24 10:30:02 -08001752 // Do not remove resources without default values nor dedupe resource configurations with the same value
Roshan Pius4df2bc72020-04-27 09:42:27 -07001753 aaptLinkFlags := []string{"--no-resource-deduping", "--no-resource-removal"}
1754 // Allow the override of "package name" and "overlay target package name"
1755 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
1756 if overridden || r.overridableProperties.Package_name != nil {
1757 // The product override variable has a priority over the package_name property.
1758 if !overridden {
1759 manifestPackageName = *r.overridableProperties.Package_name
1760 }
1761 aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName)
1762 }
1763 if r.overridableProperties.Target_package_name != nil {
1764 aaptLinkFlags = append(aaptLinkFlags,
1765 "--rename-overlay-target-package "+*r.overridableProperties.Target_package_name)
1766 }
1767 r.aapt.buildActions(ctx, r, aaptLinkFlags...)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001768
1769 // Sign the built package
Colin Crossc2d24052020-05-13 11:05:02 -07001770 _, certificates := collectAppDeps(ctx, r, false, false)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001771 certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
1772 signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
Liz Kammer966b2f02020-05-19 16:15:25 -07001773 var lineageFile android.Path
1774 if lineage := String(r.properties.Lineage); lineage != "" {
1775 lineageFile = android.PathForModuleSrc(ctx, lineage)
1776 }
1777 SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, lineageFile)
Jaewoong Jung78ec5d82020-01-31 10:11:47 -08001778 r.certificate = certificates[0]
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001779
1780 r.outputFile = signed
1781 r.installDir = android.PathForModuleInstall(ctx, "overlay", String(r.properties.Theme))
1782 ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
1783}
1784
Jiyong Park6a927c42020-01-21 02:03:43 +09001785func (r *RuntimeResourceOverlay) sdkVersion() sdkSpec {
1786 return sdkSpecFrom(String(r.properties.Sdk_version))
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001787}
1788
1789func (r *RuntimeResourceOverlay) systemModules() string {
1790 return ""
1791}
1792
Jiyong Park6a927c42020-01-21 02:03:43 +09001793func (r *RuntimeResourceOverlay) minSdkVersion() sdkSpec {
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001794 if r.properties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +09001795 return sdkSpecFrom(*r.properties.Min_sdk_version)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001796 }
1797 return r.sdkVersion()
1798}
1799
Jiyong Park6a927c42020-01-21 02:03:43 +09001800func (r *RuntimeResourceOverlay) targetSdkVersion() sdkSpec {
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001801 return r.sdkVersion()
1802}
1803
Jiyong Park69aeba92020-04-24 21:16:36 +09001804func (r *RuntimeResourceOverlay) Certificate() Certificate {
1805 return r.certificate
1806}
1807
1808func (r *RuntimeResourceOverlay) OutputFile() android.Path {
1809 return r.outputFile
1810}
1811
1812func (r *RuntimeResourceOverlay) Theme() string {
1813 return String(r.properties.Theme)
1814}
1815
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001816// runtime_resource_overlay generates a resource-only apk file that can overlay application and
1817// system resources at run time.
1818func RuntimeResourceOverlayFactory() android.Module {
1819 module := &RuntimeResourceOverlay{}
1820 module.AddProperties(
1821 &module.properties,
Roshan Pius4df2bc72020-04-27 09:42:27 -07001822 &module.aaptProperties,
1823 &module.overridableProperties)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001824
Roshan Pius4df2bc72020-04-27 09:42:27 -07001825 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
1826 android.InitDefaultableModule(module)
1827 android.InitOverridableModule(module, &module.properties.Overrides)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001828 return module
1829}
1830
Colin Cross50ddcc42019-05-16 12:28:22 -07001831type UsesLibraryProperties struct {
1832 // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file.
1833 Uses_libs []string
1834
1835 // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file with
1836 // required=false.
1837 Optional_uses_libs []string
1838
1839 // If true, the list of uses_libs and optional_uses_libs modules must match the AndroidManifest.xml file. Defaults
1840 // to true if either uses_libs or optional_uses_libs is set. Will unconditionally default to true in the future.
1841 Enforce_uses_libs *bool
1842}
1843
1844// usesLibrary provides properties and helper functions for AndroidApp and AndroidAppImport to verify that the
1845// <uses-library> tags that end up in the manifest of an APK match the ones known to the build system through the
1846// uses_libs and optional_uses_libs properties. The build system's values are used by dexpreopt to preopt apps
1847// with knowledge of their shared libraries.
1848type usesLibrary struct {
1849 usesLibraryProperties UsesLibraryProperties
1850}
1851
Paul Duffin250e6192019-06-07 10:44:37 +01001852func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs bool) {
Colin Cross3245b2c2019-06-07 13:18:09 -07001853 if !ctx.Config().UnbundledBuild() {
1854 ctx.AddVariationDependencies(nil, usesLibTag, u.usesLibraryProperties.Uses_libs...)
1855 ctx.AddVariationDependencies(nil, usesLibTag, u.presentOptionalUsesLibs(ctx)...)
Paul Duffin250e6192019-06-07 10:44:37 +01001856 // Only add these extra dependencies if the module depends on framework libs. This avoids
1857 // creating a cyclic dependency:
1858 // e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res.
1859 if hasFrameworkLibs {
Colin Cross3245b2c2019-06-07 13:18:09 -07001860 // dexpreopt/dexpreopt.go needs the paths to the dex jars of these libraries in case construct_context.sh needs
1861 // to pass them to dex2oat. Add them as a dependency so we can determine the path to the dex jar of each
1862 // library to dexpreopt.
1863 ctx.AddVariationDependencies(nil, usesLibTag,
1864 "org.apache.http.legacy",
1865 "android.hidl.base-V1.0-java",
1866 "android.hidl.manager-V1.0-java")
Ulya Trafimovichc9af5382020-05-29 15:35:06 +01001867 ctx.AddVariationDependencies(nil, usesLibTag, optionalUsesLibs...)
Colin Cross3245b2c2019-06-07 13:18:09 -07001868 }
Colin Cross50ddcc42019-05-16 12:28:22 -07001869 }
1870}
1871
1872// presentOptionalUsesLibs returns optional_uses_libs after filtering out MissingUsesLibraries, which don't exist in the
1873// build.
1874func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []string {
1875 optionalUsesLibs, _ := android.FilterList(u.usesLibraryProperties.Optional_uses_libs, ctx.Config().MissingUsesLibraries())
1876 return optionalUsesLibs
1877}
1878
Ulya Trafimovichd4bcea42020-06-03 14:57:22 +01001879// usesLibraryPaths returns a map of module names of shared library dependencies to the paths
1880// to their dex jars on host and on device.
1881func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.LibraryPaths {
1882 usesLibPaths := make(dexpreopt.LibraryPaths)
Colin Cross50ddcc42019-05-16 12:28:22 -07001883
1884 if !ctx.Config().UnbundledBuild() {
1885 ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
Ulya Trafimovichd4bcea42020-06-03 14:57:22 +01001886 dep := ctx.OtherModuleName(m)
Colin Cross50ddcc42019-05-16 12:28:22 -07001887 if lib, ok := m.(Dependency); ok {
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00001888 if dexJar := lib.DexJarBuildPath(); dexJar != nil {
Ulya Trafimovichd4bcea42020-06-03 14:57:22 +01001889 usesLibPaths[dep] = &dexpreopt.LibraryPath{
1890 dexJar,
1891 // TODO(b/132357300): propagate actual install paths here.
1892 filepath.Join("/system/framework", dep+".jar"),
1893 }
Colin Cross50ddcc42019-05-16 12:28:22 -07001894 } else {
Ulya Trafimovichd4bcea42020-06-03 14:57:22 +01001895 ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must"+
1896 " produce a dex jar, does it have installable: true?", dep)
Colin Cross50ddcc42019-05-16 12:28:22 -07001897 }
1898 } else if ctx.Config().AllowMissingDependencies() {
Ulya Trafimovichd4bcea42020-06-03 14:57:22 +01001899 ctx.AddMissingDependencies([]string{dep})
Colin Cross50ddcc42019-05-16 12:28:22 -07001900 } else {
Ulya Trafimovichd4bcea42020-06-03 14:57:22 +01001901 ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+
1902 "a java library", dep)
Colin Cross50ddcc42019-05-16 12:28:22 -07001903 }
1904 })
1905 }
1906
1907 return usesLibPaths
1908}
1909
1910// enforceUsesLibraries returns true of <uses-library> tags should be checked against uses_libs and optional_uses_libs
1911// properties. Defaults to true if either of uses_libs or optional_uses_libs is specified. Will default to true
1912// unconditionally in the future.
1913func (u *usesLibrary) enforceUsesLibraries() bool {
1914 defaultEnforceUsesLibs := len(u.usesLibraryProperties.Uses_libs) > 0 ||
1915 len(u.usesLibraryProperties.Optional_uses_libs) > 0
1916 return BoolDefault(u.usesLibraryProperties.Enforce_uses_libs, defaultEnforceUsesLibs)
1917}
1918
1919// verifyUsesLibrariesManifest checks the <uses-library> tags in an AndroidManifest.xml against the ones specified
1920// in the uses_libs and optional_uses_libs properties. It returns the path to a copy of the manifest.
1921func (u *usesLibrary) verifyUsesLibrariesManifest(ctx android.ModuleContext, manifest android.Path) android.Path {
1922 outputFile := android.PathForModuleOut(ctx, "manifest_check", "AndroidManifest.xml")
1923
1924 rule := android.NewRuleBuilder()
Colin Crossee94d6a2019-07-08 17:08:34 -07001925 cmd := rule.Command().BuiltTool(ctx, "manifest_check").
Colin Cross50ddcc42019-05-16 12:28:22 -07001926 Flag("--enforce-uses-libraries").
1927 Input(manifest).
1928 FlagWithOutput("-o ", outputFile)
1929
1930 for _, lib := range u.usesLibraryProperties.Uses_libs {
1931 cmd.FlagWithArg("--uses-library ", lib)
1932 }
1933
1934 for _, lib := range u.usesLibraryProperties.Optional_uses_libs {
1935 cmd.FlagWithArg("--optional-uses-library ", lib)
1936 }
1937
1938 rule.Build(pctx, ctx, "verify_uses_libraries", "verify <uses-library>")
1939
1940 return outputFile
1941}
1942
1943// verifyUsesLibrariesAPK checks the <uses-library> tags in the manifest of an APK against the ones specified
1944// in the uses_libs and optional_uses_libs properties. It returns the path to a copy of the APK.
1945func (u *usesLibrary) verifyUsesLibrariesAPK(ctx android.ModuleContext, apk android.Path) android.Path {
1946 outputFile := android.PathForModuleOut(ctx, "verify_uses_libraries", apk.Base())
1947
1948 rule := android.NewRuleBuilder()
1949 aapt := ctx.Config().HostToolPath(ctx, "aapt")
1950 rule.Command().
1951 Textf("aapt_binary=%s", aapt.String()).Implicit(aapt).
1952 Textf(`uses_library_names="%s"`, strings.Join(u.usesLibraryProperties.Uses_libs, " ")).
1953 Textf(`optional_uses_library_names="%s"`, strings.Join(u.usesLibraryProperties.Optional_uses_libs, " ")).
1954 Tool(android.PathForSource(ctx, "build/make/core/verify_uses_libraries.sh")).Input(apk)
1955 rule.Command().Text("cp -f").Input(apk).Output(outputFile)
1956
1957 rule.Build(pctx, ctx, "verify_uses_libraries", "verify <uses-library>")
1958
1959 return outputFile
1960}