应用程序需要 Flutter 中的 Multidex 支持吗?
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否尝试过“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".
使用
flutter clean
并且flutter pub get
然后您将收到是否需要安装的通知。
输入
y
(是)。然后使用flutter run
use
flutter clean
andflutter pub get
then you will get a notification on whether you need to install it or not.
type
y
(yes) to it .then useflutter run
我在 Mac M1(2021) 上遇到了同样的问题。为了在 Android 设备上进行调试,我稍微扩展了 @AntEdode 的解决方案:
在构建过程中,会弹出相同的错误,但是 SDK 现在会询问您是否要安装 multidex:
确认后 - 瞧:
在您的模拟器上运行:
I had the same issue on a Mac M1(2021). To debug on an android device, I extended @AntEdode's solution a bit:
During build, the same error will pop up, however the SDK will now ask whether or not you want to install multidex:
After confirmation - voila:
To run on your emulator:
在 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!
我直接在设备上调试时遇到类似的错误。由于它在 VS Code 调试控制台中显示错误,因此它没有显示启用 multidex 支持的选项。
但是如果你在终端/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.
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.