zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Android工程中方法数超过65536解决方法(Kotlin)

AndroidKotlin方法 解决 工程 超过
2023-09-27 14:27:30 时间

Android Studio报错:

The number of method references in a .dex file cannot exceed 64K.
Caused by: com.android.tools.r8.utils.AbortException: Error: Cannot fit requested classes in a single dex file (# methods: 68815 > 65536)

解决方案

  1. build.gradle文件android的defaultConfig里面增加multiDexEnabled true
  2. build.gradle文件dependencies里面增加implementation 'com.android.support:multidex:1.0.3'
  3. Application类中增加
  • kotlin写法
    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }
  • java写法
@Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }