上传CN1 Android构建至Google Play时出现警告,求解决方案
上传CN1 Android构建到Google Play的警告处理方案
收到的警告内容
上传构建时触发以下关键警告:
- Google Play服务使用的版本12.0.1低于15.0.0,存在已知安全漏洞,必须升级到更新的稳定版本
- Google Cloud Messaging(GCM)已被正式弃用,需要迁移至Firebase Cloud Messaging(FCM),后者是功能更完善的跨平台消息服务
当前项目依赖配置
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.appcompat:appcompat:1.0.0' compile 'com.google.android.gms:play-services-auth:12.0.1' compile 'com.google.android.gms:play-services-base:12.0.1' compile 'com.google.android.gms:play-services-analytics:12.0.1' compile 'com.google.android.gms:play-services-gcm:12.0.1' compile 'com.google.android.gms:play-services-location:12.0.1' compile 'com.google.android.gms:play-services-maps:12.0.1' compile 'com.google.android.gms:play-services-ads:12.0.1' implementation 'com.android.billingclient:billing:4.0.0' implementation 'androidx.multidex:multidex:1.0.3' implementation 'co.infinum:goldeneye:1.1.2'; }
具体修复步骤
1. 批量升级Google Play服务依赖
所有com.google.android.gms相关依赖版本停留在12.0.1,不仅有安全风险,还可能和其他新依赖冲突。建议统一升级到最新稳定版,同时把旧的compile指令替换为Android Gradle插件3.0+推荐的implementation:
// 定义统一版本号方便维护,可根据Google官方最新稳定版调整 def playServicesVersion = "20.1.0" implementation "com.google.android.gms:play-services-auth:$playServicesVersion" implementation "com.google.android.gms:play-services-base:$playServicesVersion" implementation "com.google.android.gms:play-services-analytics:$playServicesVersion" implementation "com.google.android.gms:play-services-location:$playServicesVersion" implementation "com.google.android.gms:play-services-maps:$playServicesVersion" implementation "com.google.android.gms:play-services-ads:$playServicesVersion"
2. 移除GCM依赖,迁移到FCM
GCM已彻底弃用,必须替换为FCM:
- 删除依赖里的
compile 'com.google.android.gms:play-services-gcm:12.0.1' - 添加FCM依赖:
implementation 'com.google.firebase:firebase-messaging:23.4.0'
- 在项目根目录的
build.gradle中添加Google服务插件:
buildscript { dependencies { classpath 'com.google.gms:google-services:4.4.1' } }
- 在app模块的
build.gradle末尾加上插件引用:
apply plugin: 'com.google.gms.google-services'
3. 升级其他过时的AndroidX依赖
androidx.appcompat:appcompat:1.0.0版本过旧,建议升级到最新稳定版(如1.6.1)androidx.legacy:legacy-support-v4:1.0.0属于旧兼容库,若项目无需支持过旧Android版本,可替换为更轻量化的AndroidX组件;若必须保留,也建议升级到同系列最新版本
4. 验证依赖无冲突
执行Gradle命令检查依赖树,确保没有版本冲突或残留的过时依赖:
# Mac/Linux ./gradlew app:dependencies # Windows gradlew.bat app:dependencies
内容的提问来源于stack exchange,提问作者Daniel Tsai
相关产品推荐
相关产品推荐

