应用程序需要 Flutter 中的 Multidex 支持吗?

发布于 2025-01-13 10:12:04 字数 2224 浏览 3 评论 0原文

我在 Flutter 中构建应用程序时遇到此错误。尽管我做了启用它所需的一切,但似乎没有启用 multidex 的问题。 错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeProjectDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
     Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
     Type androidx.activity.R$attr is defined multiple times: C:\Users\Abdul rehman\OneDrive\Desktop\CSC451\Capstone Project\harfanah\build\app\intermediates\project_dex_archive\debug\out\4b5c628c7fbb96e2839e63f71f8803802c039de25c33dd9c9475187dc45e6e1a_1.jar:classes.dex, C:\Users\Abdul rehman\OneDrive\Desktop\CSC451\Capstone Project\harfanah\build\app\intermediates\project_dex_archive\debug\out\9bd7ed05083b8d3edbf142363966d832d9f0694faefda4d175e3ad8ad18fc06d_1.jar:classes.dex

* 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 30s
[!] App requires Multidex support
    Flutter multidex handling is disabled. If you wish to let the tool configure multidex, use the --mutidex flag.
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

这是我已经检查了所有解决方案的 。 启用了 Multidex 支持并使用了最新版本:

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.harfanahApplication.harfanah"
        minSdkVersion 21
        targetSdkVersion 32
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }
.
.
.

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation("androidx.multidex:multidex:2.0.1")
}

我还将这些添加到 gradle.properies

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

但它仍然不起作用。有什么建议吗?

I'm getting this error while building my app in Flutter. it seems the problem that the multidex is not enabled even though I did everything needed to enable it. this the error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeProjectDexDebug'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
     Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
     Type androidx.activity.R$attr is defined multiple times: C:\Users\Abdul rehman\OneDrive\Desktop\CSC451\Capstone Project\harfanah\build\app\intermediates\project_dex_archive\debug\out\4b5c628c7fbb96e2839e63f71f8803802c039de25c33dd9c9475187dc45e6e1a_1.jar:classes.dex, C:\Users\Abdul rehman\OneDrive\Desktop\CSC451\Capstone Project\harfanah\build\app\intermediates\project_dex_archive\debug\out\9bd7ed05083b8d3edbf142363966d832d9f0694faefda4d175e3ad8ad18fc06d_1.jar:classes.dex

* 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 30s
[!] App requires Multidex support
    Flutter multidex handling is disabled. If you wish to let the tool configure multidex, use the --mutidex flag.
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

I have already checked all of the solutions.
enabled Multidex support and used the latest version:

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.harfanahApplication.harfanah"
        minSdkVersion 21
        targetSdkVersion 32
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }
.
.
.

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation("androidx.multidex:multidex:2.0.1")
}

I also added these to gradle.properies

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

Still it is not working. any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夏至、离别 2025-01-20 10:12:04

您是否尝试过“flutter clean”然后重建?您可以使用“flutter build --multidex”让 Flutter CLI 工具为您完成此操作。

Have you tried "flutter clean" and then rebuild? You can let the Flutter CLI tool do it for you with "flutter build --multidex".

杯别 2025-01-20 10:12:04

使用flutter clean并且
flutter pub get

然后您将收到是否需要安装的通知。
输入y(是)。然后使用flutter run

use flutter clean and
flutter pub get

then you will get a notification on whether you need to install it or not.
type y (yes) to it .then use flutter run

三生路 2025-01-20 10:12:04

我在 Mac M1(2021) 上遇到了同样的问题。为了在 Android 设备上进行调试,我稍微扩展了 @AntEdode 的解决方案:

flutter build apk --multidex --debug

在构建过程中,会弹出相同的错误,但是 SDK 现在会询问您是否要安装 multidex:

[!] App requires Multidex support
    Multidex support is required for your android app to build since the number of methods has exceeded 64k. You may pass the --no-multidex
    flag to skip Flutter's multidex support to use a manual solution.

    Flutter tool can add multidex support. The following file will be added by flutter:

        android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java

Do you want to continue with adding multidex support for Android? [y|n]: 

确认后 - 瞧:

✓  Built build/app/outputs/flutter-apk/app-debug.apk.

在您的模拟器上运行:

flutter run --multidex   

I had the same issue on a Mac M1(2021). To debug on an android device, I extended @AntEdode's solution a bit:

flutter build apk --multidex --debug

During build, the same error will pop up, however the SDK will now ask whether or not you want to install multidex:

[!] App requires Multidex support
    Multidex support is required for your android app to build since the number of methods has exceeded 64k. You may pass the --no-multidex
    flag to skip Flutter's multidex support to use a manual solution.

    Flutter tool can add multidex support. The following file will be added by flutter:

        android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java

Do you want to continue with adding multidex support for Android? [y|n]: 

After confirmation - voila:

✓  Built build/app/outputs/flutter-apk/app-debug.apk.

To run on your emulator:

flutter run --multidex   
沫离伤花 2025-01-20 10:12:04

在 Android Studio 的终端中运行 flutter run --debug,然后选择一个 Android 设备。

系统将提示您启用 multidex 支持,请按 y。

Flutter 工具将启用 multidex 支持并重试构建,一切顺利!

Run flutter run --debug in your android studio's terminal, and select an Android device.

You will be prompted to enable multidex support, press y.

Flutter tool will enable multidex support and retry the build, and you are good to go!

脱离于你 2025-01-20 10:12:04

我直接在设备上调试时遇到类似的错误。由于它在 VS Code 调试控制台中显示错误,因此它没有显示启用 multidex 支持的选项。

无法提示终端 ui

但是如果你在终端/git-bash 等中运行 flutter run ,它会提示你一个启用它的选项。启用后,应用程序将成功构建并安装。

输入图像描述这里

I got a similar error while debugging on the device directly. Since it was showing an error in VS Code debug console, it didn't show the option to enable multidex support.

cannot prompt without a terminal ui

But if you run flutter run in terminal/git-bash etc, it will prompt you with an option to enable it. Once enabled, the app is built and installed successfully.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文