Cannot fit requested classes in a single dex file
Cannot fit requested classes in a single dex file (# methods: 106132 > 65536 ; # fields: 79485 > 65536)

- 主要原因一个dex已经装不下项目,需要multidex
- 因为Android系统定义总方法数为short int,也就是65536,那么怎么解决呢
解决方案
找到app,moudle的build.gradle,加入如下配置
- 在app module中的build.gradle中的defaultConfig中添加以下代码
multiDexEnabled trueandroid {
compileSdkVersion 30
buildToolsVersion "30.0.2"
...
defaultConfig {
...
multiDexEnabled true
}- 在app module中的build.gradle中添加依赖
implementation 'com.android.support:multidex:1.0.3'dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}- 如果你自定义了Application需要在类中重写一个方法
MultiDex.install(this)...
override fun onCreate() {
super.onCreate()
...
//加在这里
MultiDex.install(this)
}
}










