gpt4 book ai didi

android - Google maps API v2 使 APK 的大小比旧版本大

转载 作者:行者123 更新时间:2023-11-29 20:26:06 26 4
gpt4 key购买 nike

有一个应用程序使用 Google map API v2构建签名发布 APK 后,文件长度太大我构建“HelloWord”项目来测量长度并将 google_play_services_lib 添加到项目文件长度最多比“HelloWord”APK 多 2.2 Mb

SKD Manager 的存储库和 google play 服务也已更新。

我使用 Android Studio IDE (Gradle) 并导入所有 google-play-services。是否可以导入部分

最佳答案

假设您使用 AS 和 Gradle 作为构建脚本/依赖管理

要导入整个 Google Play 服务,您需要像这样使用依赖项:

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

其中包括所有服务资源和类,这是一个巨大的列表:

+--- com.google.android.gms:play-services:7.8.0
| +--- com.google.android.gms:play-services-ads:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0
| | | \--- com.android.support:support-v4:22.2.0 -> 22.2.1
| | | \--- com.android.support:support-annotations:22.2.1
| | +--- com.google.android.gms:play-services-analytics:7.8.0
| | | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| | \--- com.google.android.gms:play-services-appindexing:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-analytics:7.8.0 (*)
| +--- com.google.android.gms:play-services-appindexing:7.8.0 (*)
| +--- com.google.android.gms:play-services-appinvite:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-appstate:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-cast:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 (*)
| | \--- com.android.support:mediarouter-v7:22.2.0
| | \--- com.android.support:appcompat-v7:22.2.0
| | \--- com.android.support:support-v4:22.2.0 -> 22.2.1 (*)
| +--- com.google.android.gms:play-services-drive:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-fitness:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 (*)
| | \--- com.google.android.gms:play-services-location:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 (*)
| | \--- com.google.android.gms:play-services-maps:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-games:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 (*)
| | \--- com.google.android.gms:play-services-drive:7.8.0 (*)
| +--- com.google.android.gms:play-services-gcm:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-identity:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-location:7.8.0 (*)
| +--- com.google.android.gms:play-services-maps:7.8.0 (*)
| +--- com.google.android.gms:play-services-nearby:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-panorama:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-plus:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-safetynet:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-vision:7.8.0
| | \--- com.google.android.gms:play-services-base:7.8.0 (*)
| +--- com.google.android.gms:play-services-wallet:7.8.0
| | +--- com.google.android.gms:play-services-base:7.8.0 (*)
| | +--- com.google.android.gms:play-services-identity:7.8.0 (*)
| | \--- com.google.android.gms:play-services-maps:7.8.0 (*)
| \--- com.google.android.gms:play-services-wearable:7.8.0
| \--- com.google.android.gms:play-services-base:7.8.0 (*)

要缩小它,您有以下三种选择:

  • 仅添加您需要的一部分,例如。 com.google.android.gms:play-services-maps:7.8.0
  • 排除不需要的部分

像这样:

compile('com.google.android.gms:play-services:7.8.0') {
exclude module: 'play-services-fitness'
exclude module: 'play-services-games'
exclude module: 'play-services-wallet'
exclude module: 'play-services-safetynet'
exclude module: 'play-services-appinvite'
exclude module: 'play-services-wearable'
exclude module: 'play-services-cast'
}
  • 或使用 Proguard (minifyEnabled),它应该从生成的 APK 资源和类中删除未使用或引用的内容

关于android - Google maps API v2 使 APK 的大小比旧版本大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32547117/

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