gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:38 24 4
gpt4 key购买 nike

如果您发现自己正在编写一个依赖于许多不同库的大型 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com