gradle 应用程序在flutter中需要Multidex支持?

vsnjm48y  于 2023-08-06  发布在  Flutter
关注(0)|答案(4)|浏览(221)

我在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


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

lh80um4z

lh80um4z1#

你有没有试过“扑干净”,然后重建?你可以让Flutter CLI工具通过“flutter build --multidex”来为你做这件事。

hrirmatl

hrirmatl2#

使用flutter cleanflutter pub get
然后你会得到一个通知,告诉你是否需要安装它。键入y(yes)到它.然后使用flutter run

6ovsh4lw

6ovsh4lw3#

我在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

x8diyxa7

x8diyxa74#

我得到了一个类似的错误,而调试设备上直接。由于它在VS Code调试控制台中显示错误,因此它没有显示启用multidex支持的选项。
x1c 0d1x的数据
但是如果你在terminal/git-bash等中运行flutter run,它会提示你一个选项来启用它。启用后,应用程序将成功构建和安装。


相关问题