Andorid 方法数超过64K的问题

转载:http://blog.csdn.net/wblyuyang/article/details/51813501


其实早就听过64K这个问题,只是觉得目前所做的项目较小,应该不会有这个问题。出现这个问题的直接原因我觉得应该是集成进了高德地图的三个jar包:309KB、377KB、474KB。然后的某天突然就提示64K的问题了,最开始我把无用的jar包删除了两个,没过三天,又出现了,以下是Android studio的提示:

Error:The number of method references in a .dex file cannot exceed 64K. 
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

不仅给出了错误原因,还给出了解决方案:https://developer.android.com/tools/building/multidex.html
这个文档说明了出现这个错误的原因、解决办法及优化方案,值得一看。 
解决方案也很简单,两步: 
* 在build.gradle里面加入multiDexEnabled true

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
  • pplication里面重写 attachBaseContext 方法
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

问题解决。


猜你喜欢

转载自blog.csdn.net/qq_24451593/article/details/79554308