Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Android, flutter run throws "error: package androidx.multidex does not exist" #148368

Closed
songyang-dev opened this issue May 15, 2024 · 11 comments · Fixed by #148515
Closed

On Android, flutter run throws "error: package androidx.multidex does not exist" #148368

songyang-dev opened this issue May 15, 2024 · 11 comments · Fixed by #148515
Assignees
Labels
P1 High-priority issues at the top of the work list platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-android Triaged by Android platform team workaround available There is a workaround available to overcome the issue

Comments

@songyang-dev
Copy link

songyang-dev commented May 15, 2024

Steps to reproduce

  1. Take an existing Flutter project from Flutter 3.19. The existing project must be using multidex support.
  2. flutter upgrade to Flutter 3.22.
  3. flutter run on Android

Actual results

The app should launch in the Android emulator.

Logs

Logs
$ flutter run
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
C:\Users\songy\Documents\Projects\Music with Anna\quick_ear\android\app\src\main\java\io\flutter\app\FlutterMultiDexApplication.java:13: error: package androidx.multidex does not exist
import androidx.multidex.MultiDex;
                        ^
C:\Users\songy\Documents\Projects\Music with Anna\quick_ear\android\app\src\main\java\io\flutter\app\FlutterMultiDexApplication.java:23: 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.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Running Gradle task 'assembleDebug'...                              6.3s
Error: Gradle task assembleDebug failed with exit code 1
Error output and standard output:

error.log
run.log

Flutter Doctor output

Doctor output
$ flutter doctor 
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [Version
    10.0.22631.3447], locale en-CA)
[√] Windows Version (Installed version of Windows is version 10 or
    higher)
[√] Android toolchain - develop for Android devices (Android SDK     
    version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community    
    2022 17.9.4)
[√] Android Studio (version 2023.3)
[√] VS Code (version 1.89.1)
[√] Connected device (4 available)
[√] Network resources

• No issues found!
@songyang-dev
Copy link
Author

This is related to #98136

@songyang-dev
Copy link
Author

songyang-dev commented May 15, 2024

Possible workaround: https://stackoverflow.com/questions/49886597/multidex-issue-with-flutter/60158352

But I suggest Flutter handles multidex by itself when an existing project is migrated to a newer version.

@penkzhou
Copy link

@songyang-dev just delete the FlutterMultiDexApplication file ,it works for me.

@chotixity
Copy link

Deleting the FlutterMultiDexApplication file works for now

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 15, 2024
@darshankawar
Copy link
Member

Thanks for the report @songyang-dev
I tried to do the same by going back to 3.16.0 to 3.22.0, but was unable to replicate the reported error.
I tried with flutter run and flutter run --multidex both.
Can you provide exact steps to replicate or a pattern or a config that is needed to replicate this in latest stable ?
Also, if you switch back to 3.19, can you check if the same error occurs or not ?
You can also provide relevant file details that are required to properly replicate the issue.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 15, 2024
@Kuhlemann
Copy link

Deleting the FlutterMultiDexApplication file works for now

Manually deleting worked for me too, but in my opinion this has to work out of the box after upgrading to Flutter 3.22.

@songyang-dev
Copy link
Author

songyang-dev commented May 16, 2024

I forgot to specify that the existing project needs to be using multidex support. When you run it on the older version of Flutter, it should say in the console that multidex support is being used.

Oh and sorry about the version number. The old version is 3.19.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 16, 2024
@darshankawar
Copy link
Member

Thanks for the update. I will try to setup and replicate this by going back to previous stable versions and have multidex support. I tried with an existing project by running it in 3.19 and upon upgrading it worked fine, but need to see the multidex support for that project, but it'll take a bit time to properly replicate this.

Meantime, I'll keep the issue open and label based on the reported behavior, for team's attention.

@darshankawar darshankawar added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team workaround available There is a workaround available to overcome the issue and removed in triage Presently being triaged by the triage team labels May 16, 2024
@quentin7b
Copy link

quentin7b commented May 16, 2024

In my side, flutter build appbundle was working fine, then upgrade to 3.22 and same error.

I had to update my android/app/build.gradle like the doc specifies

android {
    defaultConfig {
        multiDexEnabled true
    }
}

dependencies {
    implementation "androidx.multidex:multidex:2.0.1"
}

Now everything went back to normal.
In my side, flutter build appbundle was working fine, then upgrade to 3.22 and same error.

I had to update my android/app/build.gradle like the doc specifies

android {
    defaultConfig {
        multiDexEnabled true
    }
}

dependencies {
    implementation "androidx.multidex:multidex:2.0.1"
}

Now everything went back to normal.

The doc mentions

Therefore, if your minSdkVersion is 21 or higher, multidex is enabled by default and you don't need the multidex library.

Maybe it works for project that hardcode minSdkVersion, however I'm using minSdkVersion flutter.minSdkVersion

EDIT:

Look at #148368 (comment) before doing this.

@Kuhlemann
Copy link

Maybe it works for project that hardcode minSdkVersion, however I'm using minSdkVersion flutter.minSdkVersion

In my project "minSdkVersion 23" is hardcoded in android/app/build.gradle but I still had the problem.

@gmackall gmackall self-assigned this May 16, 2024
@gmackall gmackall added P1 High-priority issues at the top of the work list triaged-android Triaged by Android platform team labels May 16, 2024
@gmackall
Copy link
Member

gmackall commented May 16, 2024

Hmm yes, it looks like this was an oversight in https://github.com/flutter/flutter/pull/142267/files - there was logic to create a FlutterMultiDexApplication.java file when multidex was enabled. Multidex is enabled by default, now, for all android versions that flutter supports, and so that logic was removed.

But the removal of the logic to create the file doesn't remove the file itself, and that file itself relies on imports that were also removed in that PR, it seems. The correct solution here is to delete the file.

auto-submit bot pushed a commit that referenced this issue May 21, 2024
@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High-priority issues at the top of the work list platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-android Triaged by Android platform team workaround available There is a workaround available to overcome the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants