MueEZ
MueEZ

Reputation: 496

Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create an already created platform view, view id: 0

I am trying to build google map from flutter flamework...but this error is really buzzing me off...please help me out...

2020-02-19 05:16:45.027 24331-24360/com.cookietech.flutter_map E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create an already created platform view, view id: 0 at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:85) at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:96) at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231) at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93) at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:325) at android.os.Looper.loop(Looper.java:142) at android.app.ActivityThread.main(ActivityThread.java:6598) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) , null) #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18) #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12) #3 AndroidViewController._create (package:flutter/src/services/platform_views.dart:633:54) #4 AndroidViewController.setSize (package:flutter/src/services/platform_views.dart:550:14) #5 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:175:29) #6 RenderAndroidView.performResize (package:flutter/src/rendering/platform_view.dart:156:5) #7 RenderObject.layout (package:flutter/src/rendering/object.dart:1746:9) #8 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #9 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #10 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:11) #11 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:477:7) #12 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7) #13 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:399:14) #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #15 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #17 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #18 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1247:11) #19 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #20 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #21 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #22 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #23 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #24 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #25 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #26 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #27 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #28 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:110:13) #29 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7) #30 RenderProxyBoxMixin.performLayout (package:flu enter image description here

Upvotes: 5

Views: 18952

Answers (4)

MueEZ
MueEZ

Reputation: 496

What i did to solve the problem was write these commands to terminal:

flutter clean
flutter pub cache repair

then rebuild the app and it works. Also, I noticed a lot of the time that the app behaved unexpectedly. To correct this, I closed the app from the device and rebuilt it again.

I am guessing it is a bug. Maybe google needs to fix this, or at least give clear documentation about this fact?

Upvotes: 7

Ahmad Ellamey
Ahmad Ellamey

Reputation: 331

I just solve this problem , 1 - at first you need to add these permissions under the manifest tag in the manifest file :

enter image description here

2 - you need to add this meta data tag under the application tag in the manifest file :

<meta-data android:name="com.google.android.geo.API_KEY"
       android:value="your api key"/>

3 - this feature from google runs only with min sdk equals to 21 , so you need to upgrade your min sdk to 21 at least by replace the defaultConfig in the gradle file (Module:android.app) by the next lines :

    defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.clean_architecture"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
    minSdkVersion 21
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    }

enter image description here

but you will need to change the package name to your package name.

4 - go to the google api and set up your package name and the sha of your app so you can access the api through this application.

Upvotes: 0

Muzammil Hassan
Muzammil Hassan

Reputation: 486

I had the same issue later I realised that i havent given my API Key in AndroidManifest.xml I resolve it by root Directory => android => app => src => main =>AndroidManifest.xml there you can find your meta data inside Application tag of google, it will be just like

<meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/>

Upvotes: 0

Michael Akouwa
Michael Akouwa

Reputation: 45

I found a way to resolve. Well mostly trial and error sort of thing.

  1. In Android Studio, Go to file => settings => System Settings => Android SDk to confirm you have the SDK installed for the android version you're running. To confirm the android version you have click on AVD manager, it should be shown on Target.
  2. Check that you have internet connection in your emulator, a cold reboot should help fix that, if not Wipe Data.
  3. Check that you can open Google map on your android emulator.
  4. Go to emulator settings which that 3 horizontal dots or ellipses and go to settings, OpenGL ES API Level to Auto Select.
  5. Also make sure minSdkVersion 20 in android/app/build.gradle

Hope this helps anyone struggling at the moment.

Upvotes: 2

Related Questions