引言:
使用百度地图Flutter SDK,报错:
BDMapSDKException: you have not supplyed the global app context info from SDKInitializer.initialize(Context) function.
详细:
百度地图刚发布了Flutter版的SDK,正巧赶上之前引用的那个第三方插件的iOS版本有点问题,考虑到以后维护升级,所以就换成百度官方的Flutter SDK了。
按官方的文档说明换好之后,一直都报错,报错日志如下:
E/flutter ( 9221): [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(39)] java.lang.ExceptionInInitializerError
E/flutter ( 9221): at com.baidu.mapsdkplatform.comapi.map.m.a(Unknown Source:0)
E/flutter ( 9221): at com.baidu.mapapi.map.MapView.a(Unknown Source:2)
E/flutter ( 9221): at com.baidu.mapapi.map.MapView.<init>(Unknown Source:20)
E/flutter ( 9221): at com.baidu.flutter_bmfmap.map.FlutterMapView.init(FlutterMapView.java:72)
E/flutter ( 9221): at com.baidu.flutter_bmfmap.map.FlutterMapView.<init>(FlutterMapView.java:64)
E/flutter ( 9221): at com.baidu.flutter_bmfmap.MapViewFactory.create(MapViewFactory.java:38)
E/flutter ( 9221): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:179)
E/flutter ( 9221): at android.app.Dialog.dispatchOnCreate(Dialog.java:411)
E/flutter ( 9221): at android.app.Dialog.show(Dialog.java:304)
E/flutter ( 9221): at android.app.Presentation.show(Presentation.java:249)
E/flutter ( 9221): at io.flutter.plugin.platform.VirtualDisplayController.<init>(VirtualDisplayController.java:93)
E/flutter ( 9221): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:46)
E/flutter ( 9221): at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:112)
E/flutter ( 9221): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:95)
E/flutter ( 9221): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/flutter ( 9221): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/flutter ( 9221): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter ( 9221): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/flutter ( 9221): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 9221): at android.os.MessageQueue.next(MessageQueue.java:325)
E/flutter ( 9221): at android.os.Looper.loop(Looper.java:145)
E/flutter ( 9221): at android.app.ActivityThread.main(ActivityThread.java:7145)
E/flutter ( 9221): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 9221): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/flutter ( 9221): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:820)
E/flutter ( 9221): Caused by: java.lang.IllegalStateException: BDMapSDKException: you have not supplyed the global app context info from SDKInitializer.initialize(Context) function.
E/flutter ( 9221): at com.baidu.mapsdkplatform.comapi.a.e(Unknown Source:9)
E/flutter ( 9221): at com.baidu.mapapi.BMapManager.getContext(Unknown Source:4)
E/flutter ( 9221): at com.baidu.mapsdkplatform.comapi.map.m.<clinit>(Unknown Source:0)
E/flutter ( 9221): ... 25 more
E/flutter ( 9221):
F/flutter ( 9221): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(76)] Check failed: CheckException(env).
F/libc ( 9221): Fatal signal 6 (SIGABRT), code -6 in tid 9221 (ness.lkcustomer), pid 9221 (ness.lkcustomer)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'SMARTISAN/trident/trident:8.1.0/OPM1.171019.026/1595820511:user/dev-keys'
Revision: '0'
ABI: 'arm64'
pid: 9221, tid: 9221, name: ness.lkcustomer >>> package <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: '[FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(76)] Check failed: CheckException(env).
'
x0 0000000000000000 x1 0000000000002405 x2 0000000000000006 x3 0000000000000008
x4 0000000000000080 x5 0000000000000080 x6 0000000000000080 x7 8000000000000000
x8 0000000000000083 x9 e189aa2805f73f80 x10 0000000000000000 x11 0000000000000001
x12 ffffffffffffffff x13 0000000000000000 x14 0000000000000000 x15 e189aa2805f73f80
x16 0000005a8aa88fa8 x17 0000007d5d786a04 x18 0000000013370590 x19 0000000000002405
x20 0000000000002405 x21 0000007fea415d38 x22 0000007ca872b870 x23 0000007cb6c11658
x24 000000000000002d x25 0000007fea415fd8 x26 0000000000000000 x27 0000000000000001
x28 000000000000002d x29 0000007fea415d20 x30 0000007d5d73c108
sp 0000007fea415ce0 pc 0000007d5d73c124 pstate 0000000060000000
backtrace:
#00 pc 000000000001e124 /system/lib64/libc.so (abort+104)
#01 pc 00000000012961c8 /data/app/package-flgYYcarxmsvlEACehx3tQ==/lib/arm64/libflutter.so (offset 0x1280000)
#02 pc 0000000001287134 /data/app/package-flgYYcarxmsvlEACehx3tQ==/lib/arm64/libflutter.so (offset 0x1280000)
#03 pc 000000000128560c /data/app/package-flgYYcarxmsvlEACehx3tQ==/lib/arm64/libflutter.so (offset 0x1280000)
#04 pc 00000000012d3da8 /data/app/package-flgYYcarxmsvlEACehx3tQ==/lib/arm64/libflutter.so (offset 0x1280000)
#05 pc 0000000001296acc /data/app/package-flgYYcarxmsvlEACehx3tQ==/lib/arm64/libflutter.so (offset 0x1280000)
#06 pc 000000000129b774 /data/app/package-flgYYcarxmsvlEACehx3tQ==/lib/arm64/libflutter.so (offset 0x1280000)
#07 pc 00000000000160d0 /system/lib64/libutils.so (android::Looper::pollInner(int)+856)
#08 pc 0000000000015cf0 /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+108)
#09 pc 0000000000113e54 /system/lib64/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int)+44)
#10 pc 000000000084c0fc /system/framework/arm64/boot-framework.oat (offset 0x650000) (android.app.NativeActivity.onWindowFocusChangedNative [DEDUPED]+140)
#11 pc 000000000000b318 /dev/ashmem/dalvik-jit-code-cache (deleted)
反复比对了自己的项目跟Demo项目有什么区别,都没找出问题的所在。愁得啊。。。
解决办法
最后找到了原来百度SDK是在这里面做了初始化:
所以就像注释里写的那样,要么直接继承,要么把代码拷到你自己的onCreate里。
因为我有自己的逻辑,所以把代码拷到我的onCreate里了。
import是
import com.baidu.mapapi.SDKInitializer;
import com.baidu.flutter_bmfbase.BmfContextHelper;
以上,分享。