Flutterfire: [all] D8: Cannot fit requested classes in a single dex file

Created on 13 Oct 2019  路  5Comments  路  Source: FirebaseExtended/flutterfire

Including multiple firebase_ plugins simultaneously in a pubspec.yaml file is enough to exceed the amount of Java methods that can be included in an Android APK by default, so compilation breaks.

Repro steps

  1. flutter create foo
  2. Edit the pubspec.yaml to add the extra deps below.
dependencies:
  cloud_firestore: any
  firebase_core: any
  firebase_database: any
  firebase_ml_vision: any
  firebase_performance: any
  firebase_remote_config: any
  firebase_storage: any
  1. flutter build apk

Error output

flutter build apk
Initializing gradle...                                              0.7s
Resolving dependencies...                                           1.4s
D8: Cannot fit requested classes in a single dex file (# methods: 76505 > 65536)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForRelease'.

Fix for affected apps

This can be addressed in affected apps using the plugins by turning on multidexing in their build following the same steps as a typical Android app.

Fix for the plugins?

It's not clear to me what should be done about this. It ties into wider ongoing discussions about abstracting underlying platform code.

  1. We could grep or lint for this error in flutter tool and print out a log pointing users to something explaining this error, what multidexing is, how to turn it on.
  2. We could warn for this in the README of the firebase plugins themselves since they're likely to be used in combination.
  3. There may be a way to turn on multidexing for an app within a plugin? I'm not sure if this is actually preferable here even if it's possible. Multidexing has downsides.
  4. Could we proguard the plugins without turning proguard on for entire apps that include them? This would prune unused methods and make it a lot harder to hit this error, but wouldn't totally prevent it.

/cc @Sun3
/cc @dnfield @Hixie @amirh

crowd bug documentation

Most helpful comment

I too had the same problem I just changed my min SDK version above 21 in the build.gradle, It solved the problem for me

All 5 comments

@mklim

The issue at https://github.com/flutter/flutter/issues/27702 has been closed and moved here. Future collaboration on this issue will be done here.

Hi @mklim
You might want to check this possible solution
If are you still experiencing this issue
with the latest version of Flutter and FlutterFire plugin
can you please provide your flutter doctor -v
and your and your flutter run --verbose/flutter build --verbose ?
Also, to better address the issue, would be helpful
if you could post a self contained app on github
or the steps to reproduce it.
Thank you

I too had the same problem I just changed my min SDK version above 21 in the build.gradle, It solved the problem for me

For now, changing min SDK to 21 means losing ~5-6% old devices. Do you plan to make firebase sdk to work with SDK 16?

Was this page helpful?
0 / 5 - 0 ratings