热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何解决Dalvik编译器限制64K方法的问题?-HowtosolvetheissuewithDalvikcompilerlimitationon64Kmethods?

MyteamandIhaveinheritedalargeAndroidprojectfromanotherteam.Thewholeapplicationwitha

My team and I have inherited a large Android project from another team. The whole application with all the included libraries is reported to have around 35000 methods. We now have the task to implement a new service in the app where we need to use Protocol Buffers.

我的团队和我继承了另一个团队的大型Android项目。据报道,包含所有包含库的整个应用程序有大约35000种方法。我们现在的任务是在应用程序中实现我们需要使用Protocol Buffers的新服务。

The problem is that the generated .jar file with all the required .proto files creates another couple of 35000 methods, that's 70000 methods. And if you are not aware, the Android compiler has a limitation of 65536 methods per .dex file. We are clearly over that limit and we are getting the following error trying to compile the app:

问题是生成的.jar文件包含所有必需的.proto文件,会创建另外35000个方法,即70000个方法。如果您不知道,Android编译器每个.dex文件的限制为65536个方法。我们显然超过了这个限制,我们在尝试编译应用程序时遇到以下错误:

Unable to execute dex: method ID not in [0, 0xffff]: 65536
Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

Yes, the application architecture should probably be restructured but that will take time. And for now we are trying to figure out a solution to work around this problem temporarily.

是的,应用程序架构可能应该进行重组,但这需要时间。目前我们正试图找出解决方案来暂时解决这个问题。

Any suggestions?

7 个解决方案

#1


12  

You can use another DEX file. This is how you do it:

您可以使用其他DEX文件。这是你如何做到的:

http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html

#2


7  

Enable Proguard (http://developer.android.com/tools/help/proguard.html) to remove unused methods. The protobuf generator creates thousands of methods that are never actually used.

启用Proguard(http://developer.android.com/tools/help/proguard.html)以删除未使用的方法。 protobuf生成器创建了数千种从未实际使用过的方法。

Micro-protobuffers (https://code.google.com/p/micro-protobuf/) may also be useful.

微型protobuffers(https://code.google.com/p/micro-protobuf/)也可能有用。

#3


4  

Square had similar issues and they built Wire to deal with the method explosion caused by protobufs. They claim to have killed 10,000 methods.

Square有类似的问题,他们构建了Wire来处理protobufs引起的方法爆炸。他们声称杀死了10,000种方法。

#4


4  

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

在6.5之前的Google Play服务版本中,您必须将整个API包编译到您的应用中。在某些情况下,这样做会使您的应用程序中的方法数量(包括框架API,库方法和您自己的代码)在65,536限制下更加困难。

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

从6.5版开始,您可以选择性地将Google Play服务API编译到您的应用中。例如,要仅包含Google Fit和Android Wear API,请替换build.gradle文件中的以下行:

compile 'com.google.android.gms:play-services:6.5.87'

with these lines:

用这些线:

compile 'com.google.android.gms:play-services-fitness:6.5.87'
compile 'com.google.android.gms:play-services-wearable:6.5.87'

for more reference, you can click here

有关更多参考,请单击此处

#5


1  

If this is the first use of Protocol buffers, you could look at alternative JavaME implementations i.e.

如果这是第一次使用协议缓冲区,您可以查看备用JavaME实现,即

  • protobuf-javame
  • protobuf-j2me

there are others listed in Third party add ons. If have not used any of them, but they seem to be smaller and do not have all the methods created by the standard protocol buffers.

还有其他列在第三方添加。如果没有使用它们中的任何一个,但它们似乎更小并且没有标准协议缓冲区创建的所有方法。

#6


1  

We've recently added Nano Protobufs to Android which significantly reduces the number of methods generated.

我们最近在Android上添加了Nano Protobufs,大大减少了生成的方法数量。

#7


0  

If you are using eclipse this is the easiest work around Click Here!

如果您正在使用eclipse,这是最简单的解决方法Click Here!


推荐阅读
  • switch语句的一些用法及注意事项
    本文介绍了使用switch语句时的一些用法和注意事项,包括如何实现"fall through"、default语句的作用、在case语句中定义变量时可能出现的问题以及解决方法。同时也提到了C#严格控制switch分支不允许贯穿的规定。通过本文的介绍,读者可以更好地理解和使用switch语句。 ... [详细]
  • 本文介绍了在多平台下进行条件编译的必要性,以及具体的实现方法。通过示例代码展示了如何使用条件编译来实现不同平台的功能。最后总结了只要接口相同,不同平台下的编译运行结果也会相同。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文讨论了如何使用IF函数从基于有限输入列表的有限输出列表中获取输出,并提出了是否有更快/更有效的执行代码的方法。作者希望了解是否有办法缩短代码,并从自我开发的角度来看是否有更好的方法。提供的代码可以按原样工作,但作者想知道是否有更好的方法来执行这样的任务。 ... [详细]
  • (三)多表代码生成的实现方法
    本文介绍了一种实现多表代码生成的方法,使用了java代码和org.jeecg框架中的相关类和接口。通过设置主表配置,可以生成父子表的数据模型。 ... [详细]
  • Android系统源码分析Zygote和SystemServer启动过程详解
    本文详细解析了Android系统源码中Zygote和SystemServer的启动过程。首先介绍了系统framework层启动的内容,帮助理解四大组件的启动和管理过程。接着介绍了AMS、PMS等系统服务的作用和调用方式。然后详细分析了Zygote的启动过程,解释了Zygote在Android启动过程中的决定作用。最后通过时序图展示了整个过程。 ... [详细]
author-avatar
陈可1993_532
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有