Cannot fit requested classes in a single dex file (# methods: 66661 > 65536)

原因:dex文件中方法过多;

解决:推荐引入使用MultiDex包解决

1 引入依赖api 'androidx.multidex:multidex:2.0.1'(版本可选)

2 app的build.gradle中加入multiDexEnabled true

defaultConfig {
    applicationId "com.xx.xxxx"
    minSdkVersion 19
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"

    //写在这里~
    multiDexEnabled true

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

3 application中加入multiDex.install(提醒:application要加入到AndroidManiFest中去)

1
2
3
4
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
MultiDex.install(this)
}