4

How to solve this error I'm getting in Android Studio:

Error: Cannot fit requested classes in a single dex file (# methods: 67593 > 65536)

cant build my project now

sharonooo
  • 684
  • 3
  • 8
  • 25
sah Rishabh
  • 51
  • 1
  • 3
  • https://stackoverflow.com/questions/48249633/errorcannot-fit-requested-classes-in-a-single-dex-file-try-supplying-a-main-dex answer to your issue – hossam scott Oct 14 '18 at 09:51
  • 4
    Possible duplicate of [Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536](https://stackoverflow.com/questions/48249633/errorcannot-fit-requested-classes-in-a-single-dex-file-try-supplying-a-main-dex) – nijm Oct 14 '18 at 09:53

3 Answers3

3

Do this 4 step

1: Add this library in dependencies of the app build.gradle :

implementation 'com.android.support:multidex:1.0.3'

2: Add in the defaultConfig of the app build.gradle :

defaultConfig {
    //other configs
    multiDexEnabled true //add this line
}

3: Create new Java class like this :

public class ApplicationClass extends MultiDexApplication {
    @Override
    public void onCreate() {
           super.onCreate();
    }
}

4: Add this to your manifest (in application tag):

<application
    android:name=".ApplicationClass"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name">
Radesh
  • 13,084
  • 4
  • 51
  • 64
3

Same situation happened in my Visual Studio 2019 Xamarin project, and the way to solve this problem is just like what mentioned in the link: Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536

multiDexEnabled true

By checking the Enable multiDex checkbox in the option page of the ***.Droid project solves the problem.

Edward
  • 53
  • 5
2

Before you take any decision, as said in Google documentation :

Before configuring your app to enable use of 64K or more method references, you should take steps to reduce the total number of references called by your app code, including methods defined by your app code or included libraries.

So try to remove useless importation in your app gradle and do a nice clean project or do multidex

Source : https://developer.android.com/studio/build/multidex

Hocine B
  • 391
  • 2
  • 8