aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
249 stars 117 forks source link

fix(analytics): Fix accessing the Analytics category from RxAmplify or Kotlin Facade #2944

Closed mattcreaser closed 6 days ago

mattcreaser commented 2 weeks ago

Issue #, if available:

2943

Description of changes: The RxAmplify and the Kotlin Facade version of Amplify 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 by com.amplifyframework.rx.RxAmplify or com.amplifyframework.kotlin.core.Amplify). Such API calls always result in a IllegalStateException 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.