fluttergoogle-mapsgoogle-maps-flutter

Flutter Google Map Crash on all screen


** Flutter version ** Flutter 3.0.1 Dart 2.17.1 DevTools 2.12.2

** Packages Used ** google_maps_flutter: ^2.1.6 geolocator: ^8.2.1 geocoding: ^2.0.4

** Added Permission manifest file **

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="Google Map Key" />

<meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />

<uses-library
  android:name="org.apache.http.legacy"
  android:required="false" />

** Added in gradle properties file **

android.enableDexingArtifactTransform=false

** Code **

    GoogleMap(
        mapType: MapType.hybrid,
        initialCameraPosition: plex,
        onMapCreated: (GoogleMapController controller) {
          _controller.complete(controller);
        },
      ),

** Issue **

D/MapsInitializer(5575): preferredRenderer: null

D/zzca (5575): preferredRenderer: null

I/zzca (5575): Making Creator dynamically

Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:203115000

Selected remote version of com.google.android.gms.maps_dynamite, version >= 203115000

V/DynamiteModule(5575): Dynamite loader version >= 2, using loadModule2NoCrashUtils

I/Google Maps Android API(5575): Google Play services client version: 12451000

I/Google Maps Android API(5575): Google Play services package version: 221514037

W/MobStoreFlagStore( 5575): at agw.s(:com.google.android.gms.dynamite_mapsdynamite@221514081@22.15.14(150400-0):3)

E/AndroidRuntime( 5577): java.lang.NullPointerException: Attempt to get length of null array

E/AndroidRuntime( 5577): at java.nio.ByteBufferAsIntBuffer.put(ByteBufferAsIntBuffer.java:122) E/AndroidRuntime( 5577): at com.google.maps.api.android.lib6.gmm6.vector.gl.buffer.n.i(:com.google.android.gms.dynamite_mapsdynamite@221514081@22.15.14 (150400-0):2)


Solution

  • The following steps will fix the problem (update to new renderer in kotlin project):

    1. Add this line to your app's build.gradle:

      implementation 'com.google.android.gms:play-services-maps:18.0.2'

    2. Import these lines to MainActivity.kt:

      import com.google.android.gms.maps.MapsInitializer;
      import com.google.android.gms.maps.MapsInitializer.Renderer
      import com.google.android.gms.maps.OnMapsSdkInitializedCallback
      
      
    3. Add MapsInitializer.initialize(applicationContext, Renderer.LATEST, this) in your MainActivity onCreate method.

    Implement OnMapsSdkInitializedCallback interface for verify the new renderer. example (MainActivity.kt):

    package com.example.application
    
    import android.os.Bundle
    import io.flutter.embedding.android.FlutterActivity
    import io.flutter.embedding.engine.FlutterEngine
    import io.flutter.plugin.common.MethodChannel
    import io.flutter.plugins.GeneratedPluginRegistrant
    import io.flutter.view.FlutterMain
    import android.os.Build;
    import android.view.WindowManager
    import android.util.Log;
    import com.google.android.gms.maps.MapsInitializer
    import com.google.android.gms.maps.MapsInitializer.Renderer
    import com.google.android.gms.maps.OnMapsSdkInitializedCallback
    
    
    class MainActivity: FlutterActivity(), OnMapsSdkInitializedCallback{
        override 
        fun onCreate(savedInstanceState: Bundle?){
            super.onCreate(savedInstanceState);
            MapsInitializer.initialize(applicationContext, Renderer.LATEST, this)
        }
    
        override fun onMapsSdkInitialized(renderer: MapsInitializer.Renderer) {
          when (renderer) {
            Renderer.LATEST -> Log.d("NewRendererLog", "The latest version of the renderer is used.")
            Renderer.LEGACY -> Log.d("NewRendererLog","The legacy version of the renderer is used.")
          }
        }
    }
    
    1. Run & Check the logs, you should see these lines:

    D/MapsInitializer: loadedRenderer: LATEST D/NewRendererLog: The latest version of the renderer is used.

    source https://github.com/flutter/flutter/issues/105965#issuecomment-1224473127