Add property Optimize.Keep_runtime_invisible_annotations

This adds a new property Keep_runtime_invisible_annotations to Optimize that defaults to false.

Setting this property to true is equivalent to:
  -keepattributes RuntimeInvisibleAnnotations,
                  RuntimeInvisibleParameterAnnotations,
                  RuntimeInvisibleTypeAnnotations

This is only applicable when RELEASE_R8_ONLY_RUNTIME_VISIBLE_ANNOTATIONS is enabled and will be used to migrate away from keeping runtime invisible annotations (b/387958004 ).

It is not possible to branch on RELEASE_R8_ONLY_RUNTIME_VISIBLE_ANNOTATIONS in ProGuard configuration files. To migrate builds away from keeping runtime invisible annotations, this will remove any -keepattributes rules that retain runtime invisible annotations, and set the property Optimize.Keep_runtime_invisible_annotations. This way these builds continue to retain runtime invisible annotations when the feature flag RELEASE_R8_ONLY_RUNTIME_VISIBLE_ANNOTATIONS is not enabled.

Bug: 387958004
Test: existing
Change-Id: I2a2b9aba436c4f43533d3067f2abe319fadf78f1
diff --git a/java/dex.go b/java/dex.go
index 7b99549..4a7e9dc 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -49,6 +49,16 @@
 		// Whether to continue building even if warnings are emitted.  Defaults to true.
 		Ignore_warnings *bool
 
+		// Whether runtime invisible annotations should be kept by R8. Defaults to false.
+		// This is equivalent to:
+		//   -keepattributes RuntimeInvisibleAnnotations,
+		//                   RuntimeInvisibleParameterAnnotations,
+		//                   RuntimeInvisibleTypeAnnotations
+		// This is only applicable when RELEASE_R8_ONLY_RUNTIME_VISIBLE_ANNOTATIONS is
+		// enabled and will be used to migrate away from keeping runtime invisible
+		// annotations (b/387958004).
+		Keep_runtime_invisible_annotations *bool
+
 		// If true, runs R8 in Proguard compatibility mode, otherwise runs R8 in full mode.
 		// Defaults to false for apps and tests, true for libraries.
 		Proguard_compatibility *bool
@@ -364,6 +374,10 @@
 		r8Flags = append(r8Flags, "--ignore-library-extends-program")
 	}
 
+	if BoolDefault(opt.Keep_runtime_invisible_annotations, false) {
+		r8Flags = append(r8Flags, "--keep-runtime-invisible-annotations")
+	}
+
 	if BoolDefault(opt.Proguard_compatibility, true) {
 		r8Flags = append(r8Flags, "--force-proguard-compatibility")
 	}