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

When using Android studio to open the Android project exported from unity, due to the access to several SDKs, this problem occurs when compiling the project: “cannot fit requested classes in a single DEX file (# methods: 72633 > 65536) “and then I read other materials on the Internet, but I didn’t solve this problem. Finally, I read the following document, document link: 。
as for the reason for this problem, the document says: “when your application and its referenced library contain more than 65536 methods, you will encounter a build error”, that is, you have received the 64K reference limit of Android. What is the 64K reference limit?Documentation: Android application (APK) files contain executable bytecode files in the form of Dalvik executable (DEX) files, which contain the compiled code used to run the application. The Dalvik executable specification limits the total number of methods that can be referenced in a single DEX file to 65536, including Android framework methods, library methods, and methods in your own code. In the field of computer science, the term K stands for 1024 (2 ^ 10). Since 65536 is equal to 64 x 1024, this restriction is called “64K reference restriction”. Well, the reason for the problem is probably clear, that is, it has been solved. In fact, there are two solutions given by the document
the first method: if minsdkversion is set to 21 or higher, multidex will be enabled by default, and the support library for multidex is not required<
the second method: if minsdkversion is set to 20 or lower, you must use the multidex support library and modify the application project
first, modify the module level build.gradle file to enable multidex, and add the multidex library as a dependency


android {
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
        multiDexEnabled true

dependencies {
  implementation ''

Then customize an application

import android.content.Context;

public class App extends Application{

    protected void attachBaseContext(Context base) {

finally calls App in mainfest and recompiles it to OK. In fact, the second method is useless, and the problem is still there, so I tried the first method, and set minsdkversion to 21, and the problem was solved…
in this paper, we used the second method to solve the problem

Similar Posts: