[Flutter / error / GoogleMap] Android 페이지 전환시 app crash error

solra·2023년 4월 27일
0

안드로이드에서 GoogleMap이 있는 페이지에서 나가거나, GoogleMap이 있는 페이지(탭)를 빠르게 여러번 전환시 아래 오류를 동반하며 앱 crash가 발생되는데요,

error

E/AndroidRuntime(26401): FATAL EXCEPTION: GLThread 8774
E/AndroidRuntime(26401): Process: com. ... ..., PID: 26401
E/AndroidRuntime(26401): java.lang.NullPointerException: Attempt to get length of null array
E/AndroidRuntime(26401): at java.nio.ByteBufferAsIntBuffer.put(ByteBufferAsIntBuffer.java:122)
E/AndroidRuntime(26401): at com.google.maps.api.android.lib6.gmm6.vector.gl.buffer.n.i(:com.google.android.gms.dynamite_mapsdynamite@231416044@23.14.16 (190400-0):2)
E/AndroidRuntime(26401): at com.google.maps.api.android.lib6.gmm6.vector.gl.buffer.n.d(:com.google.android.gms.dynamite_mapsdynamite@231416044@23.14.16 (190400-0):3)
E/AndroidRuntime(26401): at com.google.maps.api.android.lib6.gmm6.vector.gl.drawable.ai.s(:com.google.android.gms.dynamite_mapsdynamite@231416044@23.14.16 (190400-0):30)
E/AndroidRuntime(26401): at com.google.maps.api.android.lib6.gmm6.vector.gl.drawable.ao.s(:com.google.android.gms.dynamite_mapsdynamite@231416044@23.14.16 (190400-0):10)
E/AndroidRuntime(26401): at com.google.maps.api.android.lib6.gmm6.vector.bx.s(:com.google.android.gms.dynamite_mapsdynamite@231416044@23.14.16 (190400-0):29)
E/AndroidRuntime(26401): at com.google.maps.api.android.lib6.gmm6.vector.bq.b(:com.google.android.gms.dynamite_mapsdynamite@231416044@23.14.16 (190400-0):151)
E/AndroidRuntime(26401): at com.google.maps.api.android.lib6.gmm6.vector.at.run(:com.google.android.gms.dynamite_mapsdynamite@231416044@23.14.16 (190400-0):48)
E/flutter (26401): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method map#getVisibleRegion on channel plugins.flutter.dev/google_maps_android_28)

저도 인지는 하고 있었지만 마땅한 해결 방법이 없어 안고 갔던 이슈사항인데,
코드 리팩토링 진행하면서 생각나서 좀 찾아봤는데 드디어 해결했습니다...!
이전에는 같은 오류가 있다는 무수한 답글만 있었는데, 3월에 드디어 해결법이 올라왔네요...흑흑

해결 방법

먼저 pub.dev에서 google_maps_flutter_android 패키지를 추가해줍니다

그 후 main.dartvoid main()에 아래 코드를 추가하면 끝입니다

void main() async {
...
  // Require Hybrid Composition mode on Android.
  final GoogleMapsFlutterPlatform mapsImplementation =
      GoogleMapsFlutterPlatform.instance;
  if (mapsImplementation is GoogleMapsFlutterAndroid) {
    mapsImplementation.useAndroidViewSurface = true;
    mapsImplementation.initializeWithRenderer(AndroidMapRenderer.latest);
  }

  runApp(Main());
}

참고페이지
https://github.com/flutter/flutter/issues/105965

profile
현 Flutter 개발자 🥴

0개의 댓글