diff options
Diffstat (limited to 'java/app.go')
| -rwxr-xr-x | java/app.go | 133 |
1 files changed, 87 insertions, 46 deletions
diff --git a/java/app.go b/java/app.go index e82004845..ae7373fc7 100755 --- a/java/app.go +++ b/java/app.go @@ -118,17 +118,17 @@ var TargetCpuAbi = map[string]string{ } func SupportedAbis(ctx android.ModuleContext) []string { - abiName := func(archVar string, deviceArch string) string { + abiName := func(targetIdx int, deviceArch string) string { if abi, found := TargetCpuAbi[deviceArch]; found { return abi } - ctx.ModuleErrorf("Invalid %s: %s", archVar, deviceArch) + ctx.ModuleErrorf("Target %d has invalid Arch: %s", targetIdx, deviceArch) return "BAD_ABI" } - result := []string{abiName("TARGET_ARCH", ctx.DeviceConfig().DeviceArch())} - if s := ctx.DeviceConfig().DeviceSecondaryArch(); s != "" { - result = append(result, abiName("TARGET_2ND_ARCH", s)) + var result []string + for i, target := range ctx.Config().Targets[android.Android] { + result = append(result, abiName(i, target.Arch.ArchType.String())) } return result } @@ -268,6 +268,9 @@ type overridableAppProperties struct { // the logging parent of this app. Logging_parent *string + + // Whether to rename the package in resources to the override name rather than the base name. Defaults to true. + Rename_resources_package *bool } // runtime_resource_overlay properties that can be overridden by override_runtime_resource_overlay @@ -284,8 +287,6 @@ type AndroidApp struct { aapt android.OverridableModuleBase - usesLibrary usesLibrary - certificate Certificate appProperties appProperties @@ -507,10 +508,23 @@ func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs } +func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string { + aaptFlags := []string{"--rename-manifest-package " + packageName} + if renameResourcesPackage { + // Required to rename the package name in the resources table. + aaptFlags = append(aaptFlags, "--rename-resources-package "+packageName) + } + return aaptFlags +} + func (a *AndroidApp) OverriddenManifestPackageName() string { return a.overriddenManifestPackageName } +func (a *AndroidApp) renameResourcesPackage() bool { + return proptools.BoolDefault(a.overridableAppProperties.Rename_resources_package, true) +} + func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { a.aapt.usesNonSdkApis = Bool(a.Module.deviceProperties.Platform_apis) @@ -543,7 +557,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { if !overridden { manifestPackageName = *a.overridableAppProperties.Package_name } - aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName) + aaptLinkFlags = append(aaptLinkFlags, generateAaptRenamePackageFlags(manifestPackageName, a.renameResourcesPackage())...) a.overriddenManifestPackageName = manifestPackageName } @@ -586,7 +600,7 @@ func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath return android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk") } -func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { +func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext, sdkLibs dexpreopt.LibraryPaths) android.Path { a.dexpreopter.installPath = a.installPath(ctx) if a.dexProperties.Uncompress_dex == nil { // If the value was not force-set by the user, use reasonable default based on the module. @@ -597,7 +611,9 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { a.dexpreopter.usesLibs = a.usesLibrary.usesLibraryProperties.Uses_libs a.dexpreopter.optionalUsesLibs = a.usesLibrary.presentOptionalUsesLibs(ctx) a.dexpreopter.libraryPaths = a.usesLibrary.usesLibraryPaths(ctx) + a.dexpreopter.libraryPaths.AddLibraryPaths(sdkLibs) a.dexpreopter.manifestFile = a.mergedManifestFile + a.exportedSdkLibs = make(dexpreopt.LibraryPaths) if ctx.ModuleName() != "framework-res" { a.Module.compile(ctx, a.aaptSrcJar) @@ -766,6 +782,15 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) + // The decision to enforce <uses-library> checks is made before adding implicit SDK libraries. + a.usesLibrary.freezeEnforceUsesLibraries() + + // Add implicit SDK libraries to <uses-library> list. + for _, usesLib := range android.SortedStringKeys(a.aapt.sdkLibraries) { + a.usesLibrary.addLib(usesLib, inList(usesLib, dexpreopt.OptionalCompatUsesLibs)) + } + + // Check that the <uses-library> list is coherent with the manifest. if a.usesLibrary.enforceUsesLibraries() { manifestCheckFile := a.usesLibrary.verifyUsesLibrariesManifest(ctx, a.mergedManifestFile) apkDeps = append(apkDeps, manifestCheckFile) @@ -778,7 +803,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.linter.resources = a.aapt.resourceFiles a.linter.buildModuleReportZip = ctx.Config().UnbundledBuildApps() - dexJarFile := a.dexBuildActions(ctx) + dexJarFile := a.dexBuildActions(ctx, a.aapt.sdkLibraries) jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) jniJarFile := a.jniBuildActions(jniLibs, ctx) @@ -792,18 +817,32 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { // Build a final signed app package. packageFile := android.PathForModuleOut(ctx, a.installApkName+".apk") + v4SigningRequested := Bool(a.Module.deviceProperties.V4_signature) + var v4SignatureFile android.WritablePath = nil + if v4SigningRequested { + v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+".apk.idsig") + } var lineageFile android.Path if lineage := String(a.overridableAppProperties.Lineage); lineage != "" { lineageFile = android.PathForModuleSrc(ctx, lineage) } - CreateAndSignAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates, apkDeps, lineageFile) + CreateAndSignAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile, lineageFile) a.outputFile = packageFile + if v4SigningRequested { + a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) + } for _, split := range a.aapt.splits { // Sign the split APKs packageFile := android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk") - CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, lineageFile) + if v4SigningRequested { + v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk.idsig") + } + CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile, lineageFile) a.extraOutputFiles = append(a.extraOutputFiles, packageFile) + if v4SigningRequested { + a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) + } } // Build an app bundle. @@ -963,6 +1002,8 @@ func (a *AndroidApp) OutputFiles(tag string) (android.Paths, error) { switch tag { case ".aapt.srcjar": return []android.Path{a.aaptSrcJar}, nil + case ".export-package.apk": + return []android.Path{a.exportPackage}, nil } return a.Library.OutputFiles(tag) } @@ -1005,8 +1046,7 @@ func AndroidAppFactory() android.Module { module.AddProperties( &module.aaptProperties, &module.appProperties, - &module.overridableAppProperties, - &module.usesLibrary.usesLibraryProperties) + &module.overridableAppProperties) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) @@ -1031,8 +1071,9 @@ type AndroidTest struct { testProperties testProperties - testConfig android.Path - data android.Paths + testConfig android.Path + extraTestConfigs android.Paths + data android.Paths } func (a *AndroidTest) InstallInTestcases() bool { @@ -1060,6 +1101,7 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config, configs) a.testConfig = a.FixTestConfig(ctx, testConfig) + a.extraTestConfigs = android.PathsForModuleSrc(ctx, a.testProperties.Test_options.Extra_test_configs) a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) } @@ -1125,7 +1167,6 @@ func AndroidTestFactory() android.Module { &module.appProperties, &module.appTestProperties, &module.overridableAppProperties, - &module.usesLibrary.usesLibraryProperties, &module.testProperties) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) @@ -1174,8 +1215,7 @@ func AndroidTestHelperAppFactory() android.Module { &module.aaptProperties, &module.appProperties, &module.appTestHelperAppProperties, - &module.overridableAppProperties, - &module.usesLibrary.usesLibraryProperties) + &module.overridableAppProperties) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) @@ -1518,7 +1558,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext if lineage := String(a.properties.Lineage); lineage != "" { lineageFile = android.PathForModuleSrc(ctx, lineage) } - SignAppPackage(ctx, signed, dexOutput, certificates, lineageFile) + SignAppPackage(ctx, signed, dexOutput, certificates, nil, lineageFile) a.outputFile = signed } else { alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename) @@ -1689,7 +1729,6 @@ func AndroidTestImportFactory() android.Module { module := &AndroidTestImport{} module.AddProperties(&module.properties) module.AddProperties(&module.dexpreoptProperties) - module.AddProperties(&module.usesLibrary.usesLibraryProperties) module.AddProperties(&module.testProperties) module.AddProperties(&module.testImportProperties) module.populateAllVariantStructs() @@ -1792,7 +1831,7 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC if !overridden { manifestPackageName = *r.overridableProperties.Package_name } - aaptLinkFlags = append(aaptLinkFlags, "--rename-manifest-package "+manifestPackageName) + aaptLinkFlags = append(aaptLinkFlags, generateAaptRenamePackageFlags(manifestPackageName, false)...) } if r.overridableProperties.Target_package_name != nil { aaptLinkFlags = append(aaptLinkFlags, @@ -1808,7 +1847,7 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC if lineage := String(r.properties.Lineage); lineage != "" { lineageFile = android.PathForModuleSrc(ctx, lineage) } - SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, lineageFile) + SignAppPackage(ctx, signed, r.aapt.exportPackage, certificates, nil, lineageFile) r.certificate = certificates[0] r.outputFile = signed @@ -1873,6 +1912,11 @@ type UsesLibraryProperties struct { // If true, the list of uses_libs and optional_uses_libs modules must match the AndroidManifest.xml file. Defaults // to true if either uses_libs or optional_uses_libs is set. Will unconditionally default to true in the future. Enforce_uses_libs *bool + + // Optional name of the <uses-library> provided by this module. This is needed for non-SDK + // libraries, because SDK ones are automatically picked up by Soong. The <uses-library> name + // normally is the same as the module name, but there are exceptions. + Provides_uses_lib *string } // usesLibrary provides properties and helper functions for AndroidApp and AndroidAppImport to verify that the @@ -1883,6 +1927,16 @@ type usesLibrary struct { usesLibraryProperties UsesLibraryProperties } +func (u *usesLibrary) addLib(lib string, optional bool) { + if !android.InList(lib, u.usesLibraryProperties.Uses_libs) && !android.InList(lib, u.usesLibraryProperties.Optional_uses_libs) { + if optional { + u.usesLibraryProperties.Optional_uses_libs = append(u.usesLibraryProperties.Optional_uses_libs, lib) + } else { + u.usesLibraryProperties.Uses_libs = append(u.usesLibraryProperties.Uses_libs, lib) + } + } +} + func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs bool) { if !ctx.Config().UnbundledBuild() { ctx.AddVariationDependencies(nil, usesLibTag, u.usesLibraryProperties.Uses_libs...) @@ -1893,11 +1947,8 @@ func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs if hasFrameworkLibs { // Dexpreopt needs paths to the dex jars of these libraries in order to construct // class loader context for dex2oat. Add them as a dependency with a special tag. - ctx.AddVariationDependencies(nil, usesLibTag, - "org.apache.http.legacy", - "android.hidl.base-V1.0-java", - "android.hidl.manager-V1.0-java") - ctx.AddVariationDependencies(nil, usesLibTag, optionalUsesLibs...) + ctx.AddVariationDependencies(nil, usesLibTag, dexpreopt.CompatUsesLibs...) + ctx.AddVariationDependencies(nil, usesLibTag, dexpreopt.OptionalCompatUsesLibs...) } } } @@ -1918,27 +1969,11 @@ func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.Libr ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) { dep := ctx.OtherModuleName(m) if lib, ok := m.(Dependency); ok { - buildPath := lib.DexJarBuildPath() - if buildPath == nil { - ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must"+ - " produce a dex jar, does it have installable: true?", dep) - return - } - - var devicePath string - installPath := lib.DexJarInstallPath() - if installPath == nil { - devicePath = filepath.Join("/system/framework", dep+".jar") - } else { - devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath)) - } - - usesLibPaths[dep] = &dexpreopt.LibraryPath{buildPath, devicePath} + usesLibPaths.AddLibraryPath(ctx, dep, lib.DexJarBuildPath(), lib.DexJarInstallPath()) } else if ctx.Config().AllowMissingDependencies() { ctx.AddMissingDependencies([]string{dep}) } else { - ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+ - "a java library", dep) + ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library", dep) } }) } @@ -1955,6 +1990,12 @@ func (u *usesLibrary) enforceUsesLibraries() bool { return BoolDefault(u.usesLibraryProperties.Enforce_uses_libs, defaultEnforceUsesLibs) } +// Freeze the value of `enforce_uses_libs` based on the current values of `uses_libs` and `optional_uses_libs`. +func (u *usesLibrary) freezeEnforceUsesLibraries() { + enforce := u.enforceUsesLibraries() + u.usesLibraryProperties.Enforce_uses_libs = &enforce +} + // verifyUsesLibrariesManifest checks the <uses-library> tags in an AndroidManifest.xml against the ones specified // in the uses_libs and optional_uses_libs properties. It returns the path to a copy of the manifest. func (u *usesLibrary) verifyUsesLibrariesManifest(ctx android.ModuleContext, manifest android.Path) android.Path { |