-
Notifications
You must be signed in to change notification settings - Fork 165
feat: Improve GoogleMapsInitializer error handling and retries #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+282
−116
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
|
Fixes #776 |
Code Coverage
|
kikoso
reviewed
Sep 24, 2025
maps-compose/src/main/java/com/google/maps/android/compose/internal/GoogleMapsInitializer.kt
Outdated
Show resolved
Hide resolved
kikoso
approved these changes
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
harrytmthy
reviewed
Sep 24, 2025
maps-compose/src/main/java/com/google/maps/android/compose/internal/GoogleMapsInitializer.kt
Show resolved
Hide resolved
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.
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))
|
🎉 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request enhances the
GoogleMapsInitializerby introducing more robust error handling and the ability to retry initialization.Key changes:
initializefunction now catches exceptions during initialization.UNINITIAL-IZED, allowing for subsequent retry attempts.FAILURE.forceInitializationparameter has been added to theinitializefunction to allow for re-initialization even if it has already succeeded or is in progress.