summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/app.go13
-rw-r--r--java/app_test.go79
-rw-r--r--java/base.go12
-rw-r--r--java/bootclasspath_fragment.go27
-rw-r--r--java/dexpreopt.go16
-rw-r--r--java/hiddenapi_singleton_test.go11
-rw-r--r--java/java.go4
-rw-r--r--java/platform_bootclasspath.go24
-rw-r--r--java/sdk_library.go12
9 files changed, 118 insertions, 80 deletions
diff --git a/java/app.go b/java/app.go
index f05b8a7cd..bab413097 100644
--- a/java/app.go
+++ b/java/app.go
@@ -338,23 +338,12 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.generateJavaUsedByApex(ctx)
}
-func (a *AndroidApp) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
- defaultMinSdkVersion := a.Module.MinSdkVersion(ctx)
- if proptools.Bool(a.appProperties.Updatable) {
- overrideApiLevel := android.MinSdkVersionFromValue(ctx, ctx.DeviceConfig().ApexGlobalMinSdkVersionOverride())
- if !overrideApiLevel.IsNone() && overrideApiLevel.CompareTo(defaultMinSdkVersion) > 0 {
- return overrideApiLevel
- }
- }
- return defaultMinSdkVersion
-}
-
func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
if a.Updatable() {
if !a.SdkVersion(ctx).Stable() {
ctx.PropertyErrorf("sdk_version", "Updatable apps must use stable SDKs, found %v", a.SdkVersion(ctx))
}
- if String(a.deviceProperties.Min_sdk_version) == "" {
+ if String(a.overridableProperties.Min_sdk_version) == "" {
ctx.PropertyErrorf("updatable", "updatable apps must set min_sdk_version.")
}
diff --git a/java/app_test.go b/java/app_test.go
index a7c48a1ed..804949435 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -4322,52 +4322,6 @@ func TestPrivappAllowlistAndroidMk(t *testing.T) {
)
}
-func TestApexGlobalMinSdkVersionOverride(t *testing.T) {
- result := android.GroupFixturePreparers(
- PrepareForTestWithJavaDefaultModules,
- android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
- variables.ApexGlobalMinSdkVersionOverride = proptools.StringPtr("Tiramisu")
- }),
- ).RunTestWithBp(t, `
- android_app {
- name: "com.android.bar",
- srcs: ["a.java"],
- sdk_version: "current",
- }
- android_app {
- name: "com.android.foo",
- srcs: ["a.java"],
- sdk_version: "current",
- min_sdk_version: "S",
- updatable: true,
- }
- override_android_app {
- name: "com.android.go.foo",
- base: "com.android.foo",
- }
- `)
- foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer")
- fooOverride := result.ModuleForTests("com.android.foo", "android_common_com.android.go.foo").Rule("manifestFixer")
- bar := result.ModuleForTests("com.android.bar", "android_common").Rule("manifestFixer")
-
- android.AssertStringDoesContain(t,
- "expected manifest fixer to set com.android.bar minSdkVersion to S",
- bar.BuildParams.Args["args"],
- "--minSdkVersion S",
- )
- android.AssertStringDoesContain(t,
- "com.android.foo: expected manifest fixer to set minSdkVersion to T",
- foo.BuildParams.Args["args"],
- "--minSdkVersion T",
- )
- android.AssertStringDoesContain(t,
- "com.android.go.foo: expected manifest fixer to set minSdkVersion to T",
- fooOverride.BuildParams.Args["args"],
- "--minSdkVersion T",
- )
-
-}
-
func TestAppFlagsPackages(t *testing.T) {
ctx := testApp(t, `
android_app {
@@ -4492,3 +4446,36 @@ func TestAppStem(t *testing.T) {
t.Errorf("Module output does not contain expected apk %s", "foo-new.apk")
}
}
+
+func TestAppMinSdkVersionOverride(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ ).RunTestWithBp(t, `
+ android_app {
+ name: "com.android.foo",
+ srcs: ["a.java"],
+ sdk_version: "current",
+ min_sdk_version: "31",
+ updatable: true,
+ }
+ override_android_app {
+ name: "com.android.go.foo",
+ base: "com.android.foo",
+ min_sdk_version: "33",
+ }
+ `)
+ foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer")
+ fooOverride := result.ModuleForTests("com.android.foo", "android_common_com.android.go.foo").Rule("manifestFixer")
+
+ android.AssertStringDoesContain(t,
+ "com.android.foo: expected manifest fixer to set minSdkVersion to T",
+ foo.BuildParams.Args["args"],
+ "--minSdkVersion 31",
+ )
+ android.AssertStringDoesContain(t,
+ "com.android.go.foo: expected manifest fixer to set minSdkVersion to T",
+ fooOverride.BuildParams.Args["args"],
+ "--minSdkVersion 33",
+ )
+
+}
diff --git a/java/base.go b/java/base.go
index 0c2867177..e97d28de2 100644
--- a/java/base.go
+++ b/java/base.go
@@ -229,10 +229,6 @@ type DeviceProperties struct {
// If the SDK kind is empty, it will be set to public.
Sdk_version *string
- // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
- // Defaults to sdk_version if not set. See sdk_version for possible values.
- Min_sdk_version *string
-
// if not blank, set the maximum version of the sdk that the compiled artifacts will run against.
// Defaults to empty string "". See sdk_version for possible values.
Max_sdk_version *string
@@ -312,6 +308,10 @@ type OverridableProperties struct {
// Otherwise, both the overridden and the overriding modules will have the same output name, which
// can cause the duplicate output error.
Stem *string
+
+ // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
+ // Defaults to sdk_version if not set. See sdk_version for possible values.
+ Min_sdk_version *string
}
// Functionality common to Module and Import
@@ -738,8 +738,8 @@ func (j *Module) SystemModules() string {
}
func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
- if j.deviceProperties.Min_sdk_version != nil {
- return android.ApiLevelFrom(ctx, *j.deviceProperties.Min_sdk_version)
+ if j.overridableProperties.Min_sdk_version != nil {
+ return android.ApiLevelFrom(ctx, *j.overridableProperties.Min_sdk_version)
}
return j.SdkVersion(ctx).ApiLevel
}
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index 82a34ca9d..4d3d794d8 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -590,13 +590,36 @@ func (b *BootclasspathFragmentModule) configuredJars(ctx android.ModuleContext)
// So ignore it even if it is not in PRODUCT_APEX_BOOT_JARS.
// TODO(b/202896428): Add better way to handle this.
_, unknown = android.RemoveFromList("android.car-module", unknown)
- if isActiveModule(ctx, ctx.Module()) && len(unknown) > 0 {
- ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_BOOT_JARS", unknown)
+ if isApexVariant(ctx) && len(unknown) > 0 {
+ if android.IsModulePrebuilt(ctx.Module()) {
+ // prebuilt bcpf. the validation of this will be done at the top-level apex
+ providerClasspathFragmentValidationInfoProvider(ctx, unknown)
+ } else if !disableSourceApexVariant(ctx) {
+ // source bcpf, and prebuilt apex are not selected.
+ ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_BOOT_JARS", unknown)
+ }
}
}
return jars
}
+var ClasspathFragmentValidationInfoProvider = blueprint.NewProvider[ClasspathFragmentValidationInfo]()
+
+type ClasspathFragmentValidationInfo struct {
+ ClasspathFragmentModuleName string
+ UnknownJars []string
+}
+
+// Set a provider with the list of jars that have not been added to PRODUCT_APEX_BOOT_JARS
+// The validation will be done in the ctx of the top-level _selected_ apex
+func providerClasspathFragmentValidationInfoProvider(ctx android.ModuleContext, unknown []string) {
+ info := ClasspathFragmentValidationInfo{
+ ClasspathFragmentModuleName: ctx.ModuleName(),
+ UnknownJars: unknown,
+ }
+ android.SetProvider(ctx, ClasspathFragmentValidationInfoProvider, info)
+}
+
// generateHiddenAPIBuildActions generates all the hidden API related build rules.
func (b *BootclasspathFragmentModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, contents []android.Module, fragments []android.Module) *HiddenAPIOutput {
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 1acac1b40..4d6dbffe1 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -262,6 +262,20 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName s
if !isApexSystemServerJar {
return true
}
+ ai, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
+ allApexInfos := []android.ApexInfo{}
+ if allApexInfosProvider, ok := android.ModuleProvider(ctx, android.AllApexInfoProvider); ok {
+ allApexInfos = allApexInfosProvider.ApexInfos
+ }
+ if len(allApexInfos) > 0 && !ai.MinSdkVersion.EqualTo(allApexInfos[0].MinSdkVersion) {
+ // Apex system server jars are dexpreopted and installed on to the system image.
+ // Since we can have BigAndroid and Go variants of system server jar providing apexes,
+ // and these two variants can have different min_sdk_versions, hide one of the apex variants
+ // from make to prevent collisions.
+ //
+ // Unlike cc, min_sdk_version does not have an effect on the build actions of java libraries.
+ ctx.Module().MakeUninstallable()
+ }
} else {
// Don't preopt the platform variant of an APEX system server jar to avoid conflicts.
if isApexSystemServerJar {
@@ -502,7 +516,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa
// Prebuilts are active, do not copy the dexpreopt'd source javalib to out/soong/system_server_dexjars
// The javalib from the deapexed prebuilt will be copied to this location.
// TODO (b/331665856): Implement a principled solution for this.
- copyApexSystemServerJarDex := !disableSourceApexVariant(ctx)
+ copyApexSystemServerJarDex := !disableSourceApexVariant(ctx) && !ctx.Module().IsHideFromMake()
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
ctx, globalSoong, global, dexpreoptConfig, appProductPackages, copyApexSystemServerJarDex)
if err != nil {
diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go
index 330013ee4..62297978c 100644
--- a/java/hiddenapi_singleton_test.go
+++ b/java/hiddenapi_singleton_test.go
@@ -198,13 +198,22 @@ func TestHiddenAPISingletonSdks(t *testing.T) {
hiddenApiFixtureFactory,
tc.preparer,
prepareForTestWithDefaultPlatformBootclasspath,
+ // Make sure that we have atleast one platform library so that we can check the monolithic hiddenapi
+ // file creation.
+ FixtureConfigureBootJars("platform:foo"),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.Always_use_prebuilt_sdks = proptools.BoolPtr(tc.unbundledBuild)
variables.BuildFlags = map[string]string{
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
}
}),
- ).RunTest(t)
+ ).RunTestWithBp(t, `
+ java_library {
+ name: "foo",
+ srcs: ["a.java"],
+ compile_dex: true,
+ }
+ `)
hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common")
hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags")
diff --git a/java/java.go b/java/java.go
index 0df96a3a5..f038f634b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -908,7 +908,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// Check min_sdk_version of the transitive dependencies if this module is created from
// java_sdk_library.
- if j.deviceProperties.Min_sdk_version != nil && j.SdkLibraryName() != nil {
+ if j.overridableProperties.Min_sdk_version != nil && j.SdkLibraryName() != nil {
j.CheckDepsMinSdkVersion(ctx)
}
@@ -1096,7 +1096,7 @@ func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberCo
// If the min_sdk_version was set then add the canonical representation of the API level to the
// snapshot.
- if j.deviceProperties.Min_sdk_version != nil {
+ if j.overridableProperties.Min_sdk_version != nil {
canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String())
if err != nil {
ctx.ModuleErrorf("%s", err)
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index b3c9ce50f..8d4cf6823 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -294,6 +294,15 @@ func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext
// generateHiddenAPIBuildActions generates all the hidden API related build rules.
func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule {
+ createEmptyHiddenApiFiles := func() {
+ paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
+ for _, path := range paths {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Touch,
+ Output: path,
+ })
+ }
+ }
// Save the paths to the monolithic files for retrieval via OutputFiles().
b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags
@@ -306,13 +315,7 @@ func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.
// optimization that can be used to reduce the incremental build time but as its name suggests it
// can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath.
if ctx.Config().DisableHiddenApiChecks() {
- paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV}
- for _, path := range paths {
- ctx.Build(pctx, android.BuildParams{
- Rule: android.Touch,
- Output: path,
- })
- }
+ createEmptyHiddenApiFiles()
return bootDexJarByModule
}
@@ -325,6 +328,13 @@ func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.
// the fragments will have already provided the flags that are needed.
classesJars := monolithicInfo.ClassesJars
+ if len(classesJars) == 0 {
+ // This product does not include any monolithic jars. Monolithic hiddenapi flag generation is not required.
+ // However, generate an empty file so that the dist tags in f/b/boot/Android.bp can be resolved, and `m dist` works.
+ createEmptyHiddenApiFiles()
+ return bootDexJarByModule
+ }
+
// Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile
input := newHiddenAPIFlagInput()
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 677b32a5e..645f51382 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1650,6 +1650,14 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
module.dexpreopter.configPath = module.implLibraryModule.dexpreopter.configPath
module.dexpreopter.outputProfilePathOnHost = module.implLibraryModule.dexpreopter.outputProfilePathOnHost
+ // Properties required for Library.AndroidMkEntries
+ module.logtagsSrcs = module.implLibraryModule.logtagsSrcs
+ module.dexpreopter.builtInstalled = module.implLibraryModule.dexpreopter.builtInstalled
+ module.jacocoReportClassesFile = module.implLibraryModule.jacocoReportClassesFile
+ module.dexer.proguardDictionary = module.implLibraryModule.dexer.proguardDictionary
+ module.dexer.proguardUsageZip = module.implLibraryModule.dexer.proguardUsageZip
+ module.linter.reports = module.implLibraryModule.linter.reports
+
if !module.Host() {
module.hostdexInstallFile = module.implLibraryModule.hostdexInstallFile
}
@@ -1814,7 +1822,6 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext)
props := struct {
Name *string
Visibility []string
- Instrument bool
Libs []string
Static_libs []string
Apex_available []string
@@ -1822,8 +1829,6 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext)
}{
Name: proptools.StringPtr(module.implLibraryModuleName()),
Visibility: visibility,
- // Set the instrument property to ensure it is instrumented when instrumentation is required.
- Instrument: true,
Libs: append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...),
@@ -1842,6 +1847,7 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext)
&module.dexProperties,
&module.dexpreoptProperties,
&module.linter.properties,
+ &module.overridableProperties,
&props,
module.sdkComponentPropertiesForChildLibrary(),
}