Flutter amap_location高德定位插件无法编译 编译出错 Xlint:unchecked new AMapLocationClient报错爆红问题

出现原因:信息新规之后,高德被搞了之后更新了高德定位SDK的使用方式,导致最新版编译类出错。
详见官网:
报错内容:
E:\flutter\flutter.pub-cache\hosted\pub.flutter-io.cn\amap_location-0.2.0\android\src\main\java\com\jzoom\amaplocation\AmapLocationPlugin.java:227: ����: δ������쳣����Exception; ���������в���������Ա��׳�
locationClient = new AMapLocationClient(getApplicationContext());
^
ע: E:\flutter\flutter.pub-cache\hosted\pub.flutter-io.cn\amap_location-0.2.0\android\src\main\java\com\jzoom\amaplocation\AmapLocationPlugin.javaʹ����δ�����򲻰�ȫ�IJ�����
ע: �й���ϸ��Ϣ, ��ʹ�� -Xlint:unchecked ���±��롣
1 ������

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:amap_location:compileDebugJavaWithJavac’.

Compilation failed; see the compiler error output for details.

  • 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.

  • Get more help at https://help.gradle.org

BUILD FAILED in 12s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

在这里插入图片描述

解决方案:两种解决方案
第一种:

  1. 进入Flutter环境下,找到amap_location依赖,打开路径:【你的flutter安装磁盘】:\flutter.pub-cache\hosted\pub.flutter-io.cn\amap_location-0.2.0\android\src\main\java\com\jzoom\amaplocation的AmapLocationPlugin.java的文件。
  2. private boolean startup(Map arguments)的函数里,初始化AMapLocationClient高德定位服务类之前,加上官方示例的代码
 AMapLocationClient.updatePrivacyShow(getApplicationContext(),true,true);
 AMapLocationClient.updatePrivacyAgree(getApplicationContext(),true);

强制同意授权隐私协议接口。
附上官方说明及完整代码:在这里插入图片描述
高德官方链接:https://lbs.amap.com/api/android-location-sdk/guide/create-project/dev-attention#t1

完整代码:

  private boolean startup(Map arguments) {
        synchronized (this){
        		// 关键的两行代码 兼容最新版本
                AMapLocationClient.updatePrivacyShow(getApplicationContext(),true,true);
                AMapLocationClient.updatePrivacyAgree(getApplicationContext(),true);
                //初始化client
                locationClient = new AMapLocationClient(getApplicationContext());


                //设置定位参数
                AMapLocationClientOption option = new AMapLocationClientOption();
                parseOptions(option,arguments);
                locationClient.setLocationOption(option);

                //将option保存一下
                this.option = option;

                return true;
            }

            return false;
        }
    }

第二种解决方法:指定amap_location依赖的高德地图版本号为5.6.1以下。

  1. 打开amap_location依赖下的build.gradle文件。路径为:【你的flutter安装磁盘】:\flutter.pub-cache\hosted\pub.flutter-io.cn\amap_location-0.2.0\android
  2. 修改高德定位SDK版本号为5.6.1以下即可。

修改前:

dependencies {
    implementation 'com.amap.api:location:latest.integration'
}

修改后:

dependencies {
    implementation  'com.amap.api:location:4.7.0'
}

然后清除编译缓存,重新编译即可。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值