Find matching variant of `required` for `common_first`

Both 32-bit and 64-bit variants of native deps were getting installed in
Soong-built system image if they were listed in `required` of
`java_binary`.

java_binary(s) have two variants, a "common" and an arch
variant (the first arch). Previously the common variant will create a
dependency to both 32-bit and 64-bit variants of their dependencies.
With this CL, common variant will not create a dependency on required
unless the requested `target` is also the common target.

Test: Ran the filelistdiff tool
Test: go test ./java -run TestNativeRequiredDepOfJavaBinary
Bug: 369678122

Change-Id: Ica97e12eefb45929ca653ec57c3339e4a3b72a76
diff --git a/android/module.go b/android/module.go
index d6c129a..95e65bb 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1005,6 +1005,14 @@
 			return
 		}
 
+		// Do not create a dependency from common variant to arch variant for `common_first` modules
+		if multilib, _ := decodeMultilib(ctx, ctx.Module().base()); multilib == string(MultilibCommonFirst) {
+			commonVariant := ctx.Arch().ArchType.Multilib == ""
+			if bothInAndroid && commonVariant && InList(target.Arch.ArchType.Multilib, []string{"lib32", "lib64"}) {
+				return
+			}
+		}
+
 		variation := target.Variations()
 		if ctx.OtherModuleFarDependencyVariantExists(variation, depName) {
 			ctx.AddFarVariationDependencies(variation, RequiredDepTag, depName)