Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DexOverflowException after adding com.google.firebase:firebase-firestore:11.4.2

I have a problem after adding compile "com.google.firebase:firebase-firestore:11.4.2" to my build.

As soon as I add that, it also adds com.google.common among other things to my dex file, which is around 27k extra references, thus bursting through the 64k dex limit.

Does anyone know why that is or am I doing something wrong?

like image 943
David Avatar asked Dec 19 '22 03:12

David


1 Answers

Try adding these lines to your build.gradle

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

This will enable multidex mode, which will allow you to exceed the 64k limit. (Read more here)

API below 21

If you're using an API level below 21, then you also need to add the support library

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>

If you use a custom Application class, try using one the of the following

Solution 1

simply override the MultiDexApplication class

public class MyApplication extends MultiDexApplication { ... }

Solution 2

override attachBaseContext and install MultiDex using the install(Application) function

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}
like image 81
edkek Avatar answered Mar 09 '23 00:03

edkek