出现原因:信息新规之后,高德被搞了之后更新了高德定位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)
解决方案:两种解决方案
第一种:
- 进入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的文件。
- 在
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以下。
- 打开amap_location依赖下的build.gradle文件。路径为:【你的flutter安装磁盘】:\flutter.pub-cache\hosted\pub.flutter-io.cn\amap_location-0.2.0\android
- 修改高德定位SDK版本号为5.6.1以下即可。
修改前:
dependencies {
implementation 'com.amap.api:location:latest.integration'
}
修改后:
dependencies {
implementation 'com.amap.api:location:4.7.0'
}
然后清除编译缓存,重新编译即可。