添加com.google.firebase后的DexOverflowException:firebase-firestore:11.4.2

时间:2017-10-06 21:51:06

标签: android firebase dex google-cloud-firestore

添加编译后出现问题" com.google.firebase:firebase-firestore:11.4.2"我的构建。

只要我添加它,它还会将com.google.common添加到我的dex文件中,这大约是27k额外引用,因此突破了64k dex限制。

有谁知道为什么或我做错了什么?

3 个答案:

答案 0 :(得分:6)

尝试将这些行添加到build.gradle

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}

这将启用multidex模式,这将允许您超过64k限制。 (阅读更多here

API低于21

如果您使用的API级别低于21,那么您还需要添加支持库

gradle.build:

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

android.manafest

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

如果您使用自定义Application课程,请尝试使用以下

中的一个

解决方案1 ​​

简单地覆盖MultiDexApplication类

public class MyApplication extends MultiDexApplication { ... }

解决方案2

覆盖attachBaseContext并使用install(Application)函数

安装MultiDex
public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

答案 1 :(得分:3)

您没有做错任何事情:Cloud Firestore的Android API很大。我们正在努力减少通往GA的SDK规模。

与此同时,如果您的申请非常重要,则需要enable multidex来构建。

我们实际上只使用了很少的com.google.common,因此您也可以在proguarding your application的64k方法限制下说出来。

答案 2 :(得分:1)

更新到11.6.0修复了此问题

相关问题