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

When creating with Unity, I get 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.

+6
source share
3 answers

I suggest checking out the official Unity3D forum on this issue:

Support for multiple Android applications

And Q / A from there: Too many method references when exporting an Android assembly

Here is a response from a Unity spokesperson:

So the biggest reason we haven't added support to Unity is because it doesn't work. Rather, it usually creates more problems than it solves. If you do not focus only on modern versions of Android, I would advise you to do everything in your power, including deleting and preliminary checking your code before you go through a route with several decks.

If you do not believe me, just check out the well-known limitations of the multi-dex library on the Googles developer page: https://developer.android.com/tools/building/multidex.html#limitations

So, we will do our best to reduce the number of methods to stay within 65K. For example, if you use google-play-services.jar, you can replace it only with the necessary submodules.

It also discusses exporting to Android Studio and creating a project there, but apparently it did not work due to a problem with dex.

In addition, I recommend reading this article about the DEX problem.

Hope this helps. Good luck

+7
source

To activate multidex on Unity, follow 3 simple steps:

enter image description here

1) Use the Gradle build system:

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

2) Check in the "Custom Gradle Template":

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

3) Modify the mainTemplate.gradle file:

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

Add the following code:

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

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

+2
source

I would recommend you go through this link, which will help you create multiidex games right through unity.

https://medium.com/@abhpatidar/solving-unity-dex-issue-538e134c8809

Note. This will only enable multidex in unity (and should fix problems with multiple items). It will not fix gradle related issues.

0
source

Source: https://habr.com/ru/post/990019/


All Articles