安卓程序高德地图报错解决
本人是个编程爱好者,平时喜欢倒腾,去年自己做了一个家庭自用的家庭安全软件,打开后自动向指定邮箱发送自己的位置,软件启动有提示信息,里面集成了家庭成员的手机防盗网址和密码,输入密码后可以查看家庭重要信息等等。由于今年孩子换了一部手机于是更新软件,因为偷懒,防盗网址直接写在了软件里面,更新后编译直接报错!
家庭软件把QQ邮箱已发送文件夹当数据库存储信息,重要信息会加密保存
软件介绍如下图片
报错代码和内容
报错的代码:
implementation ("com.amap.api:location:latest.integration")
implementation ("com.amap.api:map2d:latest.integration")
implementation ("com.amap.api:search:latest.integration")
报错内容如下:
Task :app:checkDebugDuplicateClasses FAILED
Execution failed for task ‘:app:checkDebugDuplicateClasses’.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
Duplicate class com.amap.apis.utils.core.api.AMapUtilCoreApi found in modules location-6.4.5 (com.amap.api:location:6.4.5) and search-9.7.1 (com.amap.api:search:9.7.1)
Duplicate class com.amap.apis.utils.core.api.NetProxy found in modules location-6.4.5 (com.amap.api:location:6.4.5) and search-9.7.1 (com.amap.api:search:9.7.1)
- Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
还有如下:
Duplicate class com.amap.apis.utils.core.api.AMapUtilCoreApi found in modules location-6.4.5 (com.amap.api:location:6.4.5) and search-9.7.1 (com.amap.api:search:9.7.1)
Duplicate class com.amap.apis.utils.core.api.NetProxy found in modules location-6.4.5 (com.amap.api:location:6.4.5) and search-9.7.1 (com.amap.api:search:9.7.1)
Go to the documentation to learn how to Fix dependency resolution errors.
按报错信息我疯狂的在网上查找解决办法,方法试了很多,结果还是不断报错,真是急死人了!
后来冷静思考一下,既然2023.9月软件可以编译成功说明那时的高德的库是支持的,现在报错可能是升级了库的格式,那么我为何不指定那时的库呢?于是立即查找去年9月库的版本,在依赖中直接指定,编译成功,问题解决!
修改后的代码如下:
// 2D地图SDK
implementation ("com.amap.api:map2d:6.0.0")
// 定位SDK
implementation ("com.amap.api:location:6.4.3")
// 搜索SDK
implementation ("com.amap.api:search:9.4.0")
总结
对于地图类的库,大家引用时最好指定版本,防止库升级而带来不必要的麻烦!