blob: c9ae3e776f26d0d0e14ca29709f1917960afce18 [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"
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070023 "strings"
Colin Cross30e076a2015-04-13 13:58:27 -070024
Colin Cross50ddcc42019-05-16 12:28:22 -070025 "github.com/google/blueprint"
26 "github.com/google/blueprint/proptools"
27
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossa4f08812018-10-02 22:03:40 -070029 "android/soong/cc"
Colin Cross303e21f2018-08-07 16:49:25 -070030 "android/soong/tradefed"
Colin Cross30e076a2015-04-13 13:58:27 -070031)
32
Jaewoong Jung3e18b192019-06-11 12:25:34 -070033var supportedDpis = []string{"ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"}
Jaewoong Junga5e5abc2019-04-26 14:31:50 -070034
Colin Cross3bc7ffa2017-11-22 16:19:37 -080035func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000036 RegisterAppBuildComponents(android.InitRegistrationContext)
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -070037
38 initAndroidAppImportVariantGroupTypes()
Colin Cross3bc7ffa2017-11-22 16:19:37 -080039}
40
Paul Duffinf9b1da02019-12-18 19:51:55 +000041func RegisterAppBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("android_app", AndroidAppFactory)
43 ctx.RegisterModuleType("android_test", AndroidTestFactory)
44 ctx.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory)
45 ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
46 ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
47 ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
48 ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory)
49 ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -080050 ctx.RegisterModuleType("runtime_resource_overlay", RuntimeResourceOverlayFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +000051}
52
Colin Cross30e076a2015-04-13 13:58:27 -070053// AndroidManifest.xml merging
54// package splits
55
Colin Crossfabb6082018-02-20 17:22:23 -080056type appProperties struct {
Colin Crossbd01e2a2018-10-04 15:21:03 -070057 // Names of extra android_app_certificate modules to sign the apk with in the form ":module".
Colin Cross7d5136f2015-05-11 13:39:40 -070058 Additional_certificates []string
59
60 // If set, create package-export.apk, which other packages can
61 // use to get PRODUCT-agnostic resource data like IDs and type definitions.
Nan Zhangea568a42017-11-08 21:20:04 -080062 Export_package_resources *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070063
Colin Cross16056062017-12-13 22:46:28 -080064 // Specifies that this app should be installed to the priv-app directory,
65 // where the system will grant it additional privileges not available to
66 // normal apps.
67 Privileged *bool
Colin Crossa97c5d32018-03-28 14:58:31 -070068
69 // list of resource labels to generate individual resource packages
70 Package_splits []string
Jason Monkd4122be2018-08-10 09:33:36 -040071
72 // Names of modules to be overridden. Listed modules can only be other binaries
73 // (in Make or Soong).
74 // This does not completely prevent installation of the overridden binaries, but if both
75 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
76 // from PRODUCT_PACKAGES.
77 Overrides []string
Colin Crossa4f08812018-10-02 22:03:40 -070078
79 // list of native libraries that will be provided in or alongside the resulting jar
80 Jni_libs []string `android:"arch_variant"`
81
Colin Crossee87c602020-02-19 16:57:15 -080082 // if true, allow JNI libraries that link against platform APIs even if this module sets
83 // sdk_version.
84 Jni_uses_platform_apis *bool
85
Jaewoong Jungbc625cd2019-05-06 15:48:44 -070086 // STL library to use for JNI libraries.
87 Stl *string `android:"arch_variant"`
88
Colin Crosse4246ab2019-02-05 21:55:21 -080089 // Store native libraries uncompressed in the APK and set the android:extractNativeLibs="false" manifest
90 // 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 +090091 // sdk_version or min_sdk_version is set to a version that doesn't support it (<23), defaults to true for
92 // android_app modules that are embedded to APEXes, defaults to false for other module types where the native
93 // libraries are generally preinstalled outside the APK.
Colin Crosse4246ab2019-02-05 21:55:21 -080094 Use_embedded_native_libs *bool
Colin Cross46abdad2019-02-07 13:07:08 -080095
96 // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that
97 // they are used from inside the APK at runtime.
98 Use_embedded_dex *bool
Colin Cross47fa9d32019-03-26 10:51:39 -070099
100 // Forces native libraries to always be packaged into the APK,
101 // Use_embedded_native_libs still selects whether they are stored uncompressed and aligned or compressed.
102 // True for android_test* modules.
103 AlwaysPackageNativeLibs bool `blueprint:"mutated"`
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700104
105 // If set, find and merge all NOTICE files that this module and its dependencies have and store
106 // it in the APK as an asset.
107 Embed_notices *bool
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700108
109 // cc.Coverage related properties
110 PreventInstall bool `blueprint:"mutated"`
111 HideFromMake bool `blueprint:"mutated"`
112 IsCoverageVariant bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700113}
114
Jaewoong Jung525443a2019-02-28 15:35:54 -0800115// android_app properties that can be overridden by override_android_app
116type overridableAppProperties struct {
117 // The name of a certificate in the default certificate directory, blank to use the default product certificate,
118 // or an android_app_certificate module name in the form ":module".
119 Certificate *string
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700120
121 // the package name of this app. The package name in the manifest file is used if one was not given.
122 Package_name *string
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800123
124 // the logging parent of this app.
125 Logging_parent *string
Jaewoong Jung525443a2019-02-28 15:35:54 -0800126}
127
Colin Cross30e076a2015-04-13 13:58:27 -0700128type AndroidApp struct {
Colin Crossa97c5d32018-03-28 14:58:31 -0700129 Library
130 aapt
Jaewoong Jung525443a2019-02-28 15:35:54 -0800131 android.OverridableModuleBase
Colin Crossa97c5d32018-03-28 14:58:31 -0700132
Colin Cross50ddcc42019-05-16 12:28:22 -0700133 usesLibrary usesLibrary
134
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900135 certificate Certificate
Colin Cross30e076a2015-04-13 13:58:27 -0700136
Colin Crossfabb6082018-02-20 17:22:23 -0800137 appProperties appProperties
Colin Crossae5caf52018-05-22 11:11:52 -0700138
Jaewoong Jung525443a2019-02-28 15:35:54 -0800139 overridableAppProperties overridableAppProperties
140
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700141 installJniLibs []jniLib
142 jniCoverageOutputs android.Paths
Colin Crossf6237212018-10-29 23:14:58 -0700143
144 bundleFile android.Path
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800145
146 // the install APK name is normally the same as the module name, but can be overridden with PRODUCT_PACKAGE_NAME_OVERRIDES.
147 installApkName string
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800148
Colin Cross70dda7e2019-10-01 22:05:35 -0700149 installDir android.InstallPath
Jaewoong Jung0949f312019-09-11 10:25:18 -0700150
Jaewoong Jung7dd4ae22019-09-27 17:13:15 -0700151 onDeviceDir string
152
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800153 additionalAaptFlags []string
Jaewoong Jung98772792019-07-01 17:15:13 -0700154
155 noticeOutputs android.NoticeOutputs
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900156
157 overriddenManifestPackageName string
Colin Crosse1731a52017-12-14 11:22:55 -0800158}
159
Martin Stjernholm6d415272020-01-31 17:10:36 +0000160func (a *AndroidApp) IsInstallable() bool {
161 return Bool(a.properties.Installable)
162}
163
Colin Cross89c31582018-04-30 15:55:11 -0700164func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
165 return nil
166}
167
Colin Cross66f78822018-05-02 12:58:28 -0700168func (a *AndroidApp) ExportedStaticPackages() android.Paths {
169 return nil
170}
171
Sundong Ahne1f05aa2019-08-27 13:55:42 +0900172func (a *AndroidApp) OutputFile() android.Path {
173 return a.outputFile
174}
175
Colin Cross503c1d02020-01-28 14:00:53 -0800176func (a *AndroidApp) Certificate() Certificate {
177 return a.certificate
178}
179
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700180func (a *AndroidApp) JniCoverageOutputs() android.Paths {
181 return a.jniCoverageOutputs
182}
183
Colin Crossa97c5d32018-03-28 14:58:31 -0700184var _ AndroidLibraryDependency = (*AndroidApp)(nil)
185
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900186type Certificate struct {
Colin Cross503c1d02020-01-28 14:00:53 -0800187 Pem, Key android.Path
188 presigned bool
189}
190
191var presignedCertificate = Certificate{presigned: true}
192
193func (c Certificate) AndroidMkString() string {
194 if c.presigned {
195 return "PRESIGNED"
196 } else {
197 return c.Pem.String()
198 }
Colin Cross30e076a2015-04-13 13:58:27 -0700199}
200
Colin Cross46c9b8b2017-06-22 16:51:17 -0700201func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
202 a.Module.deps(ctx)
Colin Crossa4f08812018-10-02 22:03:40 -0700203
Jiyong Park6a927c42020-01-21 02:03:43 +0900204 if String(a.appProperties.Stl) == "c++_shared" && !a.sdkVersion().specified() {
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700205 ctx.PropertyErrorf("stl", "sdk_version must be set in order to use c++_shared")
206 }
207
Paul Duffin250e6192019-06-07 10:44:37 +0100208 sdkDep := decodeSdkDep(ctx, sdkContext(a))
209 if sdkDep.hasFrameworkLibs() {
210 a.aapt.deps(ctx, sdkDep)
Colin Cross30e076a2015-04-13 13:58:27 -0700211 }
Colin Crossa4f08812018-10-02 22:03:40 -0700212
Peter Collingbournead84f972019-12-17 16:46:18 -0800213 tag := &jniDependencyTag{}
Colin Crossa4f08812018-10-02 22:03:40 -0700214 for _, jniTarget := range ctx.MultiTargets() {
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700215 variation := append(jniTarget.Variations(),
216 blueprint.Variation{Mutator: "link", Variation: "shared"})
Colin Crossc511bc52020-04-07 16:50:32 +0000217
218 // If the app builds against an Android SDK use the SDK variant of JNI dependencies
219 // unless jni_uses_platform_apis is set.
220 if a.sdkVersion().specified() && a.sdkVersion().kind != sdkCorePlatform &&
221 !Bool(a.appProperties.Jni_uses_platform_apis) {
222 variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
223 }
Colin Crossa4f08812018-10-02 22:03:40 -0700224 ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
225 }
Colin Cross50ddcc42019-05-16 12:28:22 -0700226
Paul Duffin250e6192019-06-07 10:44:37 +0100227 a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700228}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700229
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700230func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800231 cert := android.SrcIsModule(a.getCertString(ctx))
Colin Crossbd01e2a2018-10-04 15:21:03 -0700232 if cert != "" {
233 ctx.AddDependency(ctx.Module(), certificateTag, cert)
234 }
235
236 for _, cert := range a.appProperties.Additional_certificates {
237 cert = android.SrcIsModule(cert)
238 if cert != "" {
239 ctx.AddDependency(ctx.Module(), certificateTag, cert)
240 } else {
241 ctx.PropertyErrorf("additional_certificates",
242 `must be names of android_app_certificate modules in the form ":module"`)
243 }
244 }
Colin Cross30e076a2015-04-13 13:58:27 -0700245}
246
Jeongik Cha538c0d02019-07-11 15:54:27 +0900247func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
248 a.generateAndroidBuildActions(ctx)
249}
250
Colin Cross46c9b8b2017-06-22 16:51:17 -0700251func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jeongik Cha538c0d02019-07-11 15:54:27 +0900252 a.checkPlatformAPI(ctx)
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900253 a.checkSdkVersion(ctx)
Colin Crossae5caf52018-05-22 11:11:52 -0700254 a.generateAndroidBuildActions(ctx)
255}
256
Sasha Smundak6ad77252019-05-01 13:16:22 -0700257// Returns true if the native libraries should be stored in the APK uncompressed and the
Colin Crosse4246ab2019-02-05 21:55:21 -0800258// extractNativeLibs application flag should be set to false in the manifest.
Sasha Smundak6ad77252019-05-01 13:16:22 -0700259func (a *AndroidApp) useEmbeddedNativeLibs(ctx android.ModuleContext) bool {
Jiyong Park6a927c42020-01-21 02:03:43 +0900260 minSdkVersion, err := a.minSdkVersion().effectiveVersion(ctx)
Colin Crosse4246ab2019-02-05 21:55:21 -0800261 if err != nil {
262 ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
263 }
264
Jiyong Park52cd06f2019-11-11 10:14:32 +0900265 return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
266 !a.IsForPlatform()
Colin Crosse4246ab2019-02-05 21:55:21 -0800267}
268
Colin Cross43f08db2018-11-12 10:13:39 -0800269// Returns whether this module should have the dex file stored uncompressed in the APK.
270func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
Colin Cross46abdad2019-02-07 13:07:08 -0800271 if Bool(a.appProperties.Use_embedded_dex) {
272 return true
273 }
274
Colin Cross53a87f52019-06-25 13:35:30 -0700275 // Uncompress dex in APKs of privileged apps (even for unbundled builds, they may
276 // be preinstalled as prebuilts).
Jiyong Parkf7487312019-10-17 12:54:30 +0900277 if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000278 return true
279 }
280
Colin Cross53a87f52019-06-25 13:35:30 -0700281 if ctx.Config().UnbundledBuild() {
282 return false
283 }
284
Jaewoong Jungacf18d72019-05-02 14:55:29 -0700285 return shouldUncompressDex(ctx, &a.dexpreopter)
Colin Cross5a0dcd52018-10-05 14:20:06 -0700286}
287
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700288func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
289 return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
Jiyong Park52cd06f2019-11-11 10:14:32 +0900290 !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700291}
292
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900293func (a *AndroidApp) OverriddenManifestPackageName() string {
294 return a.overriddenManifestPackageName
295}
296
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800297func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
David Brazdild25060a2019-02-18 18:24:16 +0000298 a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis)
299
Jaewoong Jungc27ab662019-05-30 15:51:14 -0700300 // Ask manifest_fixer to add or update the application element indicating this app has no code.
301 a.aapt.hasNoCode = !a.hasCode(ctx)
302
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800303 aaptLinkFlags := []string{}
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800304
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800305 // 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 -0800306 hasProduct := android.PrefixInList(a.aaptProperties.Aaptflags, "--product")
Colin Crosse78dcd32018-04-19 15:25:19 -0700307 if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800308 aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
Colin Crosse78dcd32018-04-19 15:25:19 -0700309 }
310
Dan Willemsen72be5902018-10-24 20:24:57 -0700311 if !Bool(a.aaptProperties.Aapt_include_all_resources) {
312 // Product AAPT config
313 for _, aaptConfig := range ctx.Config().ProductAAPTConfig() {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800314 aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig)
Dan Willemsen72be5902018-10-24 20:24:57 -0700315 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700316
Dan Willemsen72be5902018-10-24 20:24:57 -0700317 // Product AAPT preferred config
318 if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 {
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800319 aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig())
Dan Willemsen72be5902018-10-24 20:24:57 -0700320 }
Colin Crosse78dcd32018-04-19 15:25:19 -0700321 }
322
Jiyong Park7f67f482019-01-05 12:57:48 +0900323 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
Jaewoong Jung6f373f62019-03-13 10:13:24 -0700324 if overridden || a.overridableAppProperties.Package_name != nil {
325 // The product override variable has a priority over the package_name property.
326 if !overridden {
327 manifestPackageName = *a.overridableAppProperties.Package_name
328 }
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800329 aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName)
Jiyong Parkcfaa1642020-02-28 16:51:07 +0900330 a.overriddenManifestPackageName = manifestPackageName
Jiyong Park7f67f482019-01-05 12:57:48 +0900331 }
332
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800333 aaptLinkFlags = append(aaptLinkFlags, a.additionalAaptFlags...)
334
Colin Crosse560c4a2019-03-19 16:03:11 -0700335 a.aapt.splitNames = a.appProperties.Package_splits
Colin Cross50ddcc42019-05-16 12:28:22 -0700336 a.aapt.sdkLibraries = a.exportedSdkLibs
Baligh Uddin5b16dfb2020-02-11 17:27:19 -0800337 a.aapt.LoggingParent = String(a.overridableAppProperties.Logging_parent)
Jaewoong Jungde4c02f2019-01-22 11:19:56 -0800338 a.aapt.buildActions(ctx, sdkContext(a), aaptLinkFlags...)
Colin Cross30e076a2015-04-13 13:58:27 -0700339
Colin Cross46c9b8b2017-06-22 16:51:17 -0700340 // apps manifests are handled by aapt, don't let Module see them
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700341 a.properties.Manifest = nil
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800342}
Colin Cross30e076a2015-04-13 13:58:27 -0700343
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800344func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) {
Colin Cross89c31582018-04-30 15:55:11 -0700345 var staticLibProguardFlagFiles android.Paths
346 ctx.VisitDirectDeps(func(m android.Module) {
347 if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
348 staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
349 }
350 })
351
352 staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
353
354 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
355 a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800356}
Colin Cross66dbc0b2017-12-28 12:23:20 -0800357
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800358func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path {
Colin Cross43f08db2018-11-12 10:13:39 -0800359
360 var installDir string
361 if ctx.ModuleName() == "framework-res" {
362 // framework-res.apk is installed as system/framework/framework-res.apk
363 installDir = "framework"
Jiyong Parkf7487312019-10-17 12:54:30 +0900364 } else if a.Privileged() {
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800365 installDir = filepath.Join("priv-app", a.installApkName)
Colin Cross43f08db2018-11-12 10:13:39 -0800366 } else {
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800367 installDir = filepath.Join("app", a.installApkName)
Colin Cross43f08db2018-11-12 10:13:39 -0800368 }
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800369 a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk")
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000370 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
Colin Cross50ddcc42019-05-16 12:28:22 -0700371
372 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
373 a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
374 a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
375 a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
376 a.dexpreopter.manifestFile = a.mergedManifestFile
377
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000378 a.deviceProperties.UncompressDex = a.dexpreopter.uncompressedDex
Colin Cross5a0dcd52018-10-05 14:20:06 -0700379
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800380 if ctx.ModuleName() != "framework-res" {
381 a.Module.compile(ctx, a.aaptSrcJar)
382 }
Colin Cross30e076a2015-04-13 13:58:27 -0700383
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800384 return a.maybeStrippedDexJarFile
385}
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800386
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800387func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath {
Colin Crossa4f08812018-10-02 22:03:40 -0700388 var jniJarFile android.WritablePath
Colin Crossa4f08812018-10-02 22:03:40 -0700389 if len(jniLibs) > 0 {
Jaewoong Jungbc625cd2019-05-06 15:48:44 -0700390 if a.shouldEmbedJnis(ctx) {
Colin Crossa4f08812018-10-02 22:03:40 -0700391 jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip")
Sasha Smundak6ad77252019-05-01 13:16:22 -0700392 TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.useEmbeddedNativeLibs(ctx))
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700393 for _, jni := range jniLibs {
394 if jni.coverageFile.Valid() {
Jaewoong Jung46984ee2020-04-07 13:07:55 -0700395 // Only collect coverage for the first target arch if this is a multilib target.
396 // TODO(jungjw): Ideally, we want to collect both reports, but that would cause coverage
397 // data file path collisions since the current coverage file path format doesn't contain
398 // arch-related strings. This is fine for now though; the code coverage team doesn't use
399 // multi-arch targets such as test_suite_* for coverage collections yet.
400 //
401 // Work with the team to come up with a new format that handles multilib modules properly
402 // and change this.
403 if len(ctx.Config().Targets[android.Android]) == 1 ||
404 ctx.Config().Targets[android.Android][0].Arch.ArchType == jni.target.Arch.ArchType {
405 a.jniCoverageOutputs = append(a.jniCoverageOutputs, jni.coverageFile.Path())
406 }
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700407 }
408 }
Colin Crossa4f08812018-10-02 22:03:40 -0700409 } else {
410 a.installJniLibs = jniLibs
411 }
412 }
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800413 return jniJarFile
414}
Colin Crossa4f08812018-10-02 22:03:40 -0700415
Jaewoong Jung0949f312019-09-11 10:25:18 -0700416func (a *AndroidApp) noticeBuildActions(ctx android.ModuleContext) {
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700417 // Collect NOTICE files from all dependencies.
418 seenModules := make(map[android.Module]bool)
419 noticePathSet := make(map[android.Path]bool)
420
421 ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
422 // Have we already seen this?
423 if _, ok := seenModules[child]; ok {
424 return false
425 }
426 seenModules[child] = true
427
428 // Skip host modules.
429 if child.Target().Os.Class == android.Host || child.Target().Os.Class == android.HostCross {
430 return false
431 }
432
Bob Badoura75b0572020-02-18 20:21:55 -0800433 paths := child.(android.Module).NoticeFiles()
434 if len(paths) > 0 {
435 for _, path := range paths {
436 noticePathSet[path] = true
437 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700438 }
439 return true
440 })
441
442 // If the app has one, add it too.
Bob Badoura75b0572020-02-18 20:21:55 -0800443 if len(a.NoticeFiles()) > 0 {
444 for _, path := range a.NoticeFiles() {
445 noticePathSet[path] = true
446 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700447 }
448
449 if len(noticePathSet) == 0 {
Jaewoong Jung98772792019-07-01 17:15:13 -0700450 return
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700451 }
452 var noticePaths []android.Path
453 for path := range noticePathSet {
454 noticePaths = append(noticePaths, path)
455 }
456 sort.Slice(noticePaths, func(i, j int) bool {
457 return noticePaths[i].String() < noticePaths[j].String()
458 })
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700459
Jaewoong Jung0949f312019-09-11 10:25:18 -0700460 a.noticeOutputs = android.BuildNoticeOutput(ctx, a.installDir, a.installApkName+".apk", noticePaths)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700461}
462
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700463// Reads and prepends a main cert from the default cert dir if it hasn't been set already, i.e. it
464// isn't a cert module reference. Also checks and enforces system cert restriction if applicable.
465func processMainCert(m android.ModuleBase, certPropValue string, certificates []Certificate, ctx android.ModuleContext) []Certificate {
466 if android.SrcIsModule(certPropValue) == "" {
467 var mainCert Certificate
468 if certPropValue != "" {
469 defaultDir := ctx.Config().DefaultAppCertificateDir(ctx)
470 mainCert = Certificate{
Colin Cross503c1d02020-01-28 14:00:53 -0800471 Pem: defaultDir.Join(ctx, certPropValue+".x509.pem"),
472 Key: defaultDir.Join(ctx, certPropValue+".pk8"),
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700473 }
474 } else {
475 pem, key := ctx.Config().DefaultAppCertificate(ctx)
Colin Cross503c1d02020-01-28 14:00:53 -0800476 mainCert = Certificate{
477 Pem: pem,
478 Key: key,
479 }
Colin Crossbd01e2a2018-10-04 15:21:03 -0700480 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700481 certificates = append([]Certificate{mainCert}, certificates...)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700482 }
483
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700484 if !m.Platform() {
485 certPath := certificates[0].Pem.String()
Jeongik Chac9464142019-01-07 12:07:27 +0900486 systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String()
487 if strings.HasPrefix(certPath, systemCertPath) {
488 enforceSystemCert := ctx.Config().EnforceSystemCertificate()
489 whitelist := ctx.Config().EnforceSystemCertificateWhitelist()
490
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700491 if enforceSystemCert && !inList(m.Name(), whitelist) {
Jeongik Chac9464142019-01-07 12:07:27 +0900492 ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.")
493 }
494 }
495 }
496
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700497 return certificates
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800498}
499
500func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross50ddcc42019-05-16 12:28:22 -0700501 var apkDeps android.Paths
502
Jeongik Cha538c0d02019-07-11 15:54:27 +0900503 a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx)
504 a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
505
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800506 // Check if the install APK name needs to be overridden.
Jaewoong Jung525443a2019-02-28 15:35:54 -0800507 a.installApkName = ctx.DeviceConfig().OverridePackageNameFor(a.Name())
Jaewoong Jung9d22a912019-01-23 16:27:47 -0800508
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700509 if ctx.ModuleName() == "framework-res" {
510 // framework-res.apk is installed as system/framework/framework-res.apk
Jaewoong Jung0949f312019-09-11 10:25:18 -0700511 a.installDir = android.PathForModuleInstall(ctx, "framework")
Jiyong Parkf7487312019-10-17 12:54:30 +0900512 } else if a.Privileged() {
Jaewoong Jung0949f312019-09-11 10:25:18 -0700513 a.installDir = android.PathForModuleInstall(ctx, "priv-app", a.installApkName)
514 } else if ctx.InstallInTestcases() {
Jaewoong Jung326a9412019-11-21 10:41:00 -0800515 a.installDir = android.PathForModuleInstall(ctx, a.installApkName, ctx.DeviceConfig().DeviceArch())
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700516 } else {
Jaewoong Jung0949f312019-09-11 10:25:18 -0700517 a.installDir = android.PathForModuleInstall(ctx, "app", a.installApkName)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700518 }
Jaewoong Jung7dd4ae22019-09-27 17:13:15 -0700519 a.onDeviceDir = android.InstallPathToOnDevicePath(ctx, a.installDir)
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700520
Jaewoong Jung0949f312019-09-11 10:25:18 -0700521 a.noticeBuildActions(ctx)
Jaewoong Jung98772792019-07-01 17:15:13 -0700522 if Bool(a.appProperties.Embed_notices) || ctx.Config().IsEnvTrue("ALWAYS_EMBED_NOTICES") {
523 a.aapt.noticeFile = a.noticeOutputs.HtmlGzOutput
524 }
Jaewoong Jung5b425e22019-06-17 17:40:56 -0700525
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800526 // Process all building blocks, from AAPT to certificates.
527 a.aaptBuildActions(ctx)
528
Colin Cross50ddcc42019-05-16 12:28:22 -0700529 if a.usesLibrary.enforceUsesLibraries() {
530 manifestCheckFile := a.usesLibrary.verifyUsesLibrariesManifest(ctx, a.mergedManifestFile)
531 apkDeps = append(apkDeps, manifestCheckFile)
532 }
533
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800534 a.proguardBuildActions(ctx)
535
536 dexJarFile := a.dexBuildActions(ctx)
537
Colin Cross094cde42020-02-15 10:38:00 -0800538 jniLibs, certificateDeps := collectAppDeps(ctx, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis))
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800539 jniJarFile := a.jniBuildActions(jniLibs, ctx)
540
541 if ctx.Failed() {
542 return
543 }
544
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700545 certificates := processMainCert(a.ModuleBase, a.getCertString(ctx), certificateDeps, ctx)
546 a.certificate = certificates[0]
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800547
548 // Build a final signed app package.
Jaewoong Jung5a498812019-11-07 14:14:38 -0800549 packageFile := android.PathForModuleOut(ctx, a.installApkName+".apk")
Songchun Fan17d69e32020-03-24 20:32:24 -0700550 v4SigningRequested := Bool(a.Module.deviceProperties.V4_signature)
551 var v4SignatureFile android.WritablePath = nil
552 if v4SigningRequested {
553 v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+".apk.idsig")
554 }
555 CreateAndSignAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800556 a.outputFile = packageFile
Songchun Fan17d69e32020-03-24 20:32:24 -0700557 if v4SigningRequested {
558 a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile)
559 }
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800560
Colin Crosse560c4a2019-03-19 16:03:11 -0700561 for _, split := range a.aapt.splits {
562 // Sign the split APKs
Jaewoong Jung5a498812019-11-07 14:14:38 -0800563 packageFile := android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk")
Songchun Fan17d69e32020-03-24 20:32:24 -0700564 if v4SigningRequested {
565 v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk.idsig")
566 }
567 CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile)
Colin Crosse560c4a2019-03-19 16:03:11 -0700568 a.extraOutputFiles = append(a.extraOutputFiles, packageFile)
Songchun Fan17d69e32020-03-24 20:32:24 -0700569 if v4SigningRequested {
570 a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile)
571 }
Colin Crosse560c4a2019-03-19 16:03:11 -0700572 }
573
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800574 // Build an app bundle.
Colin Crossf6237212018-10-29 23:14:58 -0700575 bundleFile := android.PathForModuleOut(ctx, "base.zip")
576 BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
577 a.bundleFile = bundleFile
578
Jaewoong Jung590b1ae2019-01-22 16:40:58 -0800579 // Install the app package.
Jiyong Park8ba50f92019-11-13 15:01:01 +0900580 if (Bool(a.Module.properties.Installable) || ctx.Host()) && a.IsForPlatform() {
581 ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
582 for _, extra := range a.extraOutputFiles {
583 ctx.InstallFile(a.installDir, extra.Base(), extra)
584 }
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800585 }
Colin Cross30e076a2015-04-13 13:58:27 -0700586}
587
Colin Cross094cde42020-02-15 10:38:00 -0800588func collectAppDeps(ctx android.ModuleContext, shouldCollectRecursiveNativeDeps bool,
589 checkNativeSdkVersion bool) ([]jniLib, []Certificate) {
Colin Crossa4f08812018-10-02 22:03:40 -0700590 var jniLibs []jniLib
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900591 var certificates []Certificate
Peter Collingbournead84f972019-12-17 16:46:18 -0800592 seenModulePaths := make(map[string]bool)
Colin Crossa4f08812018-10-02 22:03:40 -0700593
Peter Collingbournead84f972019-12-17 16:46:18 -0800594 ctx.WalkDeps(func(module android.Module, parent android.Module) bool {
Colin Crossa4f08812018-10-02 22:03:40 -0700595 otherName := ctx.OtherModuleName(module)
596 tag := ctx.OtherModuleDependencyTag(module)
597
Peter Collingbournead84f972019-12-17 16:46:18 -0800598 if IsJniDepTag(tag) || tag == cc.SharedDepTag {
Colin Crossa4f08812018-10-02 22:03:40 -0700599 if dep, ok := module.(*cc.Module); ok {
Peter Collingbournead84f972019-12-17 16:46:18 -0800600 if dep.IsNdk() || dep.IsStubs() {
601 return false
602 }
603
Colin Crossa4f08812018-10-02 22:03:40 -0700604 lib := dep.OutputFile()
Peter Collingbournead84f972019-12-17 16:46:18 -0800605 path := lib.Path()
606 if seenModulePaths[path.String()] {
607 return false
608 }
609 seenModulePaths[path.String()] = true
610
Colin Cross094cde42020-02-15 10:38:00 -0800611 if checkNativeSdkVersion {
612 if app, ok := ctx.Module().(interface{ sdkVersion() sdkSpec }); ok {
613 if app.sdkVersion().specified() &&
614 app.sdkVersion().kind != sdkCorePlatform &&
615 dep.SdkVersion() == "" {
616 ctx.PropertyErrorf("jni_libs",
617 "JNI dependency %q uses platform APIs, but this module does not",
618 otherName)
619 }
620 }
621 }
622
Colin Crossa4f08812018-10-02 22:03:40 -0700623 if lib.Valid() {
624 jniLibs = append(jniLibs, jniLib{
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700625 name: ctx.OtherModuleName(module),
626 path: path,
627 target: module.Target(),
628 coverageFile: dep.CoverageOutputFile(),
Colin Crossa4f08812018-10-02 22:03:40 -0700629 })
630 } else {
631 ctx.ModuleErrorf("dependency %q missing output file", otherName)
632 }
633 } else {
634 ctx.ModuleErrorf("jni_libs dependency %q must be a cc library", otherName)
Colin Crossa4f08812018-10-02 22:03:40 -0700635 }
Peter Collingbournead84f972019-12-17 16:46:18 -0800636
637 return shouldCollectRecursiveNativeDeps
638 }
639
640 if tag == certificateTag {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700641 if dep, ok := module.(*AndroidAppCertificate); ok {
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900642 certificates = append(certificates, dep.Certificate)
Colin Crossbd01e2a2018-10-04 15:21:03 -0700643 } else {
644 ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName)
645 }
Colin Crossa4f08812018-10-02 22:03:40 -0700646 }
Peter Collingbournead84f972019-12-17 16:46:18 -0800647
648 return false
Colin Crossa4f08812018-10-02 22:03:40 -0700649 })
650
Colin Crossbd01e2a2018-10-04 15:21:03 -0700651 return jniLibs, certificates
Colin Crossa4f08812018-10-02 22:03:40 -0700652}
653
Colin Cross0ea8ba82019-06-06 14:33:29 -0700654func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string {
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800655 certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
656 if overridden {
Jaewoong Jungacb6db32019-02-28 16:22:30 +0000657 return ":" + certificate
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800658 }
Jaewoong Jung525443a2019-02-28 15:35:54 -0800659 return String(a.overridableAppProperties.Certificate)
Jaewoong Jung2ad817c2019-01-18 14:27:16 -0800660}
661
Jiyong Park0f80c182020-01-31 02:49:53 +0900662func (a *AndroidApp) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
663 if IsJniDepTag(ctx.OtherModuleDependencyTag(dep)) {
664 return true
665 }
666 return a.Library.DepIsInSameApex(ctx, dep)
667}
668
Jiyong Parkb7c639e2019-08-19 14:56:02 +0900669// For OutputFileProducer interface
670func (a *AndroidApp) OutputFiles(tag string) (android.Paths, error) {
671 switch tag {
672 case ".aapt.srcjar":
673 return []android.Path{a.aaptSrcJar}, nil
674 }
675 return a.Library.OutputFiles(tag)
676}
677
Jiyong Parkf7487312019-10-17 12:54:30 +0900678func (a *AndroidApp) Privileged() bool {
679 return Bool(a.appProperties.Privileged)
680}
681
Jaewoong Jung87a33e72020-03-26 14:01:48 -0700682func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
683 return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
684}
685
686func (a *AndroidApp) PreventInstall() {
687 a.appProperties.PreventInstall = true
688}
689
690func (a *AndroidApp) HideFromMake() {
691 a.appProperties.HideFromMake = true
692}
693
694func (a *AndroidApp) MarkAsCoverageVariant(coverage bool) {
695 a.appProperties.IsCoverageVariant = coverage
696}
697
698var _ cc.Coverage = (*AndroidApp)(nil)
699
Colin Cross1b16b0e2019-02-12 14:41:32 -0800700// android_app compiles sources and Android resources into an Android application package `.apk` file.
Colin Cross36242852017-06-23 15:06:31 -0700701func AndroidAppFactory() android.Module {
Colin Cross30e076a2015-04-13 13:58:27 -0700702 module := &AndroidApp{}
703
Sasha Smundak2057f822019-04-16 17:16:58 -0700704 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross66dbc0b2017-12-28 12:23:20 -0800705 module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
706
Colin Crossae5caf52018-05-22 11:11:52 -0700707 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700708 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crossae5caf52018-05-22 11:11:52 -0700709
Colin Cross36242852017-06-23 15:06:31 -0700710 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -0700711 &module.Module.properties,
712 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800713 &module.Module.dexpreoptProperties,
Colin Crossa97c5d32018-03-28 14:58:31 -0700714 &module.Module.protoProperties,
715 &module.aaptProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -0800716 &module.appProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -0700717 &module.overridableAppProperties,
718 &module.usesLibrary.usesLibraryProperties)
Colin Cross36242852017-06-23 15:06:31 -0700719
Colin Crossa9d8bee2018-10-02 13:59:46 -0700720 module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
721 return class == android.Device && ctx.Config().DevicePrefer32BitApps()
722 })
723
Colin Crossa4f08812018-10-02 22:03:40 -0700724 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
725 android.InitDefaultableModule(module)
Jaewoong Jung525443a2019-02-28 15:35:54 -0800726 android.InitOverridableModule(module, &module.appProperties.Overrides)
Jiyong Park52cd06f2019-11-11 10:14:32 +0900727 android.InitApexModule(module)
Colin Crossa4f08812018-10-02 22:03:40 -0700728
Colin Cross36242852017-06-23 15:06:31 -0700729 return module
Colin Cross30e076a2015-04-13 13:58:27 -0700730}
Colin Crossae5caf52018-05-22 11:11:52 -0700731
732type appTestProperties struct {
733 Instrumentation_for *string
Jaewoong Jung26dedd32019-06-06 08:45:58 -0700734
735 // if specified, the instrumentation target package name in the manifest is overwritten by it.
736 Instrumentation_target_package *string
Colin Crossae5caf52018-05-22 11:11:52 -0700737}
738
739type AndroidTest struct {
740 AndroidApp
741
742 appTestProperties appTestProperties
743
744 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -0700745
746 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -0700747 data android.Paths
Colin Crossae5caf52018-05-22 11:11:52 -0700748}
749
Jaewoong Jung0949f312019-09-11 10:25:18 -0700750func (a *AndroidTest) InstallInTestcases() bool {
751 return true
752}
753
Colin Crossae5caf52018-05-22 11:11:52 -0700754func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jung26dedd32019-06-06 08:45:58 -0700755 if a.appTestProperties.Instrumentation_target_package != nil {
756 a.additionalAaptFlags = append(a.additionalAaptFlags,
757 "--rename-instrumentation-target-package "+*a.appTestProperties.Instrumentation_target_package)
758 } else if a.appTestProperties.Instrumentation_for != nil {
759 // Check if the instrumentation target package is overridden.
Jaewoong Jung4102e5d2019-02-27 16:26:28 -0800760 manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(*a.appTestProperties.Instrumentation_for)
761 if overridden {
762 a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+manifestPackageName)
763 }
764 }
Colin Crossae5caf52018-05-22 11:11:52 -0700765 a.generateAndroidBuildActions(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -0700766
Jaewoong Jung39982342020-01-14 10:27:18 -0800767 testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config,
Dan Shi6ffaaa82019-09-26 11:41:36 -0700768 a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config)
Jaewoong Jung39982342020-01-14 10:27:18 -0800769 a.testConfig = a.FixTestConfig(ctx, testConfig)
Colin Cross8a497952019-03-05 22:25:09 -0800770 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -0700771}
772
Jaewoong Jung39982342020-01-14 10:27:18 -0800773func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
774 if testConfig == nil {
775 return nil
776 }
777
778 fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml")
779 rule := android.NewRuleBuilder()
780 command := rule.Command().BuiltTool(ctx, "test_config_fixer").Input(testConfig).Output(fixedConfig)
781 fixNeeded := false
782
783 if ctx.ModuleName() != a.installApkName {
784 fixNeeded = true
785 command.FlagWithArg("--test-file-name ", a.installApkName+".apk")
786 }
787
788 if a.overridableAppProperties.Package_name != nil {
789 fixNeeded = true
790 command.FlagWithInput("--manifest ", a.manifestPath).
791 FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name)
792 }
793
794 if fixNeeded {
795 rule.Build(pctx, ctx, "fix_test_config", "fix test config")
796 return fixedConfig
797 }
798 return testConfig
799}
800
Colin Cross303e21f2018-08-07 16:49:25 -0700801func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross303e21f2018-08-07 16:49:25 -0700802 a.AndroidApp.DepsMutator(ctx)
Jaewoong Jung26dedd32019-06-06 08:45:58 -0700803}
804
805func (a *AndroidTest) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
806 a.AndroidApp.OverridablePropertiesDepsMutator(ctx)
Colin Cross4b964c02018-10-15 16:18:06 -0700807 if a.appTestProperties.Instrumentation_for != nil {
808 // The android_app dependency listed in instrumentation_for needs to be added to the classpath for javac,
809 // but not added to the aapt2 link includes like a normal android_app or android_library dependency, so
810 // use instrumentationForTag instead of libTag.
811 ctx.AddVariationDependencies(nil, instrumentationForTag, String(a.appTestProperties.Instrumentation_for))
812 }
Colin Crossae5caf52018-05-22 11:11:52 -0700813}
814
Colin Cross1b16b0e2019-02-12 14:41:32 -0800815// android_test compiles test sources and Android resources into an Android application package `.apk` file and
816// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
Colin Crossae5caf52018-05-22 11:11:52 -0700817func AndroidTestFactory() android.Module {
818 module := &AndroidTest{}
819
Sasha Smundak2057f822019-04-16 17:16:58 -0700820 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross5067db92018-09-17 16:46:35 -0700821
822 module.Module.properties.Instrument = true
Colin Cross9ae1b922018-06-26 17:59:05 -0700823 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse4246ab2019-02-05 21:55:21 -0800824 module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
Colin Cross47fa9d32019-03-26 10:51:39 -0700825 module.appProperties.AlwaysPackageNativeLibs = true
Colin Cross43f08db2018-11-12 10:13:39 -0800826 module.Module.dexpreopter.isTest = true
Colin Crossae5caf52018-05-22 11:11:52 -0700827
828 module.AddProperties(
829 &module.Module.properties,
830 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800831 &module.Module.dexpreoptProperties,
Colin Crossae5caf52018-05-22 11:11:52 -0700832 &module.Module.protoProperties,
833 &module.aaptProperties,
834 &module.appProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -0700835 &module.appTestProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -0800836 &module.overridableAppProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -0700837 &module.usesLibrary.usesLibraryProperties,
Dan Willemsenf5531d22018-07-16 17:21:19 -0700838 &module.testProperties)
Colin Crossae5caf52018-05-22 11:11:52 -0700839
Colin Crossa4f08812018-10-02 22:03:40 -0700840 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
841 android.InitDefaultableModule(module)
Jaewoong Jung26dedd32019-06-06 08:45:58 -0700842 android.InitOverridableModule(module, &module.appProperties.Overrides)
Colin Crossae5caf52018-05-22 11:11:52 -0700843 return module
844}
Colin Crossbd01e2a2018-10-04 15:21:03 -0700845
Colin Cross252fc6f2018-10-04 15:22:03 -0700846type appTestHelperAppProperties struct {
847 // list of compatibility suites (for example "cts", "vts") that the module should be
848 // installed into.
849 Test_suites []string `android:"arch_variant"`
Dan Shi6ffaaa82019-09-26 11:41:36 -0700850
851 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
852 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
853 // explicitly.
854 Auto_gen_config *bool
Colin Cross252fc6f2018-10-04 15:22:03 -0700855}
856
857type AndroidTestHelperApp struct {
858 AndroidApp
859
860 appTestHelperAppProperties appTestHelperAppProperties
861}
862
Jaewoong Jung326a9412019-11-21 10:41:00 -0800863func (a *AndroidTestHelperApp) InstallInTestcases() bool {
864 return true
865}
866
Colin Cross1b16b0e2019-02-12 14:41:32 -0800867// android_test_helper_app compiles sources and Android resources into an Android application package `.apk` file that
868// will be used by tests, but does not produce an `AndroidTest.xml` file so the module will not be run directly as a
869// test.
Colin Cross252fc6f2018-10-04 15:22:03 -0700870func AndroidTestHelperAppFactory() android.Module {
871 module := &AndroidTestHelperApp{}
872
Sasha Smundak2057f822019-04-16 17:16:58 -0700873 module.Module.deviceProperties.Optimize.EnabledByDefault = true
Colin Cross252fc6f2018-10-04 15:22:03 -0700874
875 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse4246ab2019-02-05 21:55:21 -0800876 module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
Colin Cross47fa9d32019-03-26 10:51:39 -0700877 module.appProperties.AlwaysPackageNativeLibs = true
Colin Cross43f08db2018-11-12 10:13:39 -0800878 module.Module.dexpreopter.isTest = true
Colin Cross252fc6f2018-10-04 15:22:03 -0700879
880 module.AddProperties(
881 &module.Module.properties,
882 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -0800883 &module.Module.dexpreoptProperties,
Colin Cross252fc6f2018-10-04 15:22:03 -0700884 &module.Module.protoProperties,
885 &module.aaptProperties,
886 &module.appProperties,
Jaewoong Jung525443a2019-02-28 15:35:54 -0800887 &module.appTestHelperAppProperties,
Colin Cross50ddcc42019-05-16 12:28:22 -0700888 &module.overridableAppProperties,
889 &module.usesLibrary.usesLibraryProperties)
Colin Cross252fc6f2018-10-04 15:22:03 -0700890
891 android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
892 android.InitDefaultableModule(module)
Anton Hansson3d2b6b42020-01-10 15:06:01 +0000893 android.InitApexModule(module)
Colin Cross252fc6f2018-10-04 15:22:03 -0700894 return module
895}
896
Colin Crossbd01e2a2018-10-04 15:21:03 -0700897type AndroidAppCertificate struct {
898 android.ModuleBase
899 properties AndroidAppCertificateProperties
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900900 Certificate Certificate
Colin Crossbd01e2a2018-10-04 15:21:03 -0700901}
902
903type AndroidAppCertificateProperties struct {
904 // Name of the certificate files. Extensions .x509.pem and .pk8 will be added to the name.
905 Certificate *string
906}
907
Colin Cross1b16b0e2019-02-12 14:41:32 -0800908// android_app_certificate modules can be referenced by the certificates property of android_app modules to select
909// the signing key.
Colin Crossbd01e2a2018-10-04 15:21:03 -0700910func AndroidAppCertificateFactory() android.Module {
911 module := &AndroidAppCertificate{}
912 module.AddProperties(&module.properties)
913 android.InitAndroidModule(module)
914 return module
915}
916
Colin Crossbd01e2a2018-10-04 15:21:03 -0700917func (c *AndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
918 cert := String(c.properties.Certificate)
Jiyong Parkc00cbd92018-10-30 21:20:05 +0900919 c.Certificate = Certificate{
Colin Cross503c1d02020-01-28 14:00:53 -0800920 Pem: android.PathForModuleSrc(ctx, cert+".x509.pem"),
921 Key: android.PathForModuleSrc(ctx, cert+".pk8"),
Colin Crossbd01e2a2018-10-04 15:21:03 -0700922 }
923}
Jaewoong Jung525443a2019-02-28 15:35:54 -0800924
925type OverrideAndroidApp struct {
926 android.ModuleBase
927 android.OverrideModuleBase
928}
929
930func (i *OverrideAndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
931 // All the overrides happen in the base module.
932 // TODO(jungjw): Check the base module type.
933}
934
935// override_android_app is used to create an android_app module based on another android_app by overriding
936// some of its properties.
937func OverrideAndroidAppModuleFactory() android.Module {
938 m := &OverrideAndroidApp{}
939 m.AddProperties(&overridableAppProperties{})
940
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700941 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
Jaewoong Jung525443a2019-02-28 15:35:54 -0800942 android.InitOverrideModule(m)
943 return m
944}
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700945
Jaewoong Jung26dedd32019-06-06 08:45:58 -0700946type OverrideAndroidTest struct {
947 android.ModuleBase
948 android.OverrideModuleBase
949}
950
951func (i *OverrideAndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
952 // All the overrides happen in the base module.
953 // TODO(jungjw): Check the base module type.
954}
955
956// override_android_test is used to create an android_app module based on another android_test by overriding
957// some of its properties.
958func OverrideAndroidTestModuleFactory() android.Module {
959 m := &OverrideAndroidTest{}
960 m.AddProperties(&overridableAppProperties{})
961 m.AddProperties(&appTestProperties{})
962
963 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
964 android.InitOverrideModule(m)
965 return m
966}
967
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700968type AndroidAppImport struct {
969 android.ModuleBase
970 android.DefaultableModuleBase
971 prebuilt android.Prebuilt
972
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -0700973 properties AndroidAppImportProperties
974 dpiVariants interface{}
975 archVariants interface{}
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700976
977 outputFile android.Path
Colin Cross503c1d02020-01-28 14:00:53 -0800978 certificate Certificate
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700979
980 dexpreopter
Colin Cross50ddcc42019-05-16 12:28:22 -0700981
982 usesLibrary usesLibrary
Jaewoong Jung8aae22e2019-07-17 10:21:49 -0700983
Colin Cross70dda7e2019-10-01 22:05:35 -0700984 installPath android.InstallPath
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700985}
986
987type AndroidAppImportProperties struct {
988 // A prebuilt apk to import
Jaewoong Jung3e18b192019-06-11 12:25:34 -0700989 Apk *string
Jaewoong Junga5e5abc2019-04-26 14:31:50 -0700990
Jaewoong Jung961d4fd2019-08-22 14:25:58 -0700991 // The name of a certificate in the default certificate directory or an android_app_certificate
992 // module name in the form ":module". Should be empty if presigned or default_dev_cert is set.
Jaewoong Jungccbb3932019-04-15 09:48:31 -0700993 Certificate *string
994
995 // Set this flag to true if the prebuilt apk is already signed. The certificate property must not
996 // be set for presigned modules.
997 Presigned *bool
998
Jaewoong Jung961d4fd2019-08-22 14:25:58 -0700999 // Sign with the default system dev certificate. Must be used judiciously. Most imported apps
1000 // need to either specify a specific certificate or be presigned.
1001 Default_dev_cert *bool
1002
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001003 // Specifies that this app should be installed to the priv-app directory,
1004 // where the system will grant it additional privileges not available to
1005 // normal apps.
1006 Privileged *bool
1007
1008 // Names of modules to be overridden. Listed modules can only be other binaries
1009 // (in Make or Soong).
1010 // This does not completely prevent installation of the overridden binaries, but if both
1011 // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
1012 // from PRODUCT_PACKAGES.
1013 Overrides []string
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001014
1015 // Optional name for the installed app. If unspecified, it is derived from the module name.
1016 Filename *string
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001017}
1018
Martin Stjernholm6d415272020-01-31 17:10:36 +00001019func (a *AndroidAppImport) IsInstallable() bool {
1020 return true
1021}
1022
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001023// Updates properties with variant-specific values.
1024func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) {
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001025 config := ctx.Config()
1026
1027 dpiProps := reflect.ValueOf(a.dpiVariants).Elem().FieldByName("Dpi_variants")
1028 // Try DPI variant matches in the reverse-priority order so that the highest priority match
1029 // overwrites everything else.
1030 // TODO(jungjw): Can we optimize this by making it priority order?
1031 for i := len(config.ProductAAPTPrebuiltDPI()) - 1; i >= 0; i-- {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001032 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPrebuiltDPI()[i])
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001033 }
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001034 if config.ProductAAPTPreferredConfig() != "" {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001035 MergePropertiesFromVariant(ctx, &a.properties, dpiProps, config.ProductAAPTPreferredConfig())
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001036 }
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001037
1038 archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName("Arch")
1039 archType := ctx.Config().Targets[android.Android][0].Arch.ArchType
1040 MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name)
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001041}
1042
Colin Cross1184b642019-12-30 18:43:07 -08001043func MergePropertiesFromVariant(ctx android.EarlyModuleContext,
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001044 dst interface{}, variantGroup reflect.Value, variant string) {
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001045 src := variantGroup.FieldByName(proptools.FieldNameForProperty(variant))
1046 if !src.IsValid() {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001047 return
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001048 }
1049
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001050 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, proptools.OrderAppend)
1051 if err != nil {
1052 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
1053 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
1054 } else {
1055 panic(err)
1056 }
1057 }
Jaewoong Junga5e5abc2019-04-26 14:31:50 -07001058}
1059
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001060func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) {
1061 cert := android.SrcIsModule(String(a.properties.Certificate))
1062 if cert != "" {
1063 ctx.AddDependency(ctx.Module(), certificateTag, cert)
1064 }
Colin Cross50ddcc42019-05-16 12:28:22 -07001065
Paul Duffin250e6192019-06-07 10:44:37 +01001066 a.usesLibrary.deps(ctx, true)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001067}
1068
1069func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
1070 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001071 // Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
1072 // with them may invalidate pre-existing signature data.
1073 if ctx.InstallInTestcases() && Bool(a.properties.Presigned) {
1074 ctx.Build(pctx, android.BuildParams{
1075 Rule: android.Cp,
1076 Output: outputPath,
1077 Input: inputPath,
1078 })
1079 return
1080 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001081 rule := android.NewRuleBuilder()
1082 rule.Command().
1083 Textf(`if (zipinfo %s 'lib/*.so' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
Colin Crossee94d6a2019-07-08 17:08:34 -07001084 BuiltTool(ctx, "zip2zip").
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001085 FlagWithInput("-i ", inputPath).
1086 FlagWithOutput("-o ", outputPath).
1087 FlagWithArg("-0 ", "'lib/**/*.so'").
1088 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
1089 rule.Build(pctx, ctx, "uncompress-embedded-jni-libs", "Uncompress embedded JIN libs")
1090}
1091
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001092// Returns whether this module should have the dex file stored uncompressed in the APK.
1093func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
1094 if ctx.Config().UnbundledBuild() {
1095 return false
1096 }
1097
1098 // Uncompress dex in APKs of privileged apps
Jiyong Parkf7487312019-10-17 12:54:30 +09001099 if ctx.Config().UncompressPrivAppDex() && a.Privileged() {
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001100 return true
1101 }
1102
1103 return shouldUncompressDex(ctx, &a.dexpreopter)
1104}
1105
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001106func (a *AndroidAppImport) uncompressDex(
1107 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
1108 rule := android.NewRuleBuilder()
1109 rule.Command().
1110 Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
Colin Crossee94d6a2019-07-08 17:08:34 -07001111 BuiltTool(ctx, "zip2zip").
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001112 FlagWithInput("-i ", inputPath).
1113 FlagWithOutput("-o ", outputPath).
1114 FlagWithArg("-0 ", "'classes*.dex'").
1115 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
1116 rule.Build(pctx, ctx, "uncompress-dex", "Uncompress dex files")
1117}
1118
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001119func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001120 a.generateAndroidBuildActions(ctx)
1121}
1122
1123func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001124 numCertPropsSet := 0
1125 if String(a.properties.Certificate) != "" {
1126 numCertPropsSet++
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001127 }
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001128 if Bool(a.properties.Presigned) {
1129 numCertPropsSet++
1130 }
1131 if Bool(a.properties.Default_dev_cert) {
1132 numCertPropsSet++
1133 }
1134 if numCertPropsSet != 1 {
1135 ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001136 }
1137
Colin Cross094cde42020-02-15 10:38:00 -08001138 _, certificates := collectAppDeps(ctx, false, false)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001139
1140 // TODO: LOCAL_EXTRACT_APK/LOCAL_EXTRACT_DPI_APK
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001141 // TODO: LOCAL_PACKAGE_SPLITS
1142
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001143 srcApk := a.prebuilt.SingleSourcePath(ctx)
Colin Cross50ddcc42019-05-16 12:28:22 -07001144
1145 if a.usesLibrary.enforceUsesLibraries() {
1146 srcApk = a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk)
1147 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001148
1149 // TODO: Install or embed JNI libraries
1150
1151 // Uncompress JNI libraries in the apk
1152 jnisUncompressed := android.PathForModuleOut(ctx, "jnis-uncompressed", ctx.ModuleName()+".apk")
1153 a.uncompressEmbeddedJniLibs(ctx, srcApk, jnisUncompressed.OutputPath)
1154
Kyeongkab.Namc4997142019-11-22 11:38:16 +09001155 var installDir android.InstallPath
1156 if Bool(a.properties.Privileged) {
1157 installDir = android.PathForModuleInstall(ctx, "priv-app", a.BaseModuleName())
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001158 } else if ctx.InstallInTestcases() {
1159 installDir = android.PathForModuleInstall(ctx, a.BaseModuleName(), ctx.DeviceConfig().DeviceArch())
Kyeongkab.Namc4997142019-11-22 11:38:16 +09001160 } else {
1161 installDir = android.PathForModuleInstall(ctx, "app", a.BaseModuleName())
1162 }
1163
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001164 a.dexpreopter.installPath = installDir.Join(ctx, a.BaseModuleName()+".apk")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001165 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
Jaewoong Jungacf18d72019-05-02 14:55:29 -07001166 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
Colin Cross50ddcc42019-05-16 12:28:22 -07001167
1168 a.dexpreopter.enforceUsesLibs = a.usesLibrary.enforceUsesLibraries()
1169 a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs
1170 a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx)
1171 a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx)
1172
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001173 dexOutput := a.dexpreopter.dexpreopt(ctx, jnisUncompressed)
Jaewoong Jungea1bdb02019-05-09 14:36:34 -07001174 if a.dexpreopter.uncompressedDex {
1175 dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk")
1176 a.uncompressDex(ctx, dexOutput, dexUncompressed.OutputPath)
1177 dexOutput = dexUncompressed
1178 }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001179
1180 // Sign or align the package
1181 // TODO: Handle EXTERNAL
1182 if !Bool(a.properties.Presigned) {
Jaewoong Jung961d4fd2019-08-22 14:25:58 -07001183 // If the certificate property is empty at this point, default_dev_cert must be set to true.
1184 // Which makes processMainCert's behavior for the empty cert string WAI.
1185 certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001186 if len(certificates) != 1 {
1187 ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
1188 }
Colin Cross503c1d02020-01-28 14:00:53 -08001189 a.certificate = certificates[0]
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001190 signed := android.PathForModuleOut(ctx, "signed", ctx.ModuleName()+".apk")
Songchun Fan17d69e32020-03-24 20:32:24 -07001191 SignAppPackage(ctx, signed, dexOutput, certificates, nil)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001192 a.outputFile = signed
1193 } else {
1194 alignedApk := android.PathForModuleOut(ctx, "zip-aligned", ctx.ModuleName()+".apk")
1195 TransformZipAlign(ctx, alignedApk, dexOutput)
1196 a.outputFile = alignedApk
Colin Cross503c1d02020-01-28 14:00:53 -08001197 a.certificate = presignedCertificate
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001198 }
1199
1200 // TODO: Optionally compress the output apk.
1201
Jaewoong Jung8aae22e2019-07-17 10:21:49 -07001202 a.installPath = ctx.InstallFile(installDir,
1203 proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk"), a.outputFile)
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001204
1205 // TODO: androidmk converter jni libs
1206}
1207
1208func (a *AndroidAppImport) Prebuilt() *android.Prebuilt {
1209 return &a.prebuilt
1210}
1211
1212func (a *AndroidAppImport) Name() string {
1213 return a.prebuilt.Name(a.ModuleBase.Name())
1214}
1215
Dario Frenicde2a032019-10-27 00:29:22 +01001216func (a *AndroidAppImport) OutputFile() android.Path {
1217 return a.outputFile
1218}
1219
Jiyong Park618922e2020-01-08 13:35:43 +09001220func (a *AndroidAppImport) JacocoReportClassesFile() android.Path {
1221 return nil
1222}
1223
Colin Cross503c1d02020-01-28 14:00:53 -08001224func (a *AndroidAppImport) Certificate() Certificate {
1225 return a.certificate
1226}
1227
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001228var dpiVariantGroupType reflect.Type
1229var archVariantGroupType reflect.Type
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001230
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001231func initAndroidAppImportVariantGroupTypes() {
1232 dpiVariantGroupType = createVariantGroupType(supportedDpis, "Dpi_variants")
1233
1234 archNames := make([]string, len(android.ArchTypeList()))
1235 for i, archType := range android.ArchTypeList() {
1236 archNames[i] = archType.Name
1237 }
1238 archVariantGroupType = createVariantGroupType(archNames, "Arch")
1239}
1240
1241// Populates all variant struct properties at creation time.
1242func (a *AndroidAppImport) populateAllVariantStructs() {
1243 a.dpiVariants = reflect.New(dpiVariantGroupType).Interface()
1244 a.AddProperties(a.dpiVariants)
1245
1246 a.archVariants = reflect.New(archVariantGroupType).Interface()
1247 a.AddProperties(a.archVariants)
1248}
1249
Jiyong Parkf7487312019-10-17 12:54:30 +09001250func (a *AndroidAppImport) Privileged() bool {
1251 return Bool(a.properties.Privileged)
1252}
1253
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001254func createVariantGroupType(variants []string, variantGroupName string) reflect.Type {
1255 props := reflect.TypeOf((*AndroidAppImportProperties)(nil))
1256
1257 variantFields := make([]reflect.StructField, len(variants))
1258 for i, variant := range variants {
1259 variantFields[i] = reflect.StructField{
1260 Name: proptools.FieldNameForProperty(variant),
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001261 Type: props,
1262 }
1263 }
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001264
1265 variantGroupStruct := reflect.StructOf(variantFields)
1266 return reflect.StructOf([]reflect.StructField{
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001267 {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001268 Name: variantGroupName,
1269 Type: variantGroupStruct,
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001270 },
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001271 })
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001272}
1273
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001274// android_app_import imports a prebuilt apk with additional processing specified in the module.
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001275// DPI-specific apk source files can be specified using dpi_variants. Example:
1276//
1277// android_app_import {
1278// name: "example_import",
1279// apk: "prebuilts/example.apk",
1280// dpi_variants: {
1281// mdpi: {
1282// apk: "prebuilts/example_mdpi.apk",
1283// },
1284// xhdpi: {
1285// apk: "prebuilts/example_xhdpi.apk",
1286// },
1287// },
1288// certificate: "PRESIGNED",
1289// }
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001290func AndroidAppImportFactory() android.Module {
1291 module := &AndroidAppImport{}
1292 module.AddProperties(&module.properties)
1293 module.AddProperties(&module.dexpreoptProperties)
Colin Cross50ddcc42019-05-16 12:28:22 -07001294 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001295 module.populateAllVariantStructs()
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001296 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -07001297 module.processVariants(ctx)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001298 })
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001299
1300 InitJavaModule(module, android.DeviceSupported)
Jaewoong Jung3e18b192019-06-11 12:25:34 -07001301 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
Jaewoong Jungccbb3932019-04-15 09:48:31 -07001302
1303 return module
1304}
Colin Cross50ddcc42019-05-16 12:28:22 -07001305
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001306type AndroidTestImport struct {
1307 AndroidAppImport
1308
1309 testProperties testProperties
1310
1311 data android.Paths
1312}
1313
1314func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1315 a.generateAndroidBuildActions(ctx)
1316
1317 a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
1318}
1319
Jaewoong Jung7c5bd832020-01-13 09:55:39 -08001320func (a *AndroidTestImport) InstallInTestcases() bool {
1321 return true
1322}
1323
Jaewoong Jungb28eb5f2019-08-27 15:01:50 -07001324// android_test_import imports a prebuilt test apk with additional processing specified in the
1325// module. DPI or arch variant configurations can be made as with android_app_import.
1326func AndroidTestImportFactory() android.Module {
1327 module := &AndroidTestImport{}
1328 module.AddProperties(&module.properties)
1329 module.AddProperties(&module.dexpreoptProperties)
1330 module.AddProperties(&module.usesLibrary.usesLibraryProperties)
1331 module.AddProperties(&module.testProperties)
1332 module.populateAllVariantStructs()
1333 android.AddLoadHook(module, func(ctx android.LoadHookContext) {
1334 module.processVariants(ctx)
1335 })
1336
1337 InitJavaModule(module, android.DeviceSupported)
1338 android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
1339
1340 return module
1341}
1342
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001343type RuntimeResourceOverlay struct {
1344 android.ModuleBase
1345 android.DefaultableModuleBase
1346 aapt
1347
1348 properties RuntimeResourceOverlayProperties
1349
Jaewoong Jung78ec5d82020-01-31 10:11:47 -08001350 certificate Certificate
1351
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001352 outputFile android.Path
1353 installDir android.InstallPath
1354}
1355
1356type RuntimeResourceOverlayProperties struct {
1357 // the name of a certificate in the default certificate directory or an android_app_certificate
1358 // module name in the form ":module".
1359 Certificate *string
1360
1361 // optional theme name. If specified, the overlay package will be applied
1362 // only when the ro.boot.vendor.overlay.theme system property is set to the same value.
1363 Theme *string
1364
1365 // if not blank, set to the version of the sdk to compile against.
1366 // Defaults to compiling against the current platform.
1367 Sdk_version *string
1368
1369 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
1370 // Defaults to sdk_version if not set.
1371 Min_sdk_version *string
1372}
1373
1374func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) {
1375 sdkDep := decodeSdkDep(ctx, sdkContext(r))
1376 if sdkDep.hasFrameworkLibs() {
1377 r.aapt.deps(ctx, sdkDep)
1378 }
1379
1380 cert := android.SrcIsModule(String(r.properties.Certificate))
1381 if cert != "" {
1382 ctx.AddDependency(ctx.Module(), certificateTag, cert)
1383 }
1384}
1385
1386func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1387 // Compile and link resources
1388 r.aapt.hasNoCode = true
Jaewoong Jungf0f747c2020-01-24 10:30:02 -08001389 // Do not remove resources without default values nor dedupe resource configurations with the same value
1390 r.aapt.buildActions(ctx, r, "--no-resource-deduping", "--no-resource-removal")
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001391
1392 // Sign the built package
Colin Cross094cde42020-02-15 10:38:00 -08001393 _, certificates := collectAppDeps(ctx, false, false)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001394 certificates = processMainCert(r.ModuleBase, String(r.properties.Certificate), certificates, ctx)
1395 signed := android.PathForModuleOut(ctx, "signed", r.Name()+".apk")
Songchun Fan17d69e32020-03-24 20:32:24 -07001396 SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, nil)
Jaewoong Jung78ec5d82020-01-31 10:11:47 -08001397 r.certificate = certificates[0]
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001398
1399 r.outputFile = signed
1400 r.installDir = android.PathForModuleInstall(ctx, "overlay", String(r.properties.Theme))
1401 ctx.InstallFile(r.installDir, r.outputFile.Base(), r.outputFile)
1402}
1403
Jiyong Park6a927c42020-01-21 02:03:43 +09001404func (r *RuntimeResourceOverlay) sdkVersion() sdkSpec {
1405 return sdkSpecFrom(String(r.properties.Sdk_version))
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001406}
1407
1408func (r *RuntimeResourceOverlay) systemModules() string {
1409 return ""
1410}
1411
Jiyong Park6a927c42020-01-21 02:03:43 +09001412func (r *RuntimeResourceOverlay) minSdkVersion() sdkSpec {
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001413 if r.properties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +09001414 return sdkSpecFrom(*r.properties.Min_sdk_version)
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001415 }
1416 return r.sdkVersion()
1417}
1418
Jiyong Park6a927c42020-01-21 02:03:43 +09001419func (r *RuntimeResourceOverlay) targetSdkVersion() sdkSpec {
Jaewoong Jung9befb0c2020-01-18 10:33:43 -08001420 return r.sdkVersion()
1421}
1422
1423// runtime_resource_overlay generates a resource-only apk file that can overlay application and
1424// system resources at run time.
1425func RuntimeResourceOverlayFactory() android.Module {
1426 module := &RuntimeResourceOverlay{}
1427 module.AddProperties(
1428 &module.properties,
1429 &module.aaptProperties)
1430
1431 InitJavaModule(module, android.DeviceSupported)
1432
1433 return module
1434}
1435
Colin Cross50ddcc42019-05-16 12:28:22 -07001436type UsesLibraryProperties struct {
1437 // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file.
1438 Uses_libs []string
1439
1440 // A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file with
1441 // required=false.
1442 Optional_uses_libs []string
1443
1444 // If true, the list of uses_libs and optional_uses_libs modules must match the AndroidManifest.xml file. Defaults
1445 // to true if either uses_libs or optional_uses_libs is set. Will unconditionally default to true in the future.
1446 Enforce_uses_libs *bool
1447}
1448
1449// usesLibrary provides properties and helper functions for AndroidApp and AndroidAppImport to verify that the
1450// <uses-library> tags that end up in the manifest of an APK match the ones known to the build system through the
1451// uses_libs and optional_uses_libs properties. The build system's values are used by dexpreopt to preopt apps
1452// with knowledge of their shared libraries.
1453type usesLibrary struct {
1454 usesLibraryProperties UsesLibraryProperties
1455}
1456
Paul Duffin250e6192019-06-07 10:44:37 +01001457func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs bool) {
Colin Cross3245b2c2019-06-07 13:18:09 -07001458 if !ctx.Config().UnbundledBuild() {
1459 ctx.AddVariationDependencies(nil, usesLibTag, u.usesLibraryProperties.Uses_libs...)
1460 ctx.AddVariationDependencies(nil, usesLibTag, u.presentOptionalUsesLibs(ctx)...)
Paul Duffin250e6192019-06-07 10:44:37 +01001461 // Only add these extra dependencies if the module depends on framework libs. This avoids
1462 // creating a cyclic dependency:
1463 // e.g. framework-res -> org.apache.http.legacy -> ... -> framework-res.
1464 if hasFrameworkLibs {
Colin Cross3245b2c2019-06-07 13:18:09 -07001465 // dexpreopt/dexpreopt.go needs the paths to the dex jars of these libraries in case construct_context.sh needs
1466 // to pass them to dex2oat. Add them as a dependency so we can determine the path to the dex jar of each
1467 // library to dexpreopt.
1468 ctx.AddVariationDependencies(nil, usesLibTag,
1469 "org.apache.http.legacy",
1470 "android.hidl.base-V1.0-java",
1471 "android.hidl.manager-V1.0-java")
1472 }
Colin Cross50ddcc42019-05-16 12:28:22 -07001473 }
1474}
1475
1476// presentOptionalUsesLibs returns optional_uses_libs after filtering out MissingUsesLibraries, which don't exist in the
1477// build.
1478func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []string {
1479 optionalUsesLibs, _ := android.FilterList(u.usesLibraryProperties.Optional_uses_libs, ctx.Config().MissingUsesLibraries())
1480 return optionalUsesLibs
1481}
1482
1483// usesLibraryPaths returns a map of module names of shared library dependencies to the paths to their dex jars.
1484func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) map[string]android.Path {
1485 usesLibPaths := make(map[string]android.Path)
1486
1487 if !ctx.Config().UnbundledBuild() {
1488 ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
1489 if lib, ok := m.(Dependency); ok {
1490 if dexJar := lib.DexJar(); dexJar != nil {
1491 usesLibPaths[ctx.OtherModuleName(m)] = dexJar
1492 } else {
1493 ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must produce a dex jar, does it have installable: true?",
1494 ctx.OtherModuleName(m))
1495 }
1496 } else if ctx.Config().AllowMissingDependencies() {
1497 ctx.AddMissingDependencies([]string{ctx.OtherModuleName(m)})
1498 } else {
1499 ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library",
1500 ctx.OtherModuleName(m))
1501 }
1502 })
1503 }
1504
1505 return usesLibPaths
1506}
1507
1508// enforceUsesLibraries returns true of <uses-library> tags should be checked against uses_libs and optional_uses_libs
1509// properties. Defaults to true if either of uses_libs or optional_uses_libs is specified. Will default to true
1510// unconditionally in the future.
1511func (u *usesLibrary) enforceUsesLibraries() bool {
1512 defaultEnforceUsesLibs := len(u.usesLibraryProperties.Uses_libs) > 0 ||
1513 len(u.usesLibraryProperties.Optional_uses_libs) > 0
1514 return BoolDefault(u.usesLibraryProperties.Enforce_uses_libs, defaultEnforceUsesLibs)
1515}
1516
1517// verifyUsesLibrariesManifest checks the <uses-library> tags in an AndroidManifest.xml against the ones specified
1518// in the uses_libs and optional_uses_libs properties. It returns the path to a copy of the manifest.
1519func (u *usesLibrary) verifyUsesLibrariesManifest(ctx android.ModuleContext, manifest android.Path) android.Path {
1520 outputFile := android.PathForModuleOut(ctx, "manifest_check", "AndroidManifest.xml")
1521
1522 rule := android.NewRuleBuilder()
Colin Crossee94d6a2019-07-08 17:08:34 -07001523 cmd := rule.Command().BuiltTool(ctx, "manifest_check").
Colin Cross50ddcc42019-05-16 12:28:22 -07001524 Flag("--enforce-uses-libraries").
1525 Input(manifest).
1526 FlagWithOutput("-o ", outputFile)
1527
1528 for _, lib := range u.usesLibraryProperties.Uses_libs {
1529 cmd.FlagWithArg("--uses-library ", lib)
1530 }
1531
1532 for _, lib := range u.usesLibraryProperties.Optional_uses_libs {
1533 cmd.FlagWithArg("--optional-uses-library ", lib)
1534 }
1535
1536 rule.Build(pctx, ctx, "verify_uses_libraries", "verify <uses-library>")
1537
1538 return outputFile
1539}
1540
1541// verifyUsesLibrariesAPK checks the <uses-library> tags in the manifest of an APK against the ones specified
1542// in the uses_libs and optional_uses_libs properties. It returns the path to a copy of the APK.
1543func (u *usesLibrary) verifyUsesLibrariesAPK(ctx android.ModuleContext, apk android.Path) android.Path {
1544 outputFile := android.PathForModuleOut(ctx, "verify_uses_libraries", apk.Base())
1545
1546 rule := android.NewRuleBuilder()
1547 aapt := ctx.Config().HostToolPath(ctx, "aapt")
1548 rule.Command().
1549 Textf("aapt_binary=%s", aapt.String()).Implicit(aapt).
1550 Textf(`uses_library_names="%s"`, strings.Join(u.usesLibraryProperties.Uses_libs, " ")).
1551 Textf(`optional_uses_library_names="%s"`, strings.Join(u.usesLibraryProperties.Optional_uses_libs, " ")).
1552 Tool(android.PathForSource(ctx, "build/make/core/verify_uses_libraries.sh")).Input(apk)
1553 rule.Command().Text("cp -f").Input(apk).Output(outputFile)
1554
1555 rule.Build(pctx, ctx, "verify_uses_libraries", "verify <uses-library>")
1556
1557 return outputFile
1558}