[Solved] com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

At the same time, multiple third-party jar packages were introduced into the project, which caused the number of methods to be called to exceed 65536 set by android (DEX 64K problem), which caused the dex to be unable to be generated, and thus the APK file could not be generated.

The solution is as follows:

1. Google has officially given relevant documents, referring to the information searched on the Internet. First of all, my question is:

Error:Execution failed for task ':duchazhushou:dexRelease'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Users\jeff\AppData\Local\Android\sdk\android-sdk\build-tools\21.1.1\dx.bat --dex --output D:\dev\android\Duchazhushou_TDT\duchazhushou\build\intermediates\dex\release --input-list=D:\dev\android\Duchazhushou_TDT\duchazhushou\build\intermediates\tmp\dex\release\inputList.txt
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
        at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
        at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
        at com.android.dx.merge.DexMerger.mergeMethodIds (DexMerger.java: 491 )
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
        at com.android.dx.merge.DexMerger.merge (DexMerger.java: 189 )
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
        at com.android.dx.command.dexer.Main.run(Main.java:245)
        at com.android.dx.command.dexer.Main.main(Main.java:214)
        at com.android.dx.command.Main.main(Main.java:106)

2. Add sub-package settings in the dependencies section of the project’s build.gradle file:

dependencies { 
... 
   compile 'com.android.support:multidex:' 
   ... 
}

3. Enable multi-dexing support by setting the multiDexEnabled tag to true in the defaultConfig section.

defaultConfig { 
   ... 
multiDexEnabled true 
... 
}

4. There are three cases. Since I did not create my own Application.class, I added it directly to the Application declaration in the AndroidManifest.xml file;

android:name="android.support.multidex.MultiDexApplication"

5. Rebuild, generate signed APK, install and use normally.

Similar Posts: