【问题标题】:DexOverflowException after adding com.google.firebase:firebase-firestore:11.4.2添加 com.google.firebase:firebase-firestore:11.4.2 后的 DexOverflowException
【发布时间】:2017-10-06 21:51:05
【问题描述】:

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

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

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

【问题讨论】:

    标签: android firebase dex google-cloud-firestore


    【解决方案1】:

    尝试将这些行添加到您的 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);
      }
    }
    

    【讨论】:

      【解决方案2】:

      您没有做错任何事:Cloud Firestore 的 Android API 实在是太大了。我们将在走向 GA 的道路上努力减少 SDK 的大小。

      同时,如果您的应用程序不重要,您需要enable multidex 来构建。

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

      【讨论】:

        【解决方案3】:

        更新到 11.6.0 解决了这个问题

        【讨论】:

          猜你喜欢
          • 2018-03-16
          • 1970-01-01
          • 1970-01-01
          • 2018-03-30
          • 2018-10-24
          • 2023-03-29
          • 1970-01-01
          • 1970-01-01
          • 2018-04-25
          相关资源
          最近更新 更多