Do not generate empty dex in multidex.

This was possible when the first class considered for adding in a dex was too
big to be sure it will fit. Now DX will try to add the class in the current dex
and crash if the class causes one index to overflow.

Change-Id: Ia1f8f733ee49e24bbb42db335ac9080312c1907a
diff --git a/dx/src/com/android/dx/command/dexer/Main.java b/dx/src/com/android/dx/command/dexer/Main.java
index 406e267..c5f9c94 100644
--- a/dx/src/com/android/dx/command/dexer/Main.java
+++ b/dx/src/com/android/dx/command/dexer/Main.java
@@ -712,7 +712,10 @@
         int maxFieldIdsInDex = numFieldIds + constantPoolSize + cf.getFields().size() +
                 MAX_FIELD_ADDED_DURING_DEX_CREATION;
 
-        if (args.multiDex && ((maxMethodIdsInDex > args.maxNumberOfIdxPerDex) ||
+        if (args.multiDex
+            // Never switch to the next dex if current dex is already empty
+            && (outputDex.getClassDefs().items().size() > 0)
+            && ((maxMethodIdsInDex > args.maxNumberOfIdxPerDex) ||
                 (maxFieldIdsInDex > args.maxNumberOfIdxPerDex))) {
             DexFile completeDex = outputDex;
             createDexFile();
diff --git a/dx/src/com/android/dx/dex/file/DexFile.java b/dx/src/com/android/dx/dex/file/DexFile.java
index 01a5e4b..103985c 100644
--- a/dx/src/com/android/dx/dex/file/DexFile.java
+++ b/dx/src/com/android/dx/dex/file/DexFile.java
@@ -323,7 +323,7 @@
      *
      * @return {@code non-null;} the class definitions section
      */
-    /*package*/ ClassDefsSection getClassDefs() {
+    public ClassDefsSection getClassDefs() {
         return classDefs;
     }