android studio 3上的multidex错误

时间:2017-11-16 16:11:57

标签: android multidex

在升级到AS 3之前,我在我的项目中使用了multidex就好了,升级后每次我尝试在设备上运行应用程序甚至生成APK时都会出现此错误

  

错误:将字节码转换为dex时出错:原因:   com.android.dex.DexException:多个dex文件定义   LCOM /谷歌/机器人/克/ AUTH / API /登入/内部/ ZZP;   错误:com.android.dex.DexException:多个dex文件定义   LCOM /谷歌/机器人/克/ AUTH / API /登入/内部/ ZZP;错误:at   com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)   错误:at   com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)   错误:at   com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)   错误:at   com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)   错误:在com.android.dx.merge.DexMerger.merge(DexMerger.java:198)   错误:at   com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)   错误:at   com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)   错误:at   java.util.concurrent.ForkJoinTask $ AdaptedCallable.exec(ForkJoinTask.java:1424)   错误:at   java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)   错误:at   java.util.concurrent.ForkJoinPool $ WorkQueue.runTask(ForkJoinPool.java:1056)   错误:at   java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)   错误:at   java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

请注意,我所做的只是更新AS并将gragra打包到3.0.0。我尝试回到2.3.3,但它告诉我项目不兼容。

这是我的Multidex代码:

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "net.mohammed.billmob"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

和我的申请类:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);


    }

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

这些是应用程序依赖项:

dependencies {



    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })



    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true
    }


    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:mediarouter-v7:26.1.0'

   // compile 'com.google.android.gms:play-services:11.6.0'
    compile 'com.google.android.gms:play-services-location:11.6.0'

    compile 'com.google.firebase:firebase-core:11.6.0'
    compile 'com.google.firebase:firebase-crash:11.6.0'
    compile 'com.google.firebase:firebase-auth:11.6.0'
    compile 'com.google.firebase:firebase-messaging:11.6.0'
    compile 'com.google.firebase:firebase-database:11.6.0'
    compile 'com.google.firebase:firebase-perf:11.6.0'

    compile 'com.karumi:dexter:4.1.0'

    compile 'com.firebaseui:firebase-ui-auth:3.1.0'

    compile 'com.facebook.android:facebook-android-sdk:4.28.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.github.bumptech.glide:glide:4.0.0'
    compile 'com.android.support:support-v4:26.1.0'

    compile 'com.android.support:multidex:1.0.1'
/*    compile 'com.android.support:multidex:1.0.2'
    androidTestCompile 'com.android.support:multidex:1.0.2'
    androidTestCompile 'com.android.support:multidex-instrumentation:1.0.2'*/


    annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
    testCompile 'junit:junit:4.12'
}

2 个答案:

答案 0 :(得分:0)

Sol我通过将firebase和google依赖项降级到11.4.2来解决它,以匹配此处提供的firebase ui版本:https://github.com/firebase/FirebaseUI-Android

答案 1 :(得分:0)

试一试:
1.启用multiDex:

android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
    ...
} 

更多信息:
https://developer.android.com/studio/build/multidex.html

  1. 配置gradle插件和gradle版本:
  2. //gradle-wrapper.properties
    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    //project build.gradle
    classpath 'com.android.tools.build:gradle:3.0.0'
    

    更多信息:
    https://developer.android.com/studio/releases/gradle-plugin.html