admin 发表于 2018-6-15 16:01:02

Android方法数methods超过65536

当Android App中的方法数超过65535时,如果往下兼容到低版本设备时,就会报编译错误:
Cannot fit requested classes in a single dex file. Try supplying a main-dex list.
# methods: 86204 > 65536
Message{kind=ERROR, text=Cannot fit requested classes in a single dex file. Try supplying a main-dex list.
# methods: 86204 > 65536, sources=, tool name=Optional.of(D8)}原因是Android系统定义总方法数是一个short int,short int 最大值为65536。解决这个问题的方案是:

在Android的模块gradle文件的defaultConfig默认配置里面增加:

multiDexEnabled true同时在dependencies里面增加:
implementation 'com.android.support:multidex:1.0.3'另外需要把AndroidMainfest.xml里面添加自定义的App继承自MultiDexApplication。
页: [1]
查看完整版本: Android方法数methods超过65536