Multidex issue with Flutter

Cover Image for Multidex issue with Flutter
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

šŸ“± Solving the Multidex Issue with Flutter šŸ”„

Are you encountering an error related to multidex while compiling your Flutter project in Android Studio? Don't worry, you're not alone! This blog post will address common issues and provide easy solutions to help you get past this hurdle.

šŸš€ The Short Version:

The multidex issue is encountered when you add enough dependencies to your project. To enable multidex in a Flutter app, follow the steps below:

  1. Open the android/app/build.gradle file in your project.

  2. Add the following dependency under the dependencies section:

dependencies {
  compile ''
  1. Inside the android section, add the following configuration to your defaultConfig block:

android {
    defaultConfig {
        multiDexEnabled true

By doing this, you are configuring your app for multidex, which allows your app to have more than 65,536 methods.

šŸ”§ Steps to Recreate the Issue:

To recreate the multidex issue, follow these steps:

  1. Select File/New/New Flutter Project from the toolbar in Android Studio.

  2. Select "Flutter Application" and include Kotlin & Swift support.

  3. Check if the app compiles and runs successfully.

  4. Add the following dependencies in the pubspec.yaml file:

  flutter_google_place_picker: "^0.0.1"
  location: "^1.2.0"
  1. Run Packages Get in Android Studio or execute flutter packages get command in the project directory.

  2. Modify the android/app/build.gradle file as mentioned in the "Short Version" section.

  3. Finally, select Run/Run from the toolbar to see the error.

šŸ¤” Other Things I've Tried:

If the above steps don't solve your multidex issue, you can try the following alternatives:

  1. Replace the "compile" dependency in build.gradle with each of the following options:

compile ''
implementation ''
implementation ''
  1. Follow the multidex steps for each of your dependencies. Modify their respective build.gradle files, enable multidex, and add the multidex dependency.

  2. Modify the minSdkVersion to either 21 or 27 in the build.gradle files of your project and its dependencies. Also, enable multidex for them.

  3. Enable minifying for your project.

  4. Replace location: "^1.2.0" with geolocation: "^0.2.1".

  5. Try not enabling multidex at all (skipping step 7 of the recreation process). This may result in a different error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: Unable to merge dex

If none of these alternatives work for you, continue reading for more troubleshooting options.

šŸ›  Flutter Doctor Output:

To help you further, here is a sample output of flutter doctor -v command:

$ 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!

Make sure that your Flutter and Android SDK installations are up-to-date and properly configured.

šŸ“¢ Call-to-Action:

I hope this guide helped you understand and solve the multidex issue with Flutter. If you have any further questions or need additional assistance, feel free to leave a comment or get in touch. Let's fix this and keep Fluttering! šŸ˜Š

Leave a comment | Contact us | Share on social media

More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago

šŸ”„ šŸ’» šŸ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! šŸš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago

# The Art of Stripping Punctuation: Simplifying Your Strings šŸ’„āœ‚ļø Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago

# Purge or Recreate a Ruby on Rails Database: A Simple Guide šŸš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? šŸ¤” Well, my

Matheus Mello
Matheus Mello