How it all started
Hello everyone. At a certain stage in the development of a game for Android on the Unity engine, I encountered one problem with the build. After adding plugins such as Appodeal and Google Play Games to the project, the number of methods used exceeded 65K and the following error appeared during the build:Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
After reading the Appodeal documentation, I realized that I needed to enable Multidex. I decided to do it. The site had a link with instructions for Android Studio. And then we at Unity, what should we do?And everything is pretty simple, you just have to do three actions:Enable Gradle Build System
To enable Gradle in Unity in your Android project- In Unity, open Build Settings ( File >> Build Settings )
- If you have not chosen a platform, then it's time to do it ( Platform >> Android )
- In the Build System list, select Gradle ( Build System >> Gradle )

Change Gradle Settings
1. To change Gradle settings, you first need to get the Gradle settings file, which is located in the folder ( Assets / Plugins / Android / mainTemplate.gradle ). If the mainTemplate.gradle file is downloaded from the link and pasted to the address Assets / Plugins / Android / :Download file2. If you already have the file, add the line multiDexEnabled true to the defaultConfig3 object . If the minimum Android API level is 20 or lower , add this line compile 'com.android.support:multidex:1.0.1'4. Comment out or delete the lines:minifyEnabled **MINIFY_DEBUG**
useProguard **PROGUARD_DEBUG**
Final file view:
Initializing Multidex
If the minimum level of the Android API is set to 20 or lower.Update the manifest file located in Assets / Plugins / Android / AndroidManifest.XML . If you do not have this file, you will have to create it. You can find AndroidManifest by default.xml in the Unity installation location. But you will also have to manually apply the project settings of your application: package name, permissions, configuration parameters and other information.If you just created a new manifest file or you already had one, you simply add this parameter ( android: name ) as follows:
That's all. The error disappears, and you calmly build your project.Thank you for the attention.