Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gives error "Cannot fit requested classes in a single dex file"

I don't know why but it's impossible to launch my app on my mobile this morning. I get this error message:

Cannot fit requested classes in a single dex file. Try supplying a main-dex list.

# methods: 68061 > 65536 Message{kind=ERROR, text=Cannot fit requested classes in a single dex file. Try supplying a main-dex list.

# methods: 68061 > 65536, sources=[Unknown source file], tool

I'm really new to Android and I don't understand the problem and what I need to do? And why I get this problem now and not before?

like image 289
KevinB Avatar asked Jul 14 '18 17:07

KevinB


People also ask

How to solve cannot fit requested classes in a single dex file?

To Solve Cannot fit requested classes in a single dex file. Try supplying a main-dex list Error You just need to Add dependency androidx. multidex:multidex:2.0.

What is multidexEnabled in Android?

Android applications by default have SingleDex support which limits your application to have only 65536 methods(references). So multidexEnabled = true simply means that now you can write more than 65536 methods(references) in your application.


2 Answers

Add dependency in build.gradle file:

implementation 'androidx.multidex:multidex:2.0.1' 

In build.gradle's defaultConfig section add:

multiDexEnabled true 

More details here: Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536

like image 81
Gokul Nath KP Avatar answered Sep 19 '22 11:09

Gokul Nath KP


Running RN 0.62 and this worked for me with successful build.

Update build.gradle enter image description here

classpath('com.android.support:multidex:1.0.3')

Update defaultConfig

enter image description here

multiDexEnabled true

After those 2 changes, restart the gradle build again.

like image 32
Gajen Sunthara Avatar answered Sep 20 '22 11:09

Gajen Sunthara