Revert "Revert "Enable running tests on r8lib with dependencies""

This reverts commit 98478dceff1b57e15148eea7a7603d2f41606858.

Change-Id: I18ea656d32c162164025618b072b0f2d600b2141
diff --git a/tools/archive.py b/tools/archive.py
index 78a8189..ce04494 100755
--- a/tools/archive.py
+++ b/tools/archive.py
@@ -92,9 +92,10 @@
     raise Exception('You are not a bot, don\'t archive builds')
 
   # Generate an r8-ed build without dependencies.
-  # Note: build_r8lib does a gradle-clean, this must be the first command.
-  build_r8lib('r8nomanifest', True, True, utils.R8LIB_KEEP_RULES,
-    utils.R8LIB_EXCLUDE_DEPS_JAR)
+  # The '-Pno_internal' flag is important because we generate the lib based on uses in tests.
+  gradle.RunGradleExcludeDeps([utils.R8LIB_NO_DEPS, '-Pno_internal'])
+  shutil.copyfile(utils.R8LIB_JAR, utils.R8LIB_EXCLUDE_DEPS_JAR)
+  shutil.copyfile(utils.R8LIB_JAR + '.map', utils.R8LIB_EXCLUDE_DEPS_JAR + '.map')
 
   # Create maven release which uses a build that exclude dependencies.
   create_maven_release.main(["--out", utils.LIBS])
@@ -106,6 +107,7 @@
   # Ensure all archived artifacts has been built before archiving.
   # The target tasks postfixed by 'lib' depend on the actual target task so
   # building it invokes the original task first.
+  # The '-Pno_internal' flag is important because we generate the lib based on uses in tests.
   gradle.RunGradle([
     utils.R8,
     utils.D8,
@@ -114,6 +116,7 @@
     utils.R8LIB,
     utils.COMPATDXLIB,
     utils.COMPATPROGUARDLIB,
+    '-Pno_internal'
   ])
   version = GetVersion()
   is_master = IsMaster(version)