Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Too many field references max is 65536 / Build-in class shrinker and multidex are not supported yet / there were duplicate class definitions

Environment

OS

Edition : Windows 10 Pro Version : 1709 OS Build : 16299.192

Unity

2017.3.0f3 Personal

Play Games Plugin For Unity

GooglePlayGamesPlugin-0.9.50.unitypackage

Facebook Unity

facebook-unity-sdk-7.11.0.unitypackage

Problems

A. Too many field references max is 65536

https://stackoverflow.com/questions/42582850/too-many-field-references-70613-max-is-65536

by Programmer

B. Build-in class shrinker and multidex are not supported yet

https://stackoverflow.com/questions/35627985/errorbuild-in-class-shrinker-and-multidex-are-not-supported-yet

by Ugurcan Yildirim

C. there were duplicate class definitions

https://answers.unity.com/questions/1397172/gradle-build-errors.html

by nanotribegmbh

How to resolve them

Problem A. Too many field references max is 65536

1. In Unity, switch build system to Gradle

[File] -> [Build Settings]

In the [Build Settings] dialogue

  • make sure you [Switch Platform]ed to [Android]
  • change [Build System] from [Internal] (most cases) to [Gradle]

let Unity do the rest job if it has some.

2. Custom Android manifest

Copy

<UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk\AndroidManifest.xml

to

<ProjectName>Assets\Plugins\Android\

Edit AndroidManifest.xml you just copied

Add

android:name="android.support.multidex.MultiDexApplication"

to the [application] tag.

3. Custom gradle build script

Copy

<UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates\mainTemplate.gradle

to

<ProjectName>Assets\Plugins\Android\

Make sure that in Unity

[Edit] -> [Project Settings] -> [Player] -> [Android Robot Tab] -> [Publishing Settings] -> [Build]

  • [Build System] is set to [Gradle]
  • [Custom Gradle Template] is checked and the file path is the one you just copied

Add

compile 'com.android.support:multidex:1.0.1'

to the [dependencies] block.

Add

multiDexEnabled true

to the [android] -> [defaultConfig] block.

Build and see if it works for you.

Problem B. Build-in class shrinker and multidex are not supported yet

Continue with the last step

Remove

useProguard **PROGUARD_DEBUG**

from the [android] -> [buildTypes] -> [debug] block.

Remove

useProguard **PROGUARD_RELEASE**

from the [android] -> [buildTypes] -> [release] block.

Build and see if it works for you.

Problem C. there were duplicate class definitions

In Unity, [Edit] -> [Project Settings] -> [Player] -> [Android Robot Tab] -> [Publishing Settings] -> [Build]

check [User Proguard File]

Edit the generated proguard file

Add

-dontwarn whatever.is.listed.in.the.warnings

Build and see if it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment