Fix non-determinism in prebuilt selection

This relands aosp/2978137 with acknowledgement of soong namespaces.

If multiple versions of the prebuilt module sdk share the same soong
config namespace, then PrebuiltPostDepsMutator rewrites rdeps to one of
those prebuilts in a non-deterministic way.

This CL uses apex_contributions to make this deterministic. Multiple
prebuilts will not be allowed to have their prefer evaluate to true. If
this happens, one of the prebuilts must be explicitly declared in
apex_contributions.

This CL also fixes the special-casing of the top-level
java_sdk_library_import in ReplaceDirectDependencies. For
framework-foo.v2, it will use BaseModuleName framework-foo instead of
SdkLibraryName framework-foo.v2 to determine if the source module has
been selected.

Test: ran the previously failing cmd of b/327552112
Test: Added a unit test
Test: aninja -t query
    out/soong/.intermediates/packages/modules/Permission/SafetyCenter/Config/safety-center-config/android_common/javac/safety-center-config.jar
    | grep module_sdk is empty (should not cause a regression for
    323454855)
Change-Id: Id484a41192085c50b7e34ad415c6e195edb0d006
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 97b9c84..54d2d08 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -6199,7 +6199,7 @@
 		`)
 	})
 
-	t.Run("Co-existing unflagged apexes should create a duplicate deapexer error in hiddenapi processing", func(t *testing.T) {
+	t.Run("Co-existing unflagged apexes should create a duplicate module error", func(t *testing.T) {
 		bp := `
 		// Source
 		apex {
@@ -6273,7 +6273,7 @@
 		}
 	`
 
-		testDexpreoptWithApexes(t, bp, "Multiple installable prebuilt APEXes provide ambiguous deapexers: prebuilt_myapex.v1 and prebuilt_myapex.v2", preparer, fragment)
+		testDexpreoptWithApexes(t, bp, "Multiple prebuilt modules prebuilt_myapex.v1 and prebuilt_myapex.v2 have been marked as preferred for this source module", preparer, fragment)
 	})
 
 }