HMS-Core / hms-flutter-plugin

This repo contains all of Flutter HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
289 stars 147 forks source link

Huawei map does not work first time it builds #30

Closed realvotum closed 4 years ago

realvotum commented 4 years ago

Hello,

I have an issue with the huawei_map plugin. It doest not work the first time it builds. When I fire it second and more times, it builds and shows successfully. There is an exception I have in my logs for the first time it builds a map:

E/flutter ( 1095): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. E/flutter ( 1095): at android.view.ViewGroup.addViewInner(ViewGroup.java:5326) E/flutter ( 1095): at android.view.ViewGroup.addView(ViewGroup.java:5155) E/flutter ( 1095): at android.view.ViewGroup.addView(ViewGroup.java:5127) E/flutter ( 1095): at com.huawei.map.utils.i0.p(Unknown Source:22) E/flutter ( 1095): at com.huawei.map.utils.i0.a(Unknown Source:126) E/flutter ( 1095): at com.huawei.map.utils.i0.s(Unknown Source:12) E/flutter ( 1095): at com.huawei.map.utils.i0.a(Unknown Source:74) E/flutter ( 1095): at com.huawei.map.mapapi.MapView.onCreate(Unknown Source:6) E/flutter ( 1095): at com.huawei.hms.maps.provider.huawei.MapViewImpl.onCreate(Unknown Source:16) E/flutter ( 1095): at com.huawei.hms.maps.internal.mak$maa.onTransact(Unknown Source:177) E/flutter ( 1095): at android.os.Binder.transact(Binder.java:921) E/flutter ( 1095): at com.huawei.hms.maps.internal.IMapViewDelegate$Stub$Proxy.onCreate(IMapViewDelegate.java:248) E/flutter ( 1095): at com.huawei.hms.maps.MapView$MapViewLifecycleDelegate.onCreate(MapView.java:314) E/flutter ( 1095): at com.huawei.hms.feature.dynamic.DeferredLifecycleHelper$3.a(Unknown Source:11) E/flutter ( 1095): at com.huawei.hms.feature.dynamic.DeferredLifecycleHelper.a(Unknown Source:4) E/flutter ( 1095): at com.huawei.hms.feature.dynamic.DeferredLifecycleHelper.onCreate(Unknown Source:5) E/flutter ( 1095): at com.huawei.hms.maps.MapView.onCreate(MapView.java:113) E/flutter ( 1095): at com.huawei.hms.flutter.map.map.MapController.onCreate(MapController.java:450) E/flutter ( 1095): at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36) E/flutter ( 1095): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:361) E/flutter ( 1095): at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:188) E/flutter ( 1095): at com.huawei.hms.flutter.map.map.MapController.init(MapController.java:154) E/flutter ( 1095): at com.huawei.hms.flutter.map.map.MapBuilder.build(MapBuilder.java:72) E/flutter ( 1095): at com.huawei.hms.flutter.map.map.MapFactory.create(MapFactory.java:87) E/flutter ( 1095): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(SingleViewPresentation.java:186) E/flutter ( 1095): at android.app.Dialog.dispatchOnCreate(Dialog.java:635) E/flutter ( 1095): at android.app.Dialog.show(Dialog.java:420) E/flutter ( 1095): at android.app.Presentation.show(Presentation.java:250) E/flutter ( 1095): at io.flutter.plugin.platform.VirtualDisplayController.(VirtualDisplayController.java:95) E/flutter ( 1095): at io.flutter.plugin.platform.VirtualDisplayController.create(VirtualDisplayController.java:48) E/flutter ( 1095): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:214) E/flutter ( 1095): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:104) E/flutter ( 1095): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59) E/flutter ( 1095): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) E/flutter ( 1095): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/flutter ( 1095): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) E/flutter ( 1095): at android.os.MessageQueue.nativePollOnce(Native Method) E/flutter ( 1095): at android.os.MessageQueue.next(MessageQueue.java:363) E/flutter ( 1095): at android.os.Looper.loop(Looper.java:176) E/flutter ( 1095): at android.app.ActivityThread.main(ActivityThread.java:8349) E/flutter ( 1095): at java.lang.reflect.Method.invoke(Native Method) E/flutter ( 1095): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) E/flutter ( 1095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) E/flutter ( 1095): , null, null) E/flutter ( 1095): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7) E/flutter ( 1095): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18) E/flutter ( 1095): E/flutter ( 1095): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12) E/flutter ( 1095): #3 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1039:54) E/flutter ( 1095): #4 AndroidViewController.create (package:flutter/src/services/platform_views.dart:749:11) E/flutter ( 1095): #5 TextureAndroidViewController.create (package:flutter/src/services/platfo I/SecurityComp115301: er( 1095): ssf update socket factory trust manager I/SecurityComp115301: et( 1095): sasf update socket factory trust manager I/SecurityComp115301: miz( 1095): a c de begin 4 I/SecurityComp115301: miz( 1095): a c de begin 5 I/SecurityComp115301: mjm( 1095): update bks I/SecurityComp115301: mjl( 1095): createSocket I/SecurityComp115301: mjl( 1095): set default protocols I/SecurityComp115301: mjl( 1095): set default cipher suites I/SecurityComp115301: mjl( 1095): ssf update socket factory trust manager I/SecurityComp115301: mjk( 1095): sasf update socket factory trust manager I/NetworkKit_DnsUtil( 1095): RxCachedThreadScheduler-1|null|com.huawei.hms.framework.network.restclient.hwhttp.dns.mae|a|39|dns resolve source is:4 I/NetworkKit_DNResolverManager( 1095): RxCachedThreadScheduler-1|null|com.huawei.hms.framework.network.restclient.hwhttp.dns.dnresolver.mac|a|34|enter Dns lazy update flow, domain: map-dre.platform.hicloud.com, trigger type: dns_lazy_update I/SecurityComp115301: mjl( 1095): createSocket I/SecurityComp115301: mjl( 1095): set default protocols I/SecurityComp115301: mjl( 1095): set default cipher suites I/SecurityComp115301: mjn( 1095): checkServerTrusted begin ,server ca chain size is : 2 I/SecurityComp115301: mjn( 1095): check server i : 0 I/SecurityComp115301: mjn( 1095): client root ca size is : 31 I/SecurityComp115301: mjn( 1095): checkServerTrusted begin ,server ca chain size is : 2 I/SecurityComp115301: mjn( 1095): check server i : 0 I/SecurityComp115301: mjn( 1095): client root ca size is : 31 I/HmsMapKit_TileClient_69( 1095): query map data version success. httpCode : 200 I/NetworkKit_HianalyticsHelper( 1095): RxCachedThreadScheduler-2 -->NetworkKit_report_ha_0|null|com.huawei.hms.framework.common.hianalytics.HianalyticsHelper|isEnableReportNoSeed|9|user experience involved needs to be opened I/NetworkKit_DefaultRCEventListener( 1095): RxCachedThreadScheduler-2 -->NetworkKit_report_ha_0|null|com.huawei.hms.framework.network.restclient.hianalytics.mac|a|22|HianalyticsHelper report disable I/HmsMapKit_TileCache_73( 1095): get data version success. tileVersion : 20200904 D/HmsMapKit_TileCache_22( 1095): tileVersionCallable unSubscribe D/HmsMapKit_BaseRequestClient_36( 1095): response code : 400 I/NetworkKit_HianalyticsHelper( 1095): RxCachedThreadScheduler-1 -->NetworkKit_report_ha_0|null|com.huawei.hms.framework.common.hianalytics.HianalyticsHelper|isEnableReportNoSeed|9|user experience involved needs to be opened E/HmsMapKit_SysParamCache_23( 1095): errorMessage is Error occurs when communicate with server. I/NetworkKit_DefaultRCEventListener( 1095): RxCachedThreadScheduler-1 -->NetworkKit_report_ha_0|null|com.huawei.hms.framework.network.restclient.hianalytics.mac|a|22|HianalyticsHelper report disable W/a ( 1095): Cannot find The class:javax.net.ssl.SSLKeyException W/a ( 1095): Cannot find The class:com.huawei.secure.android.common.util.SafeString

