The number of method references in a .dex file cannot exceed 64K.

解决方法:分割Dex

实现方法:

1、相关链接

 https://developer.android.com/tools/building/multidex.html#about

2、在app的 build.gradle 中

(1)在dependencies 中添加

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

(2)在 defaultConfig 中添加

multiDexEnabled true

比如

 defaultConfig {
    applicationId "XXX.XXX.XXX"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    multiDexEnabled true
}

3、AndroidManifest.xml 中的 application 标签中添加

<?xml version="1.0" encoding="utf-8"?>    
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="XXX.XXX.XXX">
     <application
         ...
         android:name="android.support.multidex.MultiDexApplication">
        ...
     </application>
 </manifest>

提示:如果你的应用程序继承 Application , 那么你需要重写

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

猜你喜欢

转载自blog.csdn.net/LuckChouDog/article/details/68067287