analytics-react-native: Android "Duplicate analytics client created"
This is a common issue on segment libraries for Android. The issue is that when you have already initialized the segment module on Android you cannot initialize it again without the app crashing.
This happens a lot when doing React Native development on Android, as running the Reload
function (shake your device and press Reload) will cause this crash.
One solution is to guard the initialization on Android. While the doc of this project says you can catch errors when setting up, it doesn’t seem to be working right now.
Here are some related issues in other repos with the same error: https://github.com/leoilab/react-native-analytics-segment-io/issues/3 https://github.com/segmentio/analytics-android/issues/538
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 32
- Comments: 31 (2 by maintainers)
Commits related to this issue
- fix(core): fix duplicate client error in dev mode With this change the setup method will now resolve its promises and thereby be able to catch errors during setup. Fixes #16 — committed to segmentio/analytics-react-native by cristeahub 6 years ago
- fix(core): fix duplicate client error in dev mode With this change the setup method will now resolve its promises and thereby be able to catch errors during setup. Fixes #16 — committed to segmentio/analytics-react-native by fathyb 6 years ago
- fix(core): fix duplicate client error in dev mode With this change the setup method will now resolve its promises and thereby be able to catch errors during setup. Fixes #16 — committed to segmentio/analytics-react-native by fathyb 6 years ago
- https://github.com/segmentio/analytics-react-native/issues/16 — committed to Flatbook/analytics-react-native by michaelkitson 6 years ago
- applying the fix for not handling promises on setup() from this https://github.com/segmentio/analytics-react-native/pull/15/commits/e74ab69471beb6da0c7fe9491aa1d47e350f49ef referenced in this issue: h... — committed to weavix/analytics-react-native by deleted user 5 years ago
- fix(core): fix duplicate client error in dev mode With this change the setup method will now resolve its promises and thereby be able to catch errors during setup. Fixes #16 — committed to segmentio/analytics-react-native by fathyb 6 years ago
- fix(core): fix duplicate client error in dev mode With this change the setup method will now resolve its promises and thereby be able to catch errors during setup. Fixes #16 — committed to segmentio/analytics-react-native by cristeahub 6 years ago
- fix(core): fix duplicate client error in dev mode With this change the setup method will now resolve its promises and thereby be able to catch errors during setup. Fixes #16 — committed to segmentio/analytics-react-native by cristeahub 6 years ago
- fix(core): fix duplicate client error in dev mode With this change the setup method will now resolve its promises and thereby be able to catch errors during setup. Fixes #16 — committed to segmentio/analytics-react-native by cristeahub 6 years ago
- fix(core): fix duplicate client error in dev mode (#51) Ref: LIB-891 Fixes #16 Closes #15 — committed to segmentio/analytics-react-native by fathyb 5 years ago
- chore(release): 1.0.0 [skip ci] ## @uswitch/analytics-react-native-v1.0.0 (2022-06-29) ### ⚠ BREAKING CHANGES * We've improved iOS support for non-Cocoapods users. You do not need to follow these s... — committed to uswitch/analytics-react-native by semantic-release-bot 2 years ago
- chore(release): 1.0.0 [skip ci] ## @uswitch/analytics-react-native-v1.0.0 (2022-06-29) ### ⚠ BREAKING CHANGES * We've improved iOS support for non-Cocoapods users. You do not need to follow these s... — committed to uswitch/analytics-react-native by semantic-release-bot 2 years ago
@fathyb @michaelkitson Any updates?
@fathyb Hate to bother, but we’re excited about this fix too. Let us know if you have a timeline?
The problem is annoying 😦
@fathyb Any updates?
Hey everyone, we’ve released a bug fix in
0.0.1-beta.4
: https://github.com/segmentio/analytics-react-native/blob/master/CHANGELOG.md#001-beta4-2019-03-29I have contacted the support directly to explain the problem as this repository does not seems to have activity. I waited 10 days for an answer that is something like “It’s in the ticket system, I am waiting for an ETA”
I suggest every concerned people to contact support to make these issue more visible and make the Segment devs to do more active support.
Thank you @anandwahed ! I already forked this repo to have a fixed version.
Thanks to crashlytics I detected this issue in production. They are raised because I use code push to deploy OTA. When the app is reloaded with the new version, the
analytics.setup
is called again, and my clients enjoy a new crash. I am not totally sure if this is the only scenario where this library crashes in production.It would be great if you handle this native error and then raise it to JS to handle it there.
Thanks !
👍 to having this error with CodePush. Unpleasant choosing between our delivery mechanism, and our analytics tracking mechanism.
@f2prateek trying that, yarn gives the error
error Can't add "@internal/analytics-react-native": invalid package version undefined.
@snackvideo-dkeith’s fork works (thank you!), though I’d rather not ship a production version of our app based on an unpublished third-party fork! Any word on this fix being published?@fathyb will the fix be merged anytime soon or is there any other workaround for this issue during the app development?
Me too comment. And also feels in some strange situation we get this in production app
In my experience I haven’t had any issues in production, only when reloading during development.
One very quick solution is to do something like this:
With this I haven’t had any issues in our builds, neither during development or production. I can’t 100 % be sure this won’t ever break in production, but our numbers seems to match that this is fine to do.
You can of course also expand this by adding some more error logging if you want to.
When using appcenter codepush : this causes the app crash 😦
Same here if you could please let us know when the fix has been merged.
I came across this bug for iOS, using React Native. Error triggered when trying to use
recordScreenViews: true
ortrackAppLifecycleEvents: true
.Solution: If you are encountering this error for React Native, and you are using CocoaPods, make sure you are not installing both
Analytics
andRNAnalytics
in your podfile.Having both declared seems to cause the duplicate analytics client bug.
@sejas the solution posted by @cristeahub https://github.com/segmentio/analytics-react-native/issues/16#issuecomment-439326062 works fine for us. Till not we haven’t seen any issues in the production as well.
We are seeing another crash in our production system.
This is what we do https://github.com/segmentio/analytics-react-native/issues/16#issuecomment-439326062 . Decide for yourselves if you only want to apply this patch in dev or not.