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

Dav*_*vid 4 android dex firebase google-cloud-firestore

将编译"com.google.firebase:firebase-firestore:11.4.2"添加到我的构建后,我遇到了问题.

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

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

小智 7

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

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

这将启用multidex模式,这将允许您超过64k限制.(在这里阅读更多)

API低于21

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

gradle.build:

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

如果您使用自定义Application类,请尝试使用以下一个

解决方案1

只需覆盖MultiDexApplication类

public class MyApplication extends MultiDexApplication { ... }
Run Code Online (Sandbox Code Playgroud)

解决方案2

attachBaseContext使用该install(Application)函数覆盖并安装MultiDex

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}
Run Code Online (Sandbox Code Playgroud)