本文介绍了"麻烦的写输出:太多的字段引用:70185;最大值为65536.您可以尝试使用--multi-dex选项.在构建Android项目时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个错误,但没有找到错误消息,因此,我想与大家分享我想出的解决方案,以免其他人遇到重复我的工作时遇到的问题.

I hit this error and found no hits for the error message, so I thought I'd share the solution I came up with to save anyone else facing the problem repeating my work.

编写用于(大型)应用程序的新Android库(apklib)时,在将新项目添加为依赖项时,在dexing过程中出现以下错误:

When writing a new Android library (apklib) for use in a (large) application, I'm getting the following error during dexing when I add my new project as a dependency:

其失败的特定构建步骤是:

The particular build step it fails on is:

java -jar $ANDROID_SDK/build-tools/19.0.3/lib/dx.jar --dex \
--output=$PROJECT_HOME/target/classes.dex \
<... long list of apklib and jar dependencies elided ...>

按照错误消息的建议使用--multi-dex可能是一种解决方案,但是我不是应用程序项目的所有者,并且它已经具有庞大的复杂构建过程,无论如何我都会不敢更改.

Using --multi-dex as recommended by the error message might be a solution, but I'm not the owner of the application project and it already has a large complex build process that I would hesitate to change regardless.

我可以使用没有字段的无操作测试库项目来重现此问题,但是在错误输出中,它被列为具有6000多个字段.在错误输出中列出的程序包中,有少数具有相似的6k +字段计数,但随后绝大多数的< 1k字段计数似乎更合理.

I can reproduce this problem with a no-op test library project that has literally no fields, but in the error output it's listed as having 6000+ fields. Of the packages listed in the error output, there are a handful with similar 6k+ field counts, but then the vast majority have more plausible <1k field counts.

此问题类似于 Facebook著名地黑客入侵了. FB解决方案似乎很疯狂,而且是我找到的唯一其他解决方案(例如,此Android错误凭单或此 a>,此SO答案这个其他答案)都涉及更改主应用程序的代码,这超出了我想做的范围.

This problem is similar to the "Too many methods" problem that Facebook famously hacked their way around. The FB solution seems insane, and the only other solutions I've found (e.g., this Android bug ticket, or this one, this SO answer, this other SO answer) all involve changing the main app's code which is well beyond the scope of what I want to do.

还有其他解决方法吗?

推荐答案

解决方案是更改 package ,以匹配主应用程序的包.

The solution was to change the package in the AndroidManifest to match the main application's package.

这样的清单:

<manifest package="com.example.testlibrary" ...

导致6k +个字段,并且构建失败.对其进行更改以匹配主应用程序的程序包

resulted in 6k+ fields and build failure. Changing it to match the main application's package

<manifest package="com.example.mainapplication" ...

成功完成了项目建设.

请注意,清单中的软件包仅在更改,我没有对库的Java源代码或其布局进行任何更改(Java软件包仍为com.example.testlibrary,具有匹配的目录结构).

Note that only the package in the manifest is changing, I did not make any changes to the library's Java source or its layout (the Java package was still com.example.testlibrary with directory structure to match).

我假设不同的程序包名称导致所有Android字段再次包含在该程序包下.错误列表中具有6k +字段的所有软件包的软件包名称都与主应用程序不同.

I hypothesize that the different package name is causing all the Android fields to be included again under that package. All the packages in the error listing with 6k+ fields had a different package name than the main application.

我也(后来,grr)发现了此博客文章,其中详细介绍了相同的问题以及最终的解决方案.

I also (later, grr), found this blog post which details the same problem and the eventual same solution.

这篇关于&quot;麻烦的写输出:太多的字段引用:70185;最大值为65536.您可以尝试使用--multi-dex选项.在构建Android项目时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:59
查看更多