Enable multiDex for Unity Project

When your app and the libraries it references exceed 65,536 methods, you encounter a build error that indicates your app has reached the limit of the Android build architecture. Find more here.

Unity 5.5 and above

Using Unity 5.5 and above you can enable multiDex without exporting your project. Please follow this steps to enable multiDex:

Switch to Gradle Build System

  • Open File -> Build Settings... in Unity Editor.
  • Select Android in platform list and click Switch Platform.
  • Select Gradle (new) in Build System dropdown.

Configure Gradle Config

  • Skip if using Unity 2017.2 and above. For Unity 5.5 up to 2017.1 you need to copy mainTemplate.gradle from [unity_folder]/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/mainTemplate.gradle to your project [your_project_path]/Assets/Plugins/Android/mainTemplate.gradle.
  • Skip if using Unity below 2017.2. Open Player Settings then move to Publishing Settings in Inspector menu and tick Custom Gradle Template checkbox. It will create mainTemplate.gradle file in your Assets/Plugins/Android/ folder. 
  • Now open mainTemplate.gradle file in any text editor.
  • Add multiDexEnabled true as a new line inside the defaultConfig object.

If your minSdkVersion is set to 20 or lower

  • Open your main AndroidManifest.xml. It should be located in Assets/Plugins/Android/ folder. If you don't have it there just copy it from [unity_folder]/PlaybackEngines/AndroidPlayer/Apk/AndroidManifest.xml and change package name there to yours.
  • Find application tag and add there one more line: android:name="android.support.multidex.MultiDexApplication"
  • If you are using Unity 2018.2 or newer, add implementation 'com.android.support:multidex:1.0.1' as new line inside root dependencies object.
  • If your Unity version is older, add compile 'com.android.support:multidex:1.0.1' as new line inside root dependencies object.