Too Many Field References: 70613; Max Is 65536

Too many field references: 70613; max is 65536


So What should i do to decrease reference count ?

You have so many plugins with many functions/fields. There is a limit when building this from Unity's Editor and you have reached that limit.

To decrease reference count, you have to delete some these plugins but I am sure that you need them and deletion may not be the appropriate solution in this case.

The only way to actually get around this and build for Android at this moment is to export the Project as Android Project then build it with Android Studio. This removes the reference limit imposed by Unity's Editor.


EDIT

I forgot to mention that you have to enable multidex after exporting it out. Since many people go through this problem daily, I decided to add a thorough instruction on how to fix this problem by exporting it out and also how to fix it without exporting it.

FIX BY EXPORTING THE PROJECT

1A.Export the Unity Project as Android Project.

Sample Image

1B.Import into Android Studio:

Sample Image

If you get grade error when importing into Android Studio like the one below:

Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection
cannot be cast to
org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection

Sample Image

In the "dependencies" block which is in the "buildscript" block in the build.gradle file, change:

classpath 'com.android.tools.build.gradle.2.1.0'

to

classpath 'com.android.tools.build:gradle:2.2.3'

Sample Image


If you export the Project and still get the-same error, you need to manually enable multidex. Below is a simplified step to follow from Google's doc that will be shown to you in the error:

2.Add android:name="android.support.multidex.MultiDexApplication" > to the
application tag in the AndroidManifest.xml file.

Sample Image


3.Add compile 'com.android.support:multidex:1.0.1' to the "dependencies" block in the build.gradle file.

Sample Image


4.Add multiDexEnabled true to the "defaultConfig" block which is in the "android" block in the build.gradle file.

Sample Image

Build APK and see if it works. If the reference count error is gone, stop here.


5.Getting a GC overhead exception like the one below?

java.lang.OutOfMemoryError: GC overhead limit exceeded

Increase the heap size that will be used when performing dex operation. From this solution, add the following to the "android" block in the build.gradle file:

dexOptions {
javaMaxHeapSize "4g"
}

Sample Image

FIX WITHOUT EXPORTING THE PROJECT

Must have Unity 5.5 and above to do this:

1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates, Copy the mainTemplate.gradle file to your <ProjectName>Assets\Plugins\Android folder.


2.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Apk, Copy the AndroidManifest.xml file to your <ProjectName>Assets\Plugins\Android


3.Open both the mainTemplate.gradle and AndroidManifest.xml file you just copied with Visual Studio then do the modification from the FIX BY EXPORTING THE PROJECT instruction above. Skip/Ignore step #1A and #1B. Just do steps from #2 to #5. That's it.

This is what the final mainTemplate.gradle should look like and this is what the final AndroidManifest.xml should look like. This is only for reference purposes. I suggest you don't use mine but instead follow the copy steps above to create yours because future Unity versions can come with different files. You want to make sure you use the latest one or you may have problems building it.


4.Build APK and see if it works:

Sample Image

--

If the reference count error is gone, stop here:

5.Getting an error like the one below?

Build Failure Release builds have to be signed when using Gradle

Just sign the apk from the Publishing Settings in the Build Settings. You can create new keystore or use an existing one.

Sample Image


6.Another error like below?

Error: Avoid hardcoding the debug mode; leaving it out allows debug
and release builds to automatically assign one [HardcodedDebugMode]

Remove android:debuggable="true"> from the AndroidManifest.xml file.


If this non exporting solution did not work for you then you have to
use the exporting solution.

trouble writing output: Too many methods: 66024; max is 65536. By package: ERROR

Your problem is caused by trying to put too much code into an Android app. According to this Q&A - Android: my application is too large and gives "Unable to execute dex: method ID not in [0, 0xffff]: 65536"? - the solution is to refactor your app so that some of the code is in the form of plugins.

Another approach is to try to eliminate dead code (i.e. library classes and methods that your app doesn't need). This Q&A - Android Error "Conversion to Dalvik format failed with error 2"? - suggests using Proguard to do this.

Getting multidesx issue in Unity Android project after adding Google Play services

How to resolve this?

No, you cant resolve this in Unity. 

And enable multidex in Unity project?

There is workaround to export your project in Android Studio and enable multidex options there.

android {
defaultConfig {
...
...
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}

Also add this line in your AndroidManifest.xml inside tag.

<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>

For detail explanation you can visit this link.
https://medium.com/@narendrapal39/multidex-unity-android-a5ab48b1704e



Related Topics



Leave a reply



Submit