Don't use dx output for smali tests

Bug: 185205222
Change-Id: I861d8764dbf1c6ccd0a03778d060d3bb3a6f464f
diff --git a/build.gradle b/build.gradle
index b0d3716..3c1308d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1739,10 +1739,11 @@
                 }
             }
         } else {
-            dependsOn "${taskName}_dexmerger"
+            dependsOn "${taskName}_smali"
+            dependsOn "${taskName}_jar"
             task "${taskName}_smali"(type: SmaliTask) {
                 source = smaliFiles
-                destination = intermediateFile
+                destination = destFile
             }
             task "${taskName}_java"(type: JavaCompile) {
                 source = javaFiles
@@ -1757,15 +1758,6 @@
                 destinationDir = destDir
                 from fileTree(dir: destDir, include: 'Test.class')
             }
-            task "${taskName}_dx"(type: DxTask, dependsOn: "${taskName}_jar") {
-                source = fileTree(dir: destDir, include: 'Test.jar')
-                destination = destDir
-            }
-            task "${taskName}_dexmerger"(
-                    type: DexMergerTask, dependsOn: ["${taskName}_dx", "${taskName}_smali"]) {
-                source = fileTree(dir: destDir, include: ["classes.dex", intermediateFileName])
-                destination = destFile
-            }
         }
     }
 }
diff --git a/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java b/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java
index a89ee46..384043c 100644
--- a/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunSmaliTestsTest.java
@@ -216,7 +216,6 @@
   @Test
   public void SmaliTest() throws Exception {
     Path originalDexFile = Paths.get(SMALI_DIR, directoryName, dexFileName);
-    // Path outputPath = temp.getRoot().toPath().resolve("classes.dex");
 
     if (failingOnX8.contains(directoryName)) {
       thrown.expect(CompilationFailedException.class);
@@ -229,9 +228,21 @@
     boolean originalFailing =
         (originalFailingOnArtVersions.containsKey(version)
             && originalFailingOnArtVersions.get(version).contains(directoryName));
+    Path testJar = Paths.get(SMALI_DIR, directoryName, "Test.jar");
+    boolean testJarExists = testJar.toFile().exists();
+    Path testJarDex = null;
+    if (testJarExists) {
+      testJarDex =
+          testForD8(Backend.DEX)
+              .setMinApi(parameters)
+              .addProgramFiles(testJar)
+              .compile()
+              .writeToZip();
+    }
     testForR8(parameters.getBackend())
         .addKeepAllClassesRule()
         .addProgramDexFileData(Files.readAllBytes(originalDexFile))
+        .applyIf(testJarExists, p -> p.addProgramFiles(testJar))
         .addDontWarn(missingClasses.getOrDefault(directoryName, Collections.emptySet()))
         .setMinApi(parameters)
         .compile()
@@ -243,12 +254,14 @@
 
     // Also run the original DEX if possible.
     if (!dalvikVerificationError && !originalFailing) {
+      ImmutableList.Builder<String> dexListBuilder = ImmutableList.builder();
+      dexListBuilder.add(originalDexFile.toString());
+      if (testJarExists) {
+        dexListBuilder.add(testJarDex.toString());
+      }
       String originalOutput =
           ToolHelper.runArtNoVerificationErrors(
-              ImmutableList.of(originalDexFile.toString()),
-              "Test",
-              null,
-              parameters.getRuntime().asDex().getVm());
+              dexListBuilder.build(), "Test", null, parameters.getRuntime().asDex().getVm());
       assertEquals(expectedOutput, originalOutput);
     }
   }