Multidex issue with Flutter

2,135 views
Skip to first unread message

Dave Spooner

unread,
Apr 18, 2018, 9:09:31 AM4/18/18
to Flutter Dev
Hi all. I've posted this on StackOverflow (https://stackoverflow.com/questions/49886597/multidex-issue-with-flutter) and in the flutter gitter, but not really had any response.

As far as I can tell, when adding too many dependencies to my flutter app, I trigger the Android 64k limit. Where "too many dependencies" is two. The error can be reproduced by creating a new, empty flutter project in Android Studio, adding the following two dependencies, and running the app.

Error:
  1. FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
    > java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Dependencies:
flutter_google_place_picker: "^0.0.1"
location: "^1.2.0"

flutter doctor -v
$ flutter doctor -v
[√] Flutter (Channel beta, v0.2.8, on Microsoft Windows [Version 10.0.16299.371], locale en-GB)
     Flutter version 0.2.8 at D:\flutter
     Framework revision b397406561 (2 weeks ago), 2018-04-02 13:53:20 -0700
     Engine revision c903c217a1
     Dart version 2.0.0-dev.43.0.flutter-52afcba357

[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
     Android SDK at C:\Users\Dave\AppData\Local\Android\sdk
     Android NDK location not configured (optional; useful for native profiling support)
     Platform android-27, build-tools 27.0.3
     Java binary at: D:\AndroidDev\jre\bin\java
     Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
     All Android licenses accepted.

[√] Android Studio (version 3.1)
     Android Studio at D:\AndroidDev
     Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)

[√] Connected devices (1 available)
     Android SDK built for x86 64  emulator-5554  android-x64  Android 5.1.1 (API 22) (emulator)

 No issues found!

I sort of assumed I'd actually exceeded the 64k limit with two potentially quite large dependencies. But I've not got much Android dev experience making this somewhat hard to diagnose. There's more information on the SO if useful.

Thanks in advance for any suggestions.

Eugenio Tesio

unread,
Apr 18, 2018, 9:31:11 AM4/18/18
to Dave Spooner, Flutter Dev
The same happend to my in an Android Pure proyect in Android Studio. I solve it decrementing the gradle plugin to 3.0.1. Go to android folder in you flutter project, find the build.gradle and use this gradle plugin verision classpath 'com.android.tools.build:gradle:3.0.1' .

Hope this can help you.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Eugenio Tesio
Zetus - Soluciones Empresariales
División Sistemas
(+549) 3564-15-599945
San Francisco - 2400
Pcia de Córdoba - Argentina



Dave Spooner

unread,
Apr 18, 2018, 9:34:46 AM4/18/18
to Flutter Dev
Hi Eugenio, thanks a lot for your reply. I'm quite sad to report that it was already 3.0.1.

Mikkel Ravn

unread,
Apr 18, 2018, 9:39:01 AM4/18/18
to spoo...@gmail.com, Flutter Dev

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Mikkel Nygaard Ravn
Software Engineer

Karthik Ponnam

unread,
Apr 18, 2018, 9:54:48 AM4/18/18
to Flutter Dev

inside your build.gradle file

location : rootProject/android/app/build.gradle


add thses below lines


implementation
('com.google.android.gms:play-services-places:11.8.0') {
    force
= true
}
implementation
('com.google.android.gms:play-services-location:11.8.0') {
    force
= true
}


at the bottom all dependencies like below


dependencies {

   
...


    implementation
('com.google.android.gms:play-services-places:11.8.0') {
        force
= true
   
}
    implementation
('com.google.android.gms:play-services-location:11.8.0') {
        force
= true
   
}


}

Dave Spooner

unread,
Apr 18, 2018, 9:58:25 AM4/18/18
to Flutter Dev
For the record (in case anyone reads this later), that's worked, thank you very much!

Dave Spooner

unread,
Apr 18, 2018, 9:59:37 AM4/18/18
to Flutter Dev
Thanks Karthik, good to have an alternative. See Mikkel's response for what I presume is a slightly different option.

Olawale Alabi

unread,
Feb 9, 2019, 5:20:52 PM2/9/19
to Flutter Dev
I have been stucked at this for several hours with no respite!
I have done all the recommended suggestions and its becoming a little bit irritating.
So, I am following the official recommendations of adding firebase to a brand new flutter project.
I cant afford to serve only 21 SDKs and above.
So, I am hit with the dex limits simply by adding a few official firebase plugins.
One of the overriding suggestions was to accomodate more than one dex files...sounds neat but for some weird reasons, all recommended steps seemed to work for others but me.
But here is another suggestion, that I reduce the amount of methods imported.
This sounds neater and the best route in my opinion but still, I cant make it work.
As per your suggestion, I tried to import only:
implementation ('com.google.firebase:firebase-core:16.0.7') {
force = true
}
implementation ('com.google.firebase:firebase-database:16.0.6') {
force = true
}
and removed
 compile 'com.android.support:multidex:1.0.3'
and
classpath 'com.google.gms:google-services:4.2.0'

Several permutations but none seems working.
Why I said this is becoming irritating is, thinking about it....
How am I the only who had ever thought of importing only a few services instead of EVERYTHING into my projects, or how am I the only one convinced that having a bloated project is a big worry on performance.
Just about 4 standard plugins on an empty project triggring 64K method limits.
Isn't that weird?
Now, if I am not the only one with these concerns, why is there no clear-cut solutions to these glaring gotchas?
Why is there no official steps-by-steps instruction that actually works?

Well, at this point, I need every help I can get from anyone who has actually broken through this limits.
Thanks so much!!!!

Steven McDowall

unread,
Feb 9, 2019, 7:00:54 PM2/9/19
to Olawale Alabi, Flutter Dev
Do yourself a favor and just release to iOS .. :) 

Seriously I’d Multidex now and get it done .. you’ll have to probably invoke it anyway if using Firebase and other Google stuff

If you need help DM and I can share the grade build we use .. it’s pretty easy

Sent from my iPad

Olawale Alabi

unread,
Feb 10, 2019, 5:05:05 AM2/10/19
to Flutter Dev
I wish it were that easy Steven...
My target market is Nigeria, and the majority is on Android, running on SDKs far lower than 20.
Hence, my need to  make it work, or bust.
Thanks for the offer!
I will make sure to take you up on it when going iOS.
Reply all
Reply to author
Forward
0 new messages