字段引用过多:70613;最大值为 65536 [英] Too many field references: 70613; max is 65536

查看:38
本文介绍了字段引用过多:70613;最大值为 65536的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用这些插件:

  • OneSignal
  • GooglePlay 服务
  • 调整
  • 谷歌分析
  • Unity IAP
  • Facebook SDK

这些插件几乎用在每个项目中.

但是我超过了字段引用计数

这是我的 .aar 文件列表

我应该怎么做才能减少引用计数?

解决方案

那么我应该怎么做才能减少引用计数?

你有这么多功能/领域的插件.从 Unity 的编辑器构建它时存在限制,并且您已达到该限制.

要减少引用计数,您必须删除一些这些插件,但我确信您需要它们,在这种情况下,删除可能不是合适的解决方案.

目前真正解决这个问题并为 Android 构建的唯一方法是

1B.导入到 Android Studio:

如果您在导入 Android Studio 时遇到如下所示的成绩错误:

<块引用>

错误:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection不能投射到org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection

build.gradle 文件的buildscript"块中的dependencies"块中,更改:

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

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

<小时>

如果导出项目还是出现同样的错误,则需要手动启用multidex.以下是 Google 的

<小时>

3.将 compile 'com.android.support:multidex:1.0.1' 添加到 dependencies" 块中的 build.gradle 文件.

<小时>

4.将 multiDexEnabled true 添加到 defaultConfig" 块中,该块位于 构建中的android"块中.gradle 文件.

构建 APK 并查看它是否有效.如果引用计数错误消失了,就到此为止.

<小时>

5. 是否会出现如下所示的 GC 开销异常?

<块引用>

java.lang.OutOfMemoryError:超出 GC 开销限制

增加执行 dex 操作时将使用的堆大小.从此

无需导出项目即可修复

必须有 Unity 5.5 及更高版本才能执行此操作:

1.转到EditorDataPlaybackEnginesAndroidPlayerToolsGradleTemplates,复制mainTemplate.gradle文件到您的 AssetsPluginsAndroid 文件夹.

<小时>

2.转到EditorDataPlaybackEnginesAndroidPlayerApk,将AndroidManifest.xml文件复制到你的 AssetsPluginsAndroid

<小时>

3.打开您刚刚使用 Visual Studio 复制的 mainTemplate.gradleAndroidManifest.xml 文件,然后从 <强>通过导出项目修复 上面的说明.跳过/忽略步骤 #1A#1B.只需执行从 #2#5 的步骤即可.而已.

--

如果引用计数错误消失了,就停在这里:

5. 遇到如下错误?

<块引用>

使用 Gradle 时必须对构建失败发布构建进行签名

只需

<小时>

6.还有如下错误?

<块引用>

错误:避免硬编码调试模式;省略它允许调试并发布构建以自动分配一个 [HardcodedDebugMode]

AndroidManifest.xml 文件中删除 android:debuggable="true">.

<小时>

如果此非导出解决方案对您不起作用,那么您必须使用导出解决方案.

My project uses these plugins:

  • OneSignal
  • GooglePlayServices
  • Adjust
  • Google Analytics
  • Unity IAP
  • Facebook SDK

Those plugins are used in almost every project.

But I am over field references count

This is my .aar file list

What should I do to decrease reference count?

解决方案

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.

1B.Import into Android Studio:

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

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'


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.


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


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

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"
}

FIX WITHOUT EXPORTING THE PROJECT

Must have Unity 5.5 and above to do this:

1.Go to <UnityInstallationDirecory>EditorDataPlaybackEnginesAndroidPlayerToolsGradleTemplates, Copy the mainTemplate.gradle file to your <ProjectName>AssetsPluginsAndroid folder.


2.Go to <UnityInstallationDirecory>EditorDataPlaybackEnginesAndroidPlayerApk, Copy the AndroidManifest.xml file to your <ProjectName>AssetsPluginsAndroid


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:

--

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.


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.

这篇关于字段引用过多:70613;最大值为 65536的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