天天看点

Android配置方法数超过 64K 的应用

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/studio/build/multidex.html?hl=zh-cn

下面做下简单总结解决步骤:

1、在build.gradle里面加入multiDexEnabled true

defaultConfig {      
        minSdkVersion 
        targetSdkVersion 

        // Enabling multidex support.
        multiDexEnabled true
    }
           

2、添加依赖包

/**dex分包*/
compile 'com.android.support:multidex:1.0.0'
           

3、在Application里面重写 attachBaseContext 方法

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

问题解决。

参考:http://blog.5ibc.net/p/85377.html

继续阅读