【问题标题】:Does "play-services:9.8.0" include "play-services-location:9.8.0"?“play-services:9.8.0”是否包括“play-services-location:9.8.0”?
【发布时间】:2017-03-30 16:30:57
【问题描述】:

我正在升级一个应用程序,在我的 build.gradle 文件中,我有这个:

dependencies {
    ..........
    compile 'com.google.android.gms:play-services:9.8.0'
    ..........
}

在 Urban Airship 提供的 Android SDK 设置快速入门指南中,他们将其作为示例代码提供:

dependencies {
    ..........
    // Recommended for location services
    compile 'com.google.android.gms:play-services-location:9.8.0'
    ..........
}

如果我使用“play-services:9.8.0”,我会假设它还包括“play-services-location:9.8.0”,因为“play-services-location:9.8.0”应该是“play-services:9.8.0”,但我想确认一下。你知道这是否是一个正确的假设吗?谢谢。

【问题讨论】:

  • 为什么不使用最新的:compile 'com.google.android.gms:play-services:10.2.1'
  • 当然,所以我的问题是,“编译'com.google.android.gms:play-services:10.2.1'”是否包括“编译'com.google.android.gms:play-服务位置:10.2.1'”?我的问题的目的不是关注特定版本,而只是确认导入“play-services”是否包括在导入“play-services-location”的情况下您还拥有的所有内容,假设“play-services -location”是“play-services”的子集,因为“play-services”是超集。
  • 最好使用最零散的库,以避免不需要的代码=)
  • 我知道,你是绝对正确的,但我只是想确认导入“play-services”是否会包括你使用“play-services-location”时所拥有的一切,但它看起来像答案是肯定的。

标签: android push-notification urbanairship.com


【解决方案1】:

来自 Google Api Documentation

你可以使用最新的谷歌播放服务api:

 dependencies {
    compile 'com.google.android.gms:play-services:10.2.1'
}

如果您的应用中的方法引用数量超过 65K 限制,您的应用可能无法编译。在编译应用时,您可以通过仅指定应用使用的特定 Google Play 服务 API 而不是全部来缓解此问题。

选择性地将 API 编译到您的可执行文件中:

 compile 'com.google.android.gms:play-services-maps:10.2.1'
compile 'com.google.android.gms:play-services-plus:10.2.1'
compile 'com.google.android.gms:play-services-location:10.2.1'
compile 'com.google.android.gms:play-services-games:10.2.1'
compile 'com.google.android.gms:play-services-gcm:10.2.1'

文档中提供了详细列表。

【讨论】:

  • 我明白了。实际上限制是 64K,而不是 65K,如 developer.android.com/studio/build/multidex.html 所述。
  • 我从 google api 文档中添加的..在我提供的链接上
  • 我正在阅读 developer.android.com/studio/build/multidex.html#avoid 的“避免 64K 限制”标题。 64K或65K,我明白了。谢谢你的回答。
  • 你是对的限制...Because 65,536 is equal to 64 X 1024, this limit is referred to as the '64K reference limit'..我不知道他们为什么把 65K 放在那里。
  • 是的,这是有道理的。
【解决方案2】:

是的,play-services 是完整的捆绑包。它们被分解以减少您的应用程序的方法计数,因此您不会点击the dex limit。更多信息可以找到here

【讨论】:

  • 我可以从您发送的参考资料 (developer.android.com/studio/build/multidex.html) 中看出您的意思:“一个常见的反模式是包含一个非常大的库,因为一些实用方法很有用。减少您的应用程序代码依赖项通常可以帮助您避免 DEX 引用限制。”
猜你喜欢
  • 2017-11-17
  • 2013-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多