don't export systemserverclasspath_fragment if contents are empty
If a systemserverclasspath_fragment only contains libraries that have a
higher min_sdk_version than the target build release version, then we
should not export the systemserverclasspath_fragment. Before this
change, the fragment was exported with an empty `contents` property
which caused errors after being dropped as a prebuilt.
Bug: 289183551
Test: go test ./sdk
Change-Id: Ifefc6880228e4dd37f5e42b2bda31a83df785375
diff --git a/sdk/systemserverclasspath_fragment_sdk_test.go b/sdk/systemserverclasspath_fragment_sdk_test.go
index 66c44c8..7ccc114 100644
--- a/sdk/systemserverclasspath_fragment_sdk_test.go
+++ b/sdk/systemserverclasspath_fragment_sdk_test.go
@@ -86,6 +86,51 @@
)
}
+func TestSnapshotWithEmptySystemServerClasspathFragment(t *testing.T) {
+ commonSdk := `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ min_sdk_version: "Tiramisu",
+ systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
+ }
+ systemserverclasspath_fragment {
+ name: "mysystemserverclasspathfragment",
+ apex_available: ["myapex"],
+ contents: ["mysdklibrary"],
+ }
+ java_sdk_library {
+ name: "mysdklibrary",
+ apex_available: ["myapex"],
+ srcs: ["Test.java"],
+ min_sdk_version: "34", // UpsideDownCake
+ }
+ sdk {
+ name: "mysdk",
+ apexes: ["myapex"],
+ }
+ `
+
+ result := android.GroupFixturePreparers(
+ prepareForSdkTestWithJava,
+ java.PrepareForTestWithJavaDefaultModules,
+ java.PrepareForTestWithJavaSdkLibraryFiles,
+ java.FixtureWithLastReleaseApis("mysdklibrary"),
+ dexpreopt.FixtureSetApexSystemServerJars("myapex:mysdklibrary"),
+ android.FixtureModifyEnv(func(env map[string]string) {
+ // targeting Tiramisu here means that we won't export mysdklibrary
+ env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = "Tiramisu"
+ }),
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.Platform_version_active_codenames = []string{"UpsideDownCake"}
+ }),
+ prepareForSdkTestWithApex,
+ android.FixtureWithRootAndroidBp(commonSdk),
+ ).RunTest(t)
+
+ CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(`// This is auto-generated. DO NOT EDIT.`))
+}
+
func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
commonSdk := `