2

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
  • 1,834
  • 14
  • 24
  • Check this answer out https://stackoverflow.com/a/46559940/10136013 – Peter O. Jan 02 '22 at 21:22
  • @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

0 Answers0