Android Multidex问题

时间:2016-11-13 22:02:48

标签: android android-studio gradle multidex

升级到Android Studio 2.2后,我的应用有问题:Multidex 64k methods limit

但是,我的应用程序是一个非常简单的应用程序,它只有很少的库。

这是我的傻瓜:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.digitalborder.webappessentials"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 24
        versionName "2.2.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    useLibrary 'org.apache.http.legacy'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.google.android.gms:play-services:9.6.1'
    compile 'com.google.firebase:firebase-core:9.2.0'
}

apply plugin: 'com.google.gms.google-services'

有人可以帮助我吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

您的问题的原因很可能是游戏服务:

compile 'com.google.android.gms:play-services:9.6.1'

如果您确实需要这些功能,请尝试选择其中的一部分。它被分成几个较小的库,如:

com.google.android.gms:play-services-auth:9.8.0
com.google.android.gms:play-services-ads:9.8.0
com.google.android.gms:play-services-games:9.8.0

完整列表可用here

答案 1 :(得分:0)

请查看Android multidex doc

OR

您可以尝试使用此代码;

defaultConfig {
    applicationId "com.digitalborder.webappessentials"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 24
    versionName "2.2.2"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.android.support:multidex:1.0.1'
}

并创建新类

public class myApplicationClass extends Application{
   @Override
    public void onCreate() {
        MultiDex.install(getApplicationContext());
        super.onCreate();
    }
}