首页 > 解决方案 > 每当我尝试运行我的 Flutter 应用程序时执行此任务的“app:transformClassesWithMultidexlistForDebug”

问题描述

每当我尝试运行我的应用程序时,它总是失败并给出此错误

  • 出了什么问题:任务“:app:transformClassesWithMultidexlistForDebug”执行失败。com.android.build.api.transform.TransformException:生成主 dex 列表时出错。

几天来我一直在尝试解决,但没有一个解决方案有效。

我试图降级 Firebase 依赖项的版本,更改了最低 sdk 版本以及 Internet 上提供的许多其他内容。可能这是firebase依赖项的版本问题,但我无法掌握。

这是我的pubspec.yaml文件

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  url_launcher: ^4.0.2
  dio: any
  path_provider: any
  carousel_pro: ^0.0.13
  firebase_messaging: ^5.0.1
  sqflite: any
  #cloud_firestore: ^0.7.4
  firebase_database: ^3.0.0
  photo_view: ^0.2.2
  webview_flutter: ^0.3.4
  flutter_webview_plugin: ^0.3.5

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: ^0.7.0

这是app/build.gradle 文件,其中将对解决方案进行一些更改,但没有奏效。我没有添加完整的文件,只是添加了一些必不可少的部分。

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.technothlon.techno_app"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }


dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-messaging:17.3.3'

}

apply plugin: 'com.google.gms.google-services'

我的build.gradle文件


    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.2.0'
    }

我已经尝试了这些解决方法:

  1. https://github.com/flutter/flutter/issues/23929
  2. https://github.com/flutter/flutter/issues/23131

还有一些来自 Stack 和 Github 的其他解决方案,但没有任何帮助。我个人认为问题在于Firebase 依赖版本及其与AndroidX的兼容性。

报错截图:https ://ibb.co/G2sXnpx

如果有人能在这方面帮助我,那就太好了,因为我现在已经有 5 天以上无法解决这个问题了 :( 。

标签: androidfirebasedartflutterandroidx

解决方案


由于@Filled Stacks 的回答没有解决您的问题,因此问题出在 AndroidX 中,并且您的 Flutter 应用程序中已弃用支持库冲突。

根据 Flutter 文档:

AndroidX 可以通过两种方式在编译时破坏 Flutter 应用程序:

  1. 该应用程序使用 AndroidX 插件,其主要 build.gradle 文件的 compileSdkVersion 版本低于 28。
  2. 该应用同时使用已弃用的代码和 AndroidX 代码。

https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility

长话短说:您要么将整个应用程序迁移到 AndroidX,要么检查所有依赖项并确保它们都基于 Android 支持库而不是 AndroidX。

这次没有灵丹妙药,抱歉。

正如您在这个流行的无 AndroidX 库列表中所看到的,它们都已经过时了。因此,我建议您迁移到 AndroidX,除非您有一个基于已弃用支持库且无法替换的密钥库。


推荐阅读