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.
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.
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.
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.
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.
For activation multidex on Unity follow a 3 simple steps:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With