RSS Feed

Troubles with Abstraction

November 15, 2017

Goblin Defence is the largest Unity3D game I have ported from iOS to Android so far. When I tried to build I received the following error:

 

Dex limit error: Too many field references: 67000; max is 65536

 

Good old Google helped me find three options:

 

  1. Delete unnecessary jar/aar library files to reduce the number of references

  2. Move to Gradle builds and enable Proguard to remove unused code and references

  3. Move to Gradle and allow multidex to overcome the reference number limitation

I spent a busy few days cycling between the options trying to find one that worked. Missing libraries can go undetected. Also, an aar file is a collection of jar files - further complicating the issue. 

 

Implementing Gradle/Proguard was not as easy as changing drop-downs in Unity Build and Player Settings. Proguard warnings become Gradle errors and Unity fails the build. There is a parameter to ignore all warnings. It is not a good idea as Unity uses a lot of reflection. Proguard can't see classes only accessed by name at runtime.

 

Multidex is limited to Android 4 and up. I can live with that. After much fiddling around I managed to get a Gradle build that worked. The only problem was that it did not produce an APK file.

 

Eventually, I replicated a full build using an exported project and executed a command-line Gradle build. The most significant problem was in using SDK and Gradle version that matches those that come with Unity.

 

It turns out that one of my attempts using Android Studio created ~/.gradle/init.gradle and moved the build directory. Consequently, Unity could not find the file.

 

By the time you read this you will be able to play Goblin Defence on Android or iOS. Give it a go if you like tower defence games.

 

 

Share on Facebook
Share on Twitter
Please reload

Featured Posts

My limited tests show that Dictionary is faster than `SortedList`. The latter uses `Array.BinarySearch` to find entries. I have read other performance...

How are C# Dictionaries so Fast?

August 27, 2018

1/5
Please reload

Recent Posts

April 12, 2018

Please reload

Archive
Please reload

Search By Tags
Please reload

Follow Us
  • Facebook Basic Square