When I go back to previous screen, and navigate to the map, it builds with no issues. It works every time but not first. I am using Huawei P40 lite device.

`Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.15.7 19H2, locale pl-PL) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 12.0.1) [✓] Android Studio (version 4.0)

[✓] Connected device (2 available)

• No issues found! `

It used to work in the past. Maybe flutter version is faulty? Dunno. Google map works with no issues though.

EDIT: on the production app where it used to work and it had no updates since then, it started to behave the same, hmm weird. Maybe it's an issue of the platform map itself, not the plugin nor flutter?

serdar-can commented 4 years ago

Hi @realvotum , thank you for reporting the issue.

As you said, the earlier versions are OK in both production and debug apps yet Flutter and Huawei Maps changed significantly since then. For now, you may change com.huawei.hms.flutter.map.map.MapController.java file's, void init() function's, HmsMap.RESUMED case as described below:

...
 case HmsMap.RESUMED:
                //Comment out this two lines. 
                //mapView.onCreate(null);
                //mapView.onStart();
                mapView.onResume();
                break;
...

After changing the plugin file, please do not forget to Invalidate Caches and Restart the project using Android Studio.

Also, the 1.22 Version of Flutter is released recently. It is advised to use Flutter Version 1.20 since it's the version that Huawei Map Flutter Plugin is developed.

The mentioned issue is in our update scope, we will provide a permanent solution with our next release.

realvotum commented 4 years ago

@SerdarCanDev good job with those comment-outs, it works this way, thanks 👍 I will wait for the official fix in the next release of the plugin then. Do you have it already scheduled?

Also, shall I keep the issue open? Or do I close it? Since the working solution is already provided.

serdar-can commented 4 years ago

We couldn't schedule the next release yet, but please follow the pub.dev for the latest releases.