Reprint: http://blog.csdn.net/wblyuyang/article/details/51813501
In fact, I have heard about the problem of 64K for a long time, but I think that the current project is relatively small, so there should be no such problem. I think the direct cause of this problem should be the three jar packages integrated into the Gaode map: 309KB, 377KB, and 474KB. Then one day, the problem of 64K was suddenly prompted. At first, I deleted two useless jar packages. After three days, it appeared again. The following is the prompt of 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
Not only the cause of the error, but also the solution is given: https://developer.android.com/tools/building/multidex.html
This document explains the reason, solution and optimization plan for this error, it is worth seeing .
The solution is also very simple, two steps:
* Add multiDexEnabled true in build.gradle
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
- Rewrite the attachBaseContext method in the application
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
problem solved.