2

After I added the next dependecies to my Flutter project:

cloud_firestore: ^0.9.0   
firebase_auth: ^0.8.0+1   
google_sign_in: ^4.0.0

I tried to run the app by clicking the run button in Android Studio but something weird is happening here:

Case 1: If I open the root Flutter project directory from Android Studio, Let's call it my_flutter_app directory, and click the run button I get the next error:

D8: Cannot fit requested classes in a single dex file (# methods: 68762 > 65536) java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a .dex file cannot exceed 64K.

Note: I perfectly understand what that error means and how to solve it, in fact if I add the known line to solve it:

multiDexEnabled true

With its respective dependencies the app is built fine and deployed to the device without getting any errors.

But the weird thing is the next:

Case 2: If I open the android directory of the same Flutter app from Android Studio, I mean my_flutter_app/android directory, and click the run button the app is built fine and deployed to the device without getting any errors. (Yes, without modifying any files, exactly the same scenario for both cases, without the multiDexEnabled true line)

So, I want to know what is happening here? Why the Android project does not showing me that 64K methods DEX error while the Flutter project does?

I'm trying to keep my develop stuff as clean as possible so I'm hesitating to add that multiDexEnabled true line if is not necessary, so that's the reason of my question.

EDIT: Here are the contents for each directories:

This is the Flutter root directory view

This is the Flutter root directory view

This is the Android directory view

This is the Android directory view

SaloGala
  • 1,904
  • 3
  • 14
  • 19

1 Answers1

0

classes in a single dex file (# methods: 68762 > 65536)

This clearly tells you that your method counts are higher than the acceptable method count for a single dex file(64K).

So in order to fix that you should enable multidex in gradle file or remove unwanted or unused third party libs from the project.

If you ask why this is happening on Android Studio only? then the reason might be some default core classes which is loaded by Android Studio.

enter image description here

Nithis Kumar
  • 278
  • 2
  • 5
  • 21
  • No, I'm asking why this is happening by running the app from the Flutter root directory only and not from Android directory? (For both cases I'm using Android Studio). And as I wrote in the question I perfectly know what that 64K Dex Error means and how to solve it. – SaloGala Feb 09 '19 at 04:19
  • You're not getting an error while running the project from `my_flutter_app/android` and it happens only when you run the project from `my_flutter_app` directory right!? – Nithis Kumar Feb 09 '19 at 04:28
  • I edited the question to show the contents inside both directories – SaloGala Feb 09 '19 at 04:44
  • Well, as I said some additional third-party or internal libraries being loaded by Android Studio when you compile it from `Project` view and at the same time AS ignores something when you switch to `Android` view. – Nithis Kumar Feb 09 '19 at 04:48