From 73c4c0ec81bace888fe6592dbc58f16c79975418 Mon Sep 17 00:00:00 2001 From: ajmichael Date: Thu, 22 Jun 2017 21:07:34 +0200 Subject: Make it an error to pass --multidex=off with --main-dex-list or --minimal-main-dex. This matches dx's behavior. Previously, DexFileMerger would override --multidex=off with --multidex=minimal if either --main-dex-list or --minimal-main-dex were passed. RELNOTES: Incremental dexing errors on combination of --multidex=off and either --main-dex-list or --minimal-main-dex. PiperOrigin-RevId: 159858242 --- .../devtools/build/android/dexer/DexFileMerger.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/tools') diff --git a/src/tools/android/java/com/google/devtools/build/android/dexer/DexFileMerger.java b/src/tools/android/java/com/google/devtools/build/android/dexer/DexFileMerger.java index 0a68efb110..ebfb1ec1f2 100644 --- a/src/tools/android/java/com/google/devtools/build/android/dexer/DexFileMerger.java +++ b/src/tools/android/java/com/google/devtools/build/android/dexer/DexFileMerger.java @@ -96,7 +96,6 @@ class DexFileMerger { defaultValue = "null", category = "multidex", converter = ExistingPathConverter.class, - implicitRequirements = "--multidex=minimal", help = "List of classes to be placed into \"main\" classes.dex file." ) public Path mainDexListFile; @@ -105,7 +104,6 @@ class DexFileMerger { name = "minimal-main-dex", defaultValue = "false", category = "multidex", - implicitRequirements = "--multidex=minimal", help = "If true, *only* classes listed in --main_dex_list file are placed into \"main\" " + "classes.dex file." @@ -156,6 +154,16 @@ class DexFileMerger { @VisibleForTesting static void buildMergedDexFiles(Options options) throws IOException { + if (!options.multidexMode.isMultidexAllowed()) { + checkArgument( + options.mainDexListFile == null, + "--main-dex-list is only supported with multidex enabled, but mode is: %s", + options.multidexMode); + checkArgument( + !options.minimalMainDex, + "--minimal-main-dex is only supported with multidex enabled, but mode is: %s", + options.multidexMode); + } ImmutableSet classesInMainDex = options.mainDexListFile != null ? ImmutableSet.copyOf(Files.readAllLines(options.mainDexListFile, UTF_8)) : null; @@ -172,10 +180,6 @@ class DexFileMerger { if (classesInMainDex == null) { processDexFiles(zip, out, Predicates.alwaysTrue()); } else { - // Options parser should be making sure of this but let's be extra-safe as other modes - // might result in classes from main dex list ending up in files other than classes.dex - checkArgument(options.multidexMode == MultidexStrategy.MINIMAL, "Only minimal multidex " - + "mode is supported with --main_dex_list, but mode is: %s", options.multidexMode); // To honor --main_dex_list make two passes: // 1. process only the classes listed in the given file // 2. process the remaining files -- cgit v1.2.3