3

While running my Flutter app, I sometimes use the Visual Studio Code menu: Run > Start Debugging, and some other times I use the CLI: flutter run -d H (a Huawei device)

I've been using the CLI while I integrated: Firebase (Firestore, Storage) and Stripe. At some point I hit the Multidex 64K reference error so I upgraded to minSdkVersion 21 in build.gradle to get rid of that issue.

According to these instructions, API 21 already includes Multidex so I didn't need to configure anything else. Although at some point I did have to add android.useAndroidX=true in gradle.properties file, I just don't remember when or why.

The problem now: I want to run the app from the VS Run menu, but I get this error:

Users/maganap/Documents/develop/projects/kiryoku/kiryoku-app-flutter-3/android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java:8: error: package androidx.multidex does not exist
import androidx.multidex.MultiDex;
                        ^
/Users/maganap/Documents/develop/projects/kiryoku/kiryoku-app-flutter-3/android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java:18: error: cannot find symbol
    MultiDex.install(this);
    ^
  symbol:   variable MultiDex
  location: class FlutterMultiDexApplication
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

But, it does work properly when run from the CLI with flutter run -d H.

The question: I just don't want to start guessing and changing settings here and there to make it work, since following any documentation I can find about this apparently is only required when < API 21. Does anyone know the proper way to solve this?

% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.63.2)
[✓] Connected device (3 available)

Thanks in advance.

maganap
  • 2,414
  • 21
  • 24
  • Check this answer out https://stackoverflow.com/a/46559940/10136013 – Peter Obiechina Jan 02 '22 at 21:22
  • 1
    @PeterO. As you can read in that same answer: `This problem occurs only for apps that support Android versions below Lollipop (API level 21).`. I'm using API 21. That's exactly what I want to avoid... configuring settings trying to randomly guess. – maganap Jan 03 '22 at 08:51
  • @PeterO. Well it does work, if you were wondering. But it contradicts the official documentation. What I'd really like to know is why, and what's the difference between running debug from the CLI vs from VS Run menu. Anyway I'm temporarily using the suggestion in that other answer. Thank you. – maganap Jan 03 '22 at 21:25

3 Answers3

1

This Stackoverflow Answer solves it

Add multiDexEnabled to true in your defaultConfig app/build.gradle file

  defaultConfig {
      ...
       multiDexEnabled true
    }

and also add

  dependencies{
   ...
   implementation 'com.android.support:multidex:1.0.3'
    }
 
0

Add implementation 'com.android.support:multidex:1.0.3' to your dependencies

0

Unluckily, it seems like this is a known issue. A good thing would be to upvote it, so it gets more attention.

[Android] flutter run --multidex fails with error: package androidx.multidex does not exist #98136

Until then, I find myself forced to use the terminal.

PS. I added a VSCode-related comment in the thread, so upvote that too if you have that issue.

venir
  • 1,809
  • 7
  • 19
  • 1
    Upvoted issue. Although that was a project I'm not working with anymore. It's not happening to me in other projects, but I'll try to test that old project in Flutter 3 just to have some updated feedback. – maganap Aug 02 '22 at 10:32
  • Thanks, considering upvoting this answer too, to give it more visibility – venir Aug 02 '22 at 14:36