【问题标题】:"app:transformClassesWithMultidexlistForDebug" execution for this task whenever I try to run my Flutter app每当我尝试运行我的 Flutter 应用程序时执行此任务的“app:transformClassesWithMultidexlistForDebug”
【发布时间】:2019-09-30 02:30:18
【问题描述】:

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

  • 出了什么问题: 任务 ':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 天以上无法解决这个问题了 :( .

【问题讨论】:

  • 通过将 minSdkVersion 更改为 19 或 21 来检查,我遇到了类似的问题,这对我有用。

标签: android firebase dart flutter androidx


【解决方案1】:

由于@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

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

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

正如您在this list of popular AndroidX-free libs 中看到的那样,它们都已经过时了。因此,我建议您迁移到 AndroidX,除非您有一个基于已弃用的支持库且无法替换的密钥库。

【讨论】:

    【解决方案2】:

    在您的 app/build.gradle 文件中,您表示要在默认配置中使用 multidex

    multiDexEnabled true
    

    但是您没有 multidex 作为依赖项。在你的依赖项下添加

    dependencies {
      ...
      implementation 'com.android.support:multidex:1.0.3'
    }
    

    【讨论】:

    • 不幸的是,这也不起作用。它给出了与以前相同的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 2016-04-09
    • 2022-06-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 2021-09-11
    相关资源
    最近更新 更多