Relocate keepanno utilities in R8

The keep annotation library may be on classpath and R8 should use its
own version in such cases. Our build is still incorrectly configured,
but with this change R8 is not affected. Once relocated, the tests
also need to explicitly include the keepanno module as a dependency.

Fixes: b/325878738
Change-Id: Ic06cd2e9b3c5acacacd7bd3c0f8c6ccf760173b3
diff --git a/d8_r8/main/build.gradle.kts b/d8_r8/main/build.gradle.kts
index d7746ac..f365f9f 100644
--- a/d8_r8/main/build.gradle.kts
+++ b/d8_r8/main/build.gradle.kts
@@ -298,6 +298,12 @@
              // com.android.tools.r8.
              "--map",
              "com.android.tools.r8.**->com.android.tools.r8",
+             // Add identify for the public annotation surface of keepanno
+             "--map",
+             "com.android.tools.r8.keepanno.annotations.**->com.android.tools.r8.keepanno.annotations",
+             // Explicitly move all other keepanno utilities.
+             "--map",
+             "com.android.tools.r8.keepanno.**->com.android.tools.r8.relocated.keepanno",
              "--map",
              "com.android.**->com.android.tools.r8.com.android",
              "--map",
diff --git a/d8_r8/test_modules/tests_java_8/build.gradle.kts b/d8_r8/test_modules/tests_java_8/build.gradle.kts
index 0d492cc..f2f8725 100644
--- a/d8_r8/test_modules/tests_java_8/build.gradle.kts
+++ b/d8_r8/test_modules/tests_java_8/build.gradle.kts
@@ -161,6 +161,8 @@
     dependsOn(gradle.includedBuild("resourceshrinker").task(":jar"))
     from(testDependencies().map(::zipTree))
     from(resourceShrinkerDepsJarTask.outputs.getFiles().map(::zipTree))
+    from(keepAnnoJarTask.outputs.getFiles().map(::zipTree))
+    exclude("com/android/tools/r8/keepanno/annotations/**")
     duplicatesStrategy = DuplicatesStrategy.EXCLUDE
     archiveFileName.set("deps.jar")
   }
diff --git a/src/main/keep.txt b/src/main/keep.txt
index 2aba17e..83f70b1 100644
--- a/src/main/keep.txt
+++ b/src/main/keep.txt
@@ -29,7 +29,3 @@
 
 # Test in this class is using the class name to fing the original .java file.
 -keep class com.android.tools.r8.ir.desugar.varhandle.VarHandleDesugaringMethods
-
-# Keep everything in the annotations package of keepanno.
-# These are public API as they denote the supported annotations to be interpreted by R8.
--keep class com.android.tools.r8.keepanno.annotations.** { *; }