Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable multi-dex option for Android in Unity3D?

On building with Unity, I am getting an error:

trouble writing output: Too many method references: 78849; max is 65536.
You may try using --multi-dex option.

But I can't figure out how to explicitly tell Unity to use multi dex.

like image 510
Igor Kostenko Avatar asked Jun 30 '15 14:06

Igor Kostenko


People also ask

Why multidex is required in Android?

This number represents the total number of references that can be invoked by the code within a single Dalvik Executable (DEX) bytecode file. This page explains how to move past this limitation by enabling an app configuration known as multidex, which allows your app to build and read multiple DEX files.

What is multidex unity?

Multidex is a tool that is required for Android projects that exceed DEX limit – over 64K methods. You can read from the official Android documentation for developers what this dex limit is and how to enable Multidex in Android projects.

Where do I put multiDexEnabled true?

Step 3: Working with build.gradle(module) fileGo to build. gradle file, inside that you will find the scope { } of defaultConfig then inside that scope just add multiDexEnabled = true as shown below then click sync now.

Why multidex?

If you are working on an Android application that includes more than 64K methods then to avoid the 64K reference limit, you can use Multidex in your application.


1 Answers

For activation multidex on Unity follow a 3 simple steps:

enter image description here

1) Use Gradle build system:

Unity -> File -> Build Settings -> Build System -> Gradle.

2) Check in "Сustom Gradle Template":

Player Setting... -> Publish Settings -> Check in "Сustom Gradle Template"

3) Change mainTemplate.gradle file:

Open file from path: Assets\Plugins\Android\mainTemplate.gradle

Add folow code:

android 
{
   ...
   defaultConfig
   {
       multiDexEnabled true
       ...
    }
}

Additional information: https://docs.unity3d.com/Manual/android-gradle-overview.html

like image 106
Anonimys Avatar answered Sep 25 '22 18:09

Anonimys