Fix api versions xml file handling in droidstubs

Api levels annotations flags should respect the stubs type, but the
everything api versions xml file was being passed to the metalava
invocation for both everything and exportable metalava invocation.

This change fixes such issue by setting api versions xml file (passed to
metalava as --apply-api-levels argument) to respect the stubs type.

Test: m nothing --no-skip-soong-tests
Bug: 319162970
Change-Id: If7155b3701b32fb4cd81dc918648b449de090201
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 6ef2afe..dc3a0ec 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -537,11 +537,17 @@
 	var apiVersions android.Path
 	if proptools.Bool(d.properties.Api_levels_annotations_enabled) {
 		d.apiLevelsGenerationFlags(ctx, cmd, stubsType, apiVersionsXml)
-		apiVersions = d.everythingArtifacts.apiVersionsXml
+		apiVersions = apiVersionsXml
 	} else {
 		ctx.VisitDirectDepsWithTag(metalavaAPILevelsModuleTag, func(m android.Module) {
 			if s, ok := m.(*Droidstubs); ok {
-				apiVersions = s.everythingArtifacts.apiVersionsXml
+				if stubsType == Everything {
+					apiVersions = s.everythingArtifacts.apiVersionsXml
+				} else if stubsType == Exportable {
+					apiVersions = s.exportableArtifacts.apiVersionsXml
+				} else {
+					ctx.ModuleErrorf("%s stubs type does not generate api-versions.xml file", stubsType.String())
+				}
 			} else {
 				ctx.PropertyErrorf("api_levels_module",
 					"module %q is not a droidstubs module", ctx.OtherModuleName(m))