Whenever I try to run my App, it always fails and it gives this error

  • What went wrong: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. com.android.build.api.transform.TransformException: Error while generating the main dex list.

I have been trying to resolve for some days but none of the solutions work.

I have tried to downgrade the versions of Firebase dependency, changed the minimum sdk version and many other things which were available on the Internet. Probably it is a version problem for the firebase dependency but I couldn't get a hold of that.

This is my pubspec.yaml file

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

This is the app/build.gradle file in which some changes were to be made for the solution but which didn't work. I haven't added the complete file but just some parts which are essential.

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'

My build.gradle file


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

I have tried these workarounds:

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

And some other solutions as well from Stack and Github but nothing helped me up. Personally I believe that the problem lies with the Firebase dependency version and its compatibililty with AndroidX.

Screenshot of the error: https://ibb.co/G2sXnpx

It would be great if someone can help me on this because I couldn't get my head around this problem for over 5 days now :( .

1 Answers

0
Filled Stacks On

In your app/build.gradle file you're indicating that you want to use multidex in the default config with

multiDexEnabled true

But you don't have multidex as a dependency. Add under your dependencies

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