- Home /
Too many method references when I export android build
When I export android build, I got some errors below
stderr[
trouble writing output: Too many method references: 74004; max is 65536. You may try using --multi-dex option. References by package: ...
how do I use '--multi-dex option' ?
or
how to set on project.properties files in Unity side? I know dex force jumbo flags can help. but I cant find it in Unity.
how do I avoid this situation?
Yes. I use many kinds of sdks. but I needs those.
Answer by liortal · Oct 26, 2014 at 07:43 AM
This excellent post describes why this error happens in the first place: https://medium.com/@rotxed/dex-skys-the-limit-no-65k-methods-is-28e6cb40cf71
Unity is "hard-wired" to run the dex tool with a certain set of arguments. You cannot modify that unfortunately.
What you could do is output a code project ("Google Android Project") and then build it from the command line using the appropriate options.
Another solution would be to limit the number of method references your game has to avoid this issue in the first place. This can be done in a number of different ways:
Remove unused native Android plugins from your project.
Use Gradle + ProGuard to strip any unused / unreferenced code automatically.
Use Gradle + Multidex to create multiple dex files, overcoming the reference count limit (although his is not recommended, which is why I listed it as the last option).
I can't export a project either because of the dex issue.
no. I have the same issue. The method limit is being reached because of third party libraries such as the Google Games plugin rather than the game itself. We can't not use the API's so there needs to be a solution for this!
I have the same problem... did you find a solution? Thanks!
I cannot think of any solution other than reducing the number of methods/code that you're adding in via 3rd party libraries, or if that's not possible, run some sort of code stripping tool (e.g: ProGuard)
Answer by wpdev · May 01, 2015 at 04:09 AM
This usually happens when google google-play-services.jar included, and this is really large library. Couple of month ago google separated this lib on submodules and you can try to include only required. If this not solved the issue, then you have to export google project from unity and build apk on your own. If you have any errors that dont allow you to export project then simply remove some jars from plugin folder and export, after add them back in android studio through graddle. Now its possible to enable multidex support for android 4.0.+. However if you need to support android 2.3.+ then its very tricky. You will need to limit dex file size(file can be found inside apk) to about 5mb each to allow every low performance device to load it. Why? Because enabled multidex option cuts on 10mb dex files and this apk wont install on some 2.3 devices
Answer by $$anonymous$$ · Aug 08, 2017 at 06:26 PM
Check this post over at StackOverflow to learn how to enable multidex in Unity.