android - 使用 Google Play 服务时如何避免 65k 方法限制

标签 android google-play-services android-gradle-plugin dalvik dex

如果您发现自己正在编写一个依赖于许多不同库的大型 Android 应用程序(我建议您这样做而不是重新发明轮子),那么您很可能已经遇到了 65k method limit Dalvik 可执行文件 classes.dex。此外,如果您依赖大型库,例如 Google Play Services SDK,它本身已经包含 more than 20k methods in version 5.0你被迫use tricks like stripping packagesmultidex support以免打包时出错。使用 Android 的新运行时 ART这是公开可用的,因为 Android Lollipop 多个 dex 文件更容易处理,但目前开发人员仍然被迫进行方法计数。

在使用 Google Play 服务时减少应用程序方法数的最简单方法是什么?

最佳答案

6.5 release of the Google Play Services 为开发人员带来的最大变化可能是粒度依赖管理。 Google 设法拆分了它的库,以允许开发人员仅依赖于他们的应用程序真正需要的某些组件。

从 6.5 版开始,开发人员不再被迫在他们的应用中实现完整的 Google Play 服务库,而是可以有选择地依赖这样的组件:

compile 'com.google.android.gms:play-services-fitness:6.5.+'
compile 'com.google.android.gms:play-services-wearable:6.5.+'
compile 'com.gogole.android.gms:play-services-maps:6.5.+'
...

如果您想将完整的库编译到您的应用程序中,您仍然可以这样做:

compile 'com.google.android.gms:play-services:6.5.+'

可以找到可用软件包的完整列表 on the Android Developers site .

关于android - 使用 Google Play 服务时如何避免 65k 方法限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27589560/

相关文章:

android - 适配器作为演示者?还是与 Presenter 交谈? Android 和 MVP

真实设备中的 Android strace

android - 在Android中将触摸事件传递给父 View 的onTouchListener

android - 发布 Alpha 新 Android 游戏时如何将 "Link App"转换为现有客户端 ID 和生产 SHA1

java - 如果将 google-play-services.jar lib 添加到我在 Eclipse 中的 helloworld android 项目中,Android 编译会卡住

android - 项目升级到gradle后无法编译 :2. 1.0-alpha5

java - 膨胀 View 会在物理设备上抛出 Resources$NotFoundException

android - 我可以删除谷歌播放服务语言文件吗?

java - 如何使用 Gradle 抑制 "warning: Ignoring InnerClasses attribute for an anonymous inner class"?

android - 将 Android Studio 2.3.3 更新到 3.0 后无法合并 dex