diff options
Diffstat (limited to 'java/app.go')
-rwxr-xr-x | java/app.go | 118 |
1 files changed, 63 insertions, 55 deletions
diff --git a/java/app.go b/java/app.go index a45ab6f99..4bb292ddf 100755 --- a/java/app.go +++ b/java/app.go @@ -28,6 +28,7 @@ import ( "android/soong/android" "android/soong/cc" + "android/soong/dexpreopt" "android/soong/tradefed" ) @@ -96,6 +97,14 @@ func (as *AndroidAppSet) Privileged() bool { return Bool(as.properties.Privileged) } +func (as *AndroidAppSet) OutputFile() android.Path { + return as.packedOutput +} + +func (as *AndroidAppSet) MasterFile() string { + return as.masterFile +} + var TargetCpuAbi = map[string]string{ "arm": "ARMEABI_V7A", "arm64": "ARM64_V8A", @@ -120,11 +129,11 @@ func SupportedAbis(ctx android.ModuleContext) []string { } func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { - as.packedOutput = android.PathForModuleOut(ctx, "extracted.zip") + as.packedOutput = android.PathForModuleOut(ctx, ctx.ModuleName()+".zip") // We are assuming here that the master file in the APK // set has `.apk` suffix. If it doesn't the build will fail. // APK sets containing APEX files are handled elsewhere. - as.masterFile = ctx.ModuleName() + ".apk" + as.masterFile = as.BaseModuleName() + ".apk" screenDensities := "all" if dpis := ctx.Config().ProductAAPTPrebuiltDPI(); len(dpis) > 0 { screenDensities = strings.ToUpper(strings.Join(dpis, ",")) @@ -145,26 +154,17 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) "stem": ctx.ModuleName(), }, }) - // TODO(asmundak): add this (it's wrong now, will cause copying extracted.zip) - /* - var installDir android.InstallPath - if Bool(as.properties.Privileged) { - installDir = android.PathForModuleInstall(ctx, "priv-app", as.BaseModuleName()) - } else if ctx.InstallInTestcases() { - installDir = android.PathForModuleInstall(ctx, as.BaseModuleName(), ctx.DeviceConfig().DeviceArch()) - } else { - installDir = android.PathForModuleInstall(ctx, "app", as.BaseModuleName()) - } - ctx.InstallFile(installDir, as.masterFile", as.packedOutput) - */ } // android_app_set extracts a set of APKs based on the target device // configuration and installs this set as "split APKs". -// The set will always contain `base-master.apk` and every APK built -// to the target device. All density-specific APK will be included, too, -// unless PRODUCT_APPT_PREBUILT_DPI is defined (should contain comma-sepearated -// list of density names (LDPI, MDPI, HDPI, etc.) +// The extracted set always contains 'master' APK whose name is +// _module_name_.apk and every split APK matching target device. +// The extraction of the density-specific splits depends on +// PRODUCT_AAPT_PREBUILT_DPI variable. If present (its value should +// be a list density names: LDPI, MDPI, HDPI, etc.), only listed +// splits will be extracted. Otherwise all density-specific splits +// will be extracted. func AndroidApkSetFactory() android.Module { module := &AndroidAppSet{} module.AddProperties(&module.properties) @@ -335,7 +335,7 @@ type Certificate struct { presigned bool } -var presignedCertificate = Certificate{presigned: true} +var PresignedCertificate = Certificate{presigned: true} func (c Certificate) AndroidMkString() string { if c.presigned { @@ -445,8 +445,11 @@ func (a *AndroidApp) checkJniLibsSdkVersion(ctx android.ModuleContext, minSdkVer return } dep, _ := m.(*cc.Module) - jniSdkVersion, err := android.ApiStrToNum(ctx, dep.SdkVersion()) - if err != nil || int(minSdkVersion) < jniSdkVersion { + // The domain of cc.sdk_version is "current" and <number> + // We can rely on sdkSpec to convert it to <number> so that "current" is handled + // properly regardless of sdk finalization. + jniSdkVersion, err := sdkSpecFrom(dep.SdkVersion()).effectiveVersion(ctx) + if err != nil || minSdkVersion < jniSdkVersion { ctx.OtherModuleErrorf(dep, "sdk_version(%v) is higher than min_sdk_version(%v) of the containing android_app(%v)", dep.SdkVersion(), minSdkVersion, ctx.ModuleName()) return @@ -688,9 +691,9 @@ func processMainCert(m android.ModuleBase, certPropValue string, certificates [] systemCertPath := ctx.Config().DefaultAppCertificateDir(ctx).String() if strings.HasPrefix(certPath, systemCertPath) { enforceSystemCert := ctx.Config().EnforceSystemCertificate() - whitelist := ctx.Config().EnforceSystemCertificateWhitelist() + allowed := ctx.Config().EnforceSystemCertificateAllowList() - if enforceSystemCert && !inList(m.Name(), whitelist) { + if enforceSystemCert && !inList(m.Name(), allowed) { ctx.PropertyErrorf("certificate", "The module in product partition cannot be signed with certificate in system.") } } @@ -739,6 +742,10 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.proguardBuildActions(ctx) + a.linter.mergedManifest = a.aapt.mergedManifestFile + a.linter.manifest = a.aapt.manifestPath + a.linter.resources = a.aapt.resourceFiles + dexJarFile := a.dexBuildActions(ctx) jniLibs, certificateDeps := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) @@ -960,20 +967,13 @@ func AndroidAppFactory() android.Module { module.Module.properties.Instrument = true module.Module.properties.Installable = proptools.BoolPtr(true) + module.addHostAndDeviceProperties() module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, - &module.Module.protoProperties, &module.aaptProperties, &module.appProperties, &module.overridableAppProperties, &module.usesLibrary.usesLibraryProperties) - module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { - return class == android.Device && ctx.Config().DevicePrefer32BitApps() - }) - android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) android.InitOverridableModule(module, &module.appProperties.Overrides) @@ -1083,12 +1083,10 @@ func AndroidTestFactory() android.Module { module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true + module.Module.linter.test = true + module.addHostAndDeviceProperties() module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, - &module.Module.protoProperties, &module.aaptProperties, &module.appProperties, &module.appTestProperties, @@ -1135,12 +1133,10 @@ func AndroidTestHelperAppFactory() android.Module { module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true + module.Module.linter.test = true + module.addHostAndDeviceProperties() module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, - &module.Module.protoProperties, &module.aaptProperties, &module.appProperties, &module.appTestHelperAppProperties, @@ -1186,7 +1182,7 @@ type OverrideAndroidApp struct { android.OverrideModuleBase } -func (i *OverrideAndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func (i *OverrideAndroidApp) GenerateAndroidBuildActions(_ android.ModuleContext) { // All the overrides happen in the base module. // TODO(jungjw): Check the base module type. } @@ -1207,7 +1203,7 @@ type OverrideAndroidTest struct { android.OverrideModuleBase } -func (i *OverrideAndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func (i *OverrideAndroidTest) GenerateAndroidBuildActions(_ android.ModuleContext) { // All the overrides happen in the base module. // TODO(jungjw): Check the base module type. } @@ -1229,7 +1225,7 @@ type OverrideRuntimeResourceOverlay struct { android.OverrideModuleBase } -func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) { +func (i *OverrideRuntimeResourceOverlay) GenerateAndroidBuildActions(_ android.ModuleContext) { // All the overrides happen in the base module. // TODO(jungjw): Check the base module type. } @@ -1474,7 +1470,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext // Sign or align the package if package has not been preprocessed if a.preprocessed { a.outputFile = srcApk - a.certificate = presignedCertificate + a.certificate = PresignedCertificate } else if !Bool(a.properties.Presigned) { // If the certificate property is empty at this point, default_dev_cert must be set to true. // Which makes processMainCert's behavior for the empty cert string WAI. @@ -1494,7 +1490,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext alignedApk := android.PathForModuleOut(ctx, "zip-aligned", apkFilename) TransformZipAlign(ctx, alignedApk, dexOutput) a.outputFile = alignedApk - a.certificate = presignedCertificate + a.certificate = PresignedCertificate } // TODO: Optionally compress the output apk. @@ -1552,7 +1548,7 @@ func (a *AndroidAppImport) Privileged() bool { return Bool(a.properties.Privileged) } -func (a *AndroidAppImport) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { +func (a *AndroidAppImport) DepIsInSameApex(_ android.BaseModuleContext, _ android.Module) bool { // android_app_import might have extra dependencies via uses_libs property. // Don't track the dependency as we don't automatically add those libraries // to the classpath. It should be explicitly added to java_libs property of APEX @@ -1875,24 +1871,36 @@ func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []s return optionalUsesLibs } -// usesLibraryPaths returns a map of module names of shared library dependencies to the paths to their dex jars. -func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) map[string]android.Path { - usesLibPaths := make(map[string]android.Path) +// usesLibraryPaths returns a map of module names of shared library dependencies to the paths +// to their dex jars on host and on device. +func (u *usesLibrary) usesLibraryPaths(ctx android.ModuleContext) dexpreopt.LibraryPaths { + usesLibPaths := make(dexpreopt.LibraryPaths) if !ctx.Config().UnbundledBuild() { ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) { + dep := ctx.OtherModuleName(m) if lib, ok := m.(Dependency); ok { - if dexJar := lib.DexJar(); dexJar != nil { - usesLibPaths[ctx.OtherModuleName(m)] = dexJar + 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 { - ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must produce a dex jar, does it have installable: true?", - ctx.OtherModuleName(m)) + devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath)) } + + usesLibPaths[dep] = &dexpreopt.LibraryPath{buildPath, devicePath} } else if ctx.Config().AllowMissingDependencies() { - ctx.AddMissingDependencies([]string{ctx.OtherModuleName(m)}) + ctx.AddMissingDependencies([]string{dep}) } else { - ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library", - ctx.OtherModuleName(m)) + ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+ + "a java library", dep) } }) } |