Reenable R8CompiledThroughDexTest

Ensure that we use the keep annotations

Add dontwarn on the resource shrinker dependencies (which is not used in the compilation we run on art)

Bug: b/338379138
Change-Id: I12462984cdb0f9019b25da0308d6f62e07e54dfb
Fixes: 338379138
diff --git a/src/test/bootstrap/com/android/tools/r8/bootstrap/R8CompiledThroughDexTest.java b/src/test/bootstrap/com/android/tools/r8/bootstrap/R8CompiledThroughDexTest.java
index 1908d79..3b644f2 100644
--- a/src/test/bootstrap/com/android/tools/r8/bootstrap/R8CompiledThroughDexTest.java
+++ b/src/test/bootstrap/com/android/tools/r8/bootstrap/R8CompiledThroughDexTest.java
@@ -8,7 +8,6 @@
 import static com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification.JDK11_PATH;
 import static junit.framework.TestCase.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
 
 import com.android.tools.r8.CompilationFailedException;
 import com.android.tools.r8.CompilationMode;
@@ -86,7 +85,7 @@
   private static final String R8_KEEP =
       Paths.get(ToolHelper.SOURCE_DIR + "main/keep.txt").toAbsolutePath().toString();
 
-  private Pair<List<String>, Consumer<Builder>> buildArguments() {
+  private Pair<List<String>, Consumer<Builder>> buildArguments() throws IOException {
     ImmutableList.Builder<String> arguments = ImmutableList.builder();
     List<Consumer<Builder>> buildup = new ArrayList<>();
 
@@ -105,6 +104,13 @@
     arguments.add("--pg-conf").add(commandLinePathFor(R8_KEEP));
     buildup.add(b -> b.addProguardConfigurationFiles(Paths.get(R8_KEEP)));
 
+    // The resource shrinker has transitive dependencies that refer to classes in
+    // javax.xml.stream, which is not in android.jar. We don't run the resource shrinker, so
+    // we simply ignore these.
+    Path dontwarn = writeTextToTempFile("-dontwarn  javax.xml.stream.*");
+    arguments.add("--pg-conf").add(commandLinePathFor(dontwarn));
+    buildup.add(b -> b.addProguardConfigurationFiles(dontwarn));
+
     arguments
         .add("--desugared-lib")
         .add(commandLinePathFor(libraryDesugaringSpecification.getSpecification()));
@@ -126,11 +132,11 @@
     return new Pair<>(arguments.build(), consumer);
   }
 
-  private List<String> getSharedArguments() {
+  private List<String> getSharedArguments() throws IOException {
     return buildArguments().getFirst();
   }
 
-  private Consumer<Builder> getSharedBuilder() {
+  private Consumer<Builder> getSharedBuilder() throws IOException {
     return buildArguments().getSecond();
   }
 
@@ -140,8 +146,6 @@
 
   @Test
   public void testR8CompiledWithR8Dex() throws Exception {
-    // TODO(b/338379138): Fix and reenable
-    assumeTrue(false);
     // Compile once R8_WITH_RELOCATED_DEPS_JAR using normal R8_WITH_RELOCATED_DEPS_JAR to dex,
     // and once R8_WITH_RELOCATED_DEPS_JAR with the previously compiled version to dex.
     // Both applications should be identical.
@@ -197,7 +201,11 @@
                   commandLinePathFor(
                       getNonShrunkDesugaredLib(parameters, libraryDesugaringSpecification))),
               R8.class.getTypeName(),
-              builder -> builder.appendArtOption("--64").appendArtOption("-Xmx512m"),
+              builder ->
+                  builder
+                      .appendArtOption("--64")
+                      .appendArtOption("-Xmx512m")
+                      .appendArtSystemProperty("com.android.tools.r8.enableKeepAnnotations", "1"),
               parameters.getRuntime().asDex().getVm(),
               true,
               ImmutableList.builder()
@@ -230,6 +238,7 @@
                 .add("-Xmx1g")
                 // Set the system property to check determinism.
                 .add("-D" + checkDeterminismKey + "=" + determinismLogsDir)
+                .add("-Dcom.android.tools.r8.enableKeepAnnotations=1")
                 .add(R8.class.getTypeName())
                 .add("--output")
                 .add(commandLinePathFor(outputThroughCfExternal))
@@ -241,13 +250,14 @@
   }
 
   private void runInProcessR8(Path outputThroughCf, Path determinismLogsDir)
-      throws CompilationFailedException {
+      throws CompilationFailedException, IOException {
     long start = System.nanoTime();
     // Manually construct the R8 command as the test builder will change defaults compared
     // to the CLI invocation (eg, compressed and pg-map output).
     Builder builder = R8Command.builder().setOutput(outputThroughCf, OutputMode.DexIndexed);
     // Set API model until default changes.
     builder.setEnableExperimentalMissingLibraryApiModeling(true);
+    builder.setEnableExperimentalKeepAnnotations(true);
     getSharedBuilder().accept(builder);
     ToolHelper.runR8WithOptionsModificationOnly(
         builder.build(),