Android d8命令行在编译文件时,提示Cannot fit requested classes in a single dex file (# fields: 98482 > 65536). Try supplying a main-dex list
Compilation failed
Cannot fit requested classes in a single dex file (# fields: 98482 > 65536). Try supplying a main-dex list
PS C:\Users\73916\Desktop\test> d8 .\com.gsc.pub-r-classes.jar
Error: Cannot fit requested classes in a single dex file (# fields: 98482 > 65536). Try supplying a main-dex list
Compilation failed
dx与d8都是Android studio中的编译工具。使用dx编译时,可以利用下面的指令处理方法数大于65536的情况。但是使用d8指令进行编译时,没有了--multi-dex命令,此时,如果还想使用d8命令行生成多个dex指令,该如何实现。
dx --dex --multi-dex --output . .\com.gsc.pub-r-classes.jar
但是使用d8指令解决一个jar包中方法数超过65536的dex编译问题。
为解决d8编译命令时方法数大于65536的问题,您可以考虑使用main-dex-list提供的方法,该方法需要指定应该位于主dex文件中的类的列表。您可以使用d8编译命令,并将main-dex-list选项与dexbuilder命令一起使用。具体来说,可以使用下面的命令:
d8 --output . .\com.gsc.pub-r-classes.jar --main-dex-list maindexlist.txt
其中,maindexlist.txt是指定的类的列表,可以使用任意文本编辑器编写。此命令将使用指定的类列表,并生成单个dex文件。如果需要,您可以生成多个dex文件。
使用d8指令解决一个jar包中方法数超过65536的dex编译问题,可以使用--main-dex-list参数来指定一个主dex列表,以指定哪些类应该放在主dex文件中,以避免方法数超过65536的限制。