Android 方法数超过64k限制的解决办法

android {
 compileSdkVersion COMPILE_SDK_VERSION as int
    buildToolsVersion BUILD_TOOLS_VERSION

    defaultConfig {
        applicationId "com.x.xxx"
        minSdkVersion MIN_SDK_VERSION as int
        targetSdkVersion TARGET_SDK_VERSION as int
        versionCode 4
        versionName "1.0.3"
        multiDexEnabled true
    }
    ...
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    dexOptions{
        javaMaxHeapSize "2g"
    }
}

1.在app的build.gradle文件中添加

multiDexEnabled true
dexOptions{
        javaMaxHeapSize "2g"
    }

2.在依赖中添加multidex

dependencies {
    ...
    compile 'com.android.support:multidex:1.0.0'
    }

3.重写Application子类的方法

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

参考:
http://www.itnose.net/detail/6168594.html

你可能感兴趣的:(Android笔记)