引言:
使用百度地圖Flutter SDK确虱,報(bào)錯(cuò):
BDMapSDKException: you have not supplyed the global app context info from SDKInitializer.initialize(Context) function.
詳細(xì):
百度地圖剛發(fā)布了Flutter版的SDK含友,正巧趕上之前引用的那個(gè)第三方插件的iOS版本有點(diǎn)問題校辩,考慮到以后維護(hù)升級,所以就換成百度官方的Flutter SDK了宜咒。
按官方的文檔說明換好之后故黑,一直都報(bào)錯(cuò)儿咱,報(bào)錯(cuò)日志如下:
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)
反復(fù)比對了自己的項(xiàng)目跟Demo項(xiàng)目有什么區(qū)別,都沒找出問題的所在。愁得啊使套。。侦高。
解決辦法
最后找到了原來百度SDK是在這里面做了初始化:
所以就像注釋里寫的那樣,要么直接繼承奉呛,要么把代碼拷到你自己的onCreate里计螺。
因?yàn)槲矣凶约旱倪壿嬊谱常园汛a拷到我的onCreate里了登馒。
import是
import com.baidu.mapapi.SDKInitializer;
import com.baidu.flutter_bmfbase.BmfContextHelper;
以上咆槽,分享陈轿。