Suppress reflection errors and dedupe flags

Bug: 168689341
Test: m frameworks-base-api-current-compat
Change-Id: Ied6452849ef994424500b56a042983b92ecc41f2
diff --git a/api/Android.bp b/api/Android.bp
index 2df31ec..5b2d97f 100644
--- a/api/Android.bp
+++ b/api/Android.bp
@@ -24,12 +24,17 @@
     default_applicable_licenses: ["frameworks_base_license"],
 }
 
+metalava_cmd = "$(location metalava)"
+// Silence reflection warnings. See b/168689341
+metalava_cmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED "
+metalava_cmd += " --no-banner --format=v2 "
+
 genrule {
     name: "current-api-xml",
     tools: ["metalava"],
     srcs: [":frameworks-base-api-current.txt"],
     out: ["current.api"],
-    cmd: "$(location metalava) --no-banner -convert2xmlnostrip $(in) $(out)",
+    cmd: metalava_cmd + "-convert2xmlnostrip $(in) $(out)",
     visibility: ["//visibility:public"],
 }
 
@@ -52,7 +57,7 @@
     ],
     out: ["current.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],
@@ -77,7 +82,7 @@
     ],
     out: ["stdout.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 " +
+    cmd: metalava_cmd +
         "--check-compatibility:api:released $(location :android.api.public.latest) " +
         "--baseline:compatibility:released $(location :android-incompatibilities.api.public.latest) " +
         "$(location :frameworks-base-api-current.txt) " +
@@ -126,7 +131,7 @@
     ],
     out: ["removed.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],
@@ -157,7 +162,7 @@
     ],
     out: ["system-current.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],
@@ -183,7 +188,7 @@
     ],
     out: ["stdout.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 " +
+    cmd: metalava_cmd +
         "--check-compatibility:api:released $(location :android.api.system.latest) " +
         "--check-compatibility:base $(location :frameworks-base-api-current.txt) " +
         "--baseline:compatibility:released $(location :android-incompatibilities.api.system.latest) " +
@@ -207,7 +212,7 @@
     ],
     out: ["system-removed.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],
@@ -239,7 +244,7 @@
     ],
     out: ["module-lib-current.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],
@@ -264,7 +269,7 @@
     ],
     out: ["stdout.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 " +
+    cmd: metalava_cmd +
         "--check-compatibility:api:released $(location :android.api.module-lib.latest) " +
         // Note: having "public" be the base of module-lib is not perfect -- it should
         // ideally be a merged public+system), but this will  help when migrating from
@@ -291,7 +296,7 @@
     ],
     out: ["module-lib-removed.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],
@@ -331,7 +336,7 @@
     ],
     out: ["system-server-current.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],
@@ -354,7 +359,7 @@
     ],
     out: ["system-server-removed.txt"],
     tools: ["metalava"],
-    cmd: "$(location metalava) --no-banner --format=v2 $(in) --api $(out)",
+    cmd: metalava_cmd + "$(in) --api $(out)",
     dists: [
         {
             targets: ["droidcore"],