android - 添加 com.google.firebase :firebase-firestore:11. 4.2 后出现 DexOverflowException

标签 android firebase dex google-cloud-firestore

在我的构建中添加编译“com.google.firebase:firebase-firestore:11.4.2”后我遇到了问题。

一旦我添加它,它还会将 com.google.common 等添加到我的 dex 文件中,这是大约 27k 的额外引用,从而突破了 64k 的 dex 限制。

有谁知道这是为什么还是我做错了什么?

最佳答案

尝试将这些行添加到您的 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 类,请尝试使用以下之一

方案一

简单地覆盖 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);
  }
}

关于android - 添加 com.google.firebase :firebase-firestore:11. 4.2 后出现 DexOverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46614405/

相关文章:

java - 如何遍历数据库中的子项并将它们应用于变量

ios - ld : framework not found FirebaseAuth error due to residual firebase components

java - Android Studio 动态加载库

android - Proguard标志dontobfuscate导致Translation has been interrupted异常

java - 如何显示 EditText 中的文本?

java - 确定 ScheduledExecutorService 下次触发的时间

ios - Swift Firebase UIRefreshControl 创建重复的帖子

android - Android Test Orchestrator 是否生成任何测试报告?

android - 无法在 Android 架构组件 1.1.1 : 中找到类 DiffCallback