0





10

Advertisement

there

I'm currently study Ajadx project and have found out there could be more than one classes.dex file. Is there anyone who knows why and perhaps the evolving Android development history about it? Thank you!

Question author Kafe-chang | Source

Advertisement


0


The maximum .dex (Dalvik Executable) operation (not dex size) for Java is 4g (means, 4 GegaBytes).

The "multidex enabled" means the system can create more than one dex files on need.

When happens dex operation? It happens whenever you create apk (means, in apk build).

The maximum single dex size is 65K (means, 65KiloByte).

Note: 8K dex file can cross 65K dex operations if there are so many concurrent executions in your application. You could get the similar error even though you set total (max.) dex operation size is 4g. See this picture, MultidexEnabled: false error. It is fine in build projects, but, you get this error when you try to build APK.

To solve this, you need to enable multidex. After you enable multidex and when you build, Android Studio generates corresponding first dex file from first 65K dex operation memory, 2nd dex file from second 65K dex operation memory and so on.

Now, when you change your build.gradle to enable multidex, you can build your APK. Now, you apk file is ready. You uncompress your apk file and go inside that folder. You can see something like below picture.See this picture folder structure which contains dex files

You see, there are two dex files: classes.dex and classes2.dex. First classes.dex file is (in my example) is 8.3MB which is output of first 65K concurrent dex operations. And, the second classes2.dex file is output of rest dex operations which (We don't know exactly but we know it is less than 65K).

In this way, the overall dex operations for total dex files is 4g (4GB), which you asked here.

Hope, I gave your answer.

Answer author Uddhav-gautam