fix(analytics): Fix accessing the Analytics category from RxAmplify or Kotlin Facade #2944
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.
Issue #, if available:
#2943
Description of changes:
The
RxAmplify
and the Kotlin Facade version ofAmplify
both instantiate their own versions of the Analytics (and Logging) category. Neither do that for other categories.This is a problem because they delegate to the main Amplify for all other actions, including adding plugins. Therefore, the Analytics plugin gets added to the "main" instance of the Category (e.g. the one owned by
com.amplifyframework.core.Amplify
) while subsequent API calls get routed to the "new" instance of the category (owned bycom.amplifyframework.rx.RxAmplify
orcom.amplifyframework.kotlin.core.Amplify
). Such API calls always result in aIllegalStateException
because there is no plugin added to that instance of the category.The fix is simple, the two facade classes should reference the Analytics/Logging instance owned by the main Amplify class, just as they do for all other categories.
This fixes the crash. Now it does not matter what combination of Amplify/RxAmplify/Kotlin Facade is used, all calls work as expected.
How did you test these changes?
Documentation update required?
General Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.