error

UNEXPECTED TOP-LEVEL EXCEPTION:  
java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536 
trouble writing output: 
Too many field references: 131000; max is 65536.

 

 reason:

Dex文件方法数超过了65535的上限

 

analyze:

E-android 编译65536问题原因及解决

 solution:

1.minSdkVersion 设置为 21 或更高值,

您只需在模块级 build.gradle 文件中将 multiDexEnabled 设置为 true,如此处所示:

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

2.minSdkVersion 设置为 20 或更低值

step1: 添加分包库依赖

 compile 'com.android.support:multidex:1.0.3'

 step2: 初始化

方法一:重写 attachBaseContext 方法

public class MyApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

方法二:直接继承MultiDexApplication

public class MyApplication extends MultiDexApplication {

     // 不需要重写attachBaseContext()

     //..........
}

data from:

https://developer.android.com/studio/build/multidex

https://www.cnblogs.com/dongweiq/p/7116326.html

相关文章:

  • 2021-10-14
  • 2021-11-13
  • 2022-03-04
  • 2021-10-16
  • 2022-12-23
  • 2021-12-09
  • 2021-04-25
  • 2021-06-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-09-30
  • 2021-11-03
相关资源
相似解决方案