我得到了这个错误,而我的应用程序在颤栗。似乎问题是多重索引没有启用,即使我做了所有必要的启用它。这是错误
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
但它仍然不起作用。有什么建议吗?
发布于 2022-09-05 17:07:59
我在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
https://stackoverflow.com/questions/71443293
复制相似问题