KEMBAR78
feat: Improve GoogleMapsInitializer error handling and retries by dkhawk · Pull Request #778 · googlemaps/android-maps-compose · GitHub
Skip to content

Conversation

@dkhawk
Copy link
Collaborator

@dkhawk dkhawk commented Sep 23, 2025

This pull request enhances the GoogleMapsInitializer by introducing more robust error handling and the ability to retry initialization.

Key changes:

  • The initialize function now catches exceptions during initialization.
  • Recoverable errors will reset the state to UNINITIAL-IZED, allowing for subsequent retry attempts.
  • Unrecoverable errors, such as a missing manifest value, will set the state to FAILURE.
  • A forceInitialization parameter has been added to the initialize function to allow for re-initialization even if it has already succeeded or is in progress.

Refactored the error handling within `GoogleMapsInitializer` to make it more robust against initialization failures.

Previously, any exception during the `initialize` call would permanently set the state to `FAILURE`, preventing any subsequent attempts.

This change introduces more granular error handling:
- Unrecoverable errors, such as `GooglePlayServicesMissingManifestValueException`, will correctly set the state to `FAILURE`.
- Other exceptions, which may be transient, will now reset the state to `UNINITIALIZED`, allowing the initialization to be attempted again.

Additionally, a `forceInitialization` parameter has been added to the `initialize` function to allow bypassing the initial state check for re-initialization scenarios.
Introduced a new `preferredRenderer` parameter to the `initialize` function.

Key changes:
- The `initialize` function now accepts a `preferredRenderer` to specify which Maps renderer to use.
- The `try-catch` block within the `initialize` function has been refactored to be more idiomatic.

The `AdvancedMarkersActivity` example has been updated to use this improved initializer. It now calls `GoogleMapsInitializer.initialize` within a `LaunchedEffect`, making the initialization asynchronous and tied to the composable's lifecycle.
The `preferredRenderer` parameter has been removed from the `GoogleMapsInitializer.initialize()` function. The Maps SDK for Android now automatically selects the latest available renderer, making this parameter redundant.

This change simplifies the initialization API. The explicit initialization call in the `AdvancedMarkersActivity` sample has also been removed to reflect this simplification.
@dkhawk
Copy link
Collaborator Author

dkhawk commented Sep 23, 2025

Fixes #776

@dkhawk dkhawk requested a review from kikoso September 23, 2025 22:54
@googlemaps-bot
Copy link
Contributor

Code Coverage

There is no coverage information present for the Files changed

Copy link
Collaborator

@kikoso kikoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This commit refactors the `GoogleMapsInitializer` from a static object to an interface-based dependency provided via a `CompositionLocal`.

This architectural change offers several key benefits:
- **Improved Testability:** The initialization logic can now be easily mocked and tested in isolation, as demonstrated by the new unit tests using `mockk`.
- **Dependency Injection:** It aligns with modern dependency injection principles, making the `GoogleMap` composable more configurable and less reliant on a global singleton.
- **Robustness:** The error handling has been made more granular, distinguishing between unrecoverable manifest errors and transient, recoverable issues.

The new `DefaultGoogleMapsInitializer` provides the concrete implementation, ensuring backward compatibility for existing usages while enabling advanced testing and customization scenarios.
@dkhawk dkhawk merged commit 4e3770d into main Sep 30, 2025
10 checks passed
@dkhawk dkhawk deleted the fix/improve-googlemaps-initializer branch September 30, 2025 12:07
googlemaps-bot pushed a commit that referenced this pull request Sep 30, 2025
# [6.12.0](v6.11.0...v6.12.0) (2025-09-30)

### Features

* Improve GoogleMapsInitializer error handling and retries ([#778](#778)) ([4e3770d](4e3770d))
@googlemaps-bot
Copy link
Contributor

🎉 This PR is included in version 6.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants