Keep main dex check enabled in D8
RELNOTES: Building Android apps for legacy multi-dex (pre-L) now require a main-dex list if the application does not fit into a single DEX file.
PiperOrigin-RevId: 327633282
diff --git a/src/tools/android/java/com/android/tools/r8/CompatDxSupport.java b/src/tools/android/java/com/android/tools/r8/CompatDxSupport.java
index 68aaf8a..70d1c0e 100644
--- a/src/tools/android/java/com/android/tools/r8/CompatDxSupport.java
+++ b/src/tools/android/java/com/android/tools/r8/CompatDxSupport.java
@@ -13,7 +13,6 @@
// limitations under the License.
package com.android.tools.r8;
-import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
@@ -58,23 +57,6 @@
// as bazel might link to a shrunken r8.jar which does not have these APIs.
Object app = getInputAppMethod.invoke(command);
Object options = getInternalOptionsMethod.invoke(command);
- // DX allows --multi-dex without specifying a main dex list for legacy devices.
- // That is broken, but for CompatDX we do the same to not break existing builds
- // that are trying to transition.
- try {
- Field enableMainDexListCheckField = internalOptionsClass.getField("enableMainDexListCheck");
- try {
- // Use reflection for:
- // <code>options.enableMainDexListCheck = false;</code>
- // as bazel might link to an old r8.jar which does not have this field.
- enableMainDexListCheckField.setBoolean(options, false);
- } catch (IllegalAccessException e) {
- throw new AssertionError("Unsupported r8.jar", e);
- }
- } catch (NoSuchFieldException e) {
- // Ignore if bazel is linking to an old r8.jar.
- }
-
runForTestingMethod.invoke(null, app, options);
} catch (ReflectiveOperationException e) {
// This is an unsupported r8.jar.
diff --git a/src/tools/android/java/com/google/devtools/build/android/r8/CompatDx.java b/src/tools/android/java/com/google/devtools/build/android/r8/CompatDx.java
index d7cddd5..5e1afdf 100644
--- a/src/tools/android/java/com/google/devtools/build/android/r8/CompatDx.java
+++ b/src/tools/android/java/com/google/devtools/build/android/r8/CompatDx.java
@@ -46,7 +46,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
-import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -637,19 +636,7 @@
if (dexArgs.backportStatics) {
CompatDxSupport.enableDesugarBackportStatics(builder);
}
- try {
- // Check if the referenced r8.jar has these methods. If so, the support code accessing
- // the internals is not required.
- Method setEnableMainDexListCheck =
- D8Command.Builder.class.getDeclaredMethod("setEnableMainDexListCheck", boolean.class);
- // The methods are package private to not reveal them as part of the external API.
- setEnableMainDexListCheck.setAccessible(true);
- setEnableMainDexListCheck.invoke(builder, Boolean.FALSE);
- D8.run(builder.build());
- } catch (ReflectiveOperationException e) {
- // Go through the support code accessing the internals for the compilation.
- CompatDxSupport.run(builder.build());
- }
+ D8.run(builder.build());
} finally {
executor.shutdown();
}