rph
rph

Reputation: 128

How to correctly initialize latest renderer in android (google_maps_flutter)?

I have a question regarding the correct initialization of the [google_maps_flutter] latest android map renderer

While tracking down some warnings I get during my app initialization: Warnings:

W/DynamiteModule(11578): Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule(11578): Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:7
I/DynamiteModule(11578): Selected remote version of com.google.android.gms.googlecertificates, version >= 7    
W/MobStoreFlagStore(11578): Unable to update local snapshot for com.google.android.libraries.consentverifier#com.xxxxx , may result in stale flags.
W/MobStoreFlagStore(11578): java.util.concurrent.ExecutionException: java.lang.SecurityException: GoogleCertificatesRslt: not allowed: pkg=com.xxxxx

I found the following google maps issue, where they describe that there are some problems with the legacy renderer could cause these outputs:

https://issuetracker.google.com/issues/228091313#comment19

"Our engineering team is prioritizing works on the Latest renderer, so this Legacy renderer issue will take some time to be worked on."

Attempt of problem-solving:

1) Latest renderer requirements (check)

  • Android 5.0 (API level 21) or later
  • 2 GB or more of data storage Using
  • Google Play services version 21.39.14 or later

See: https://cloud.google.com/blog/products/maps-platform/learn-about-our-updated-renderer-maps-sdk-android

2) initialize latest renderer before GoogleMaps is initialized (check)

Using example from: https://pub.dev/packages/google_maps_flutter_android#map-renderer

The following code is called before any GoogleMaps instance is called:

import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';

[...]

Future<void> initMapsRenderer() async {

    // Initialization for custom Android map renderer.
    AndroidMapRenderer mapRenderer = AndroidMapRenderer.platformDefault;
    
    final GoogleMapsFlutterPlatform mapsImplementation = GoogleMapsFlutterPlatform.instance;

    if (mapsImplementation is GoogleMapsFlutterAndroid) {
      WidgetsFlutterBinding.ensureInitialized();
      mapRenderer = await mapsImplementation.initializeWithRenderer(AndroidMapRenderer.latest);
    }
  }

pubspec.yaml:

google_maps_flutter: ^2.5.0

3) Observed console output:

D/MapsInitializer( 1249): preferredRenderer: LATEST
I/Google Maps Android API(11578): Google Play services package version: 233717063
I/Google Maps Android API(11578): Google Play services maps renderer version(legacy): 203115000
D/MapsInitializer(11578): loadedRenderer: LEGACY

Edit 02.11.2023:

I tested the same source code with two real devices:

Motorola E20:

I/Google Maps Android API(22922): Google Play services client version: 12451000
I/Google Maps Android API(22922): Google Play services package version: 234212063
I/Google Maps Android API(22922): Google Play services maps renderer version(legacy): 203115000
D/MapsInitializer(22922): loadedRenderer: LEGACY

Samsung S22:

I/Google Android Maps SDK(27745): Google Play services client version: 12451000
I/Google Android Maps SDK(27745): Google Play services package version: 234313039
I/Google Android Maps SDK(27745): Google Play services maps renderer version(maps_core): 233610101
D/MapsInitializer(27745): loadedRenderer: LATEST

Apparently there is something device-specific happening as there are two different outputs: Google Maps Android API vs Google Maps Android SDK

Also the phones have two different service package versions, though it is updated to the newest.


What can be the cause that still the legacy renderer is loaded? Any ideas?

Upvotes: 1

Views: 2652

Answers (2)

mrconcerned
mrconcerned

Reputation: 1965

I had this problem using emulator (in real device it works fine), and searched many articles to find the solution. I finally found to add following code to android/app/build.gradle

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

Hope it helps.

Upvotes: 0

JordanDev
JordanDev

Reputation: 1

I faced the same issue. The renderer would not change no matter what I did, but I solved it by looking at the google_maps_flutter_android package example on github and also by running it on a real device and not an emulator (on the emulator the renderer stayed on legacy). The output I finally got was: loadedRenderer: LATEST.

Here is my code:

import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';

/// Initializes map renderer to the `latest` renderer type.
/// The renderer must be requested before creating GoogleMap instances,
/// as the renderer can be initialized only once per application context.
class GMService {
  static Completer<AndroidMapRenderer?>? _initializedRendererCompleter;
  static Future<AndroidMapRenderer?> initializeMapRenderer() async {
    if (_initializedRendererCompleter != null) {
      return _initializedRendererCompleter?.future;
    }

    final Completer<AndroidMapRenderer?> completer = Completer<AndroidMapRenderer?>();
    _initializedRendererCompleter = completer;

    WidgetsFlutterBinding.ensureInitialized();

    final GoogleMapsFlutterPlatform platform = GoogleMapsFlutterPlatform.instance;
    unawaited((platform as GoogleMapsFlutterAndroid)
        .initializeWithRenderer(AndroidMapRenderer.latest)
        .then((AndroidMapRenderer initializedRenderer) => completer.complete(initializedRenderer)));

    return completer.future;
  }
}

Then in main I called GMService.initializeMapRenderer();

Hopefully this works for you and will help :)

Upvotes: 0

Related Questions