如何彻底移除Android Studio项目外部库中的com.google.android.gms:play-services-ads-identifier:17.0.0@aar
彻底移除 com.google.android.gms:play-services-ads-identifier 的解决方案
1. 定位间接依赖来源
先通过Gradle命令找出是哪个第三方库间接引入了这个17.0.0版本的SDK:
在Android Studio终端执行(Mac/Linux):
./gradlew app:dependencies
Windows环境执行:
gradlew app:dependencies
在输出的依赖树中,找到包含com.google.android.gms:play-services-ads-identifier:17.0.0的节点,确认其依赖来源。
2. 添加全局排除规则
如果不想逐个排查依赖,可以在模块的build.gradle中添加全局排除配置,强制所有依赖都不引入该SDK:
configurations.all { exclude group: 'com.google.android.gms', module: 'play-services-ads-identifier' }
3. 清理Gradle缓存
残留的缓存可能导致依赖未被彻底移除,执行以下命令清理并重建项目:
Mac/Linux:
./gradlew clean build --refresh-dependencies
Windows:
gradlew clean build --refresh-dependencies
4. 清理Android Studio本地缓存
若上述步骤无效,手动清理IDE缓存:
- 点击菜单栏
File -> Invalidate Caches... - 勾选
Clear file system cache and local history,点击Invalidate and Restart
5. 验证移除结果
项目重启同步后,再次运行./gradlew app:dependencies检查输出,确认com.google.android.gms:play-services-ads-identifier已无任何引用;同时查看External Libraries目录,确认该SDK已被移除。
内容的提问来源于stack exchange,提问作者Lovely
相关产品推荐
相关产品推荐

