Branch.subscribe doesn't work when Android app is opened with link on expo-branch 2.3.1 / SDK 39

SDK Version: 39 / Managed / Android

On the Branch.subscribe, I get this as an error when I boot up the app in Android on expo-branch 2.3.1:

error: “Warning. Session initialization already happened. To force a new session, set intent extra, “branch_force_new_session”, to true.” I also do not get the Branch params coming through successfully.


After encountering this issue on my Android (OS Version 9) Phone even on previous versions, I’ve wrote a hack that checks for params = await Branch.getLatestReferringParams(); in the case I get the session initialized error. It’s really ugly…but think it might give me the functionality I need. Really curious if others are not experiencing this…

It has been occuring for users using the react-native-branch library but not in Expo:

Session initialization already happened
Unity android session initialization already happened
Warning. Session initialization already happened…

Some of these guys were doing something specific to cause this…but in my case I literally call the SDK with one require statement:

const Branch = constants.inExpo ? undefined : require("expo-branch").default;

And then just something like:

useEffect(() => Branch.subscribe(({error, params}) => undefined), [])

Nothing fancy, but I get that error when the app opens from a fresh start.

1 Like

We’re also experiencing this issue since we upgrade to SDK 39. Interestingly enough, in our case it’s not crashing when it boot up. Instead, it crashes on specific screens:

  • We have one screen where we display the expo-camera. We managed to sort this crash out using isFocused from useIsFocused hook (from react-navigation) to render the Camera component only when the screen is focused.
  • When we display a MapView component. I didn’t found the way to sort this one around yet.

Not sure what’s going in on here but seems like the error reported as “Warning. Session initialization already happened. To force a new session, set intent extra, “branch_force_new_session”, to true.” is being displayed when actually is something else crashing behind the scenes.

@aryk I’d suggest you to try to display a Hello World screen to see if that actually works for you and then start to introduce (if possible) the component of your actual screen until you reach the crash?

Yes, that is the same error I’m getting…I don’t think we are the only two affected. If it is interacting with something else in my app, then that message really doesn’t give me anything to go on.

If you google that error, you’ll find it happens to many Branch api users on different platforms through the year. Perhaps it’s simply not cleaning up previous sessions on Android? IDK. There is nothing fancy about my app, nor my implementation of branch, nor did the API change for expo-branch (to the best of my knowledge), and since rolling back to the previous version fixed it for me, there is a high probability that the new version will break other people’s branch implementations on Android.

That’s what I would wager in any case :wink:

Just to confirm. This was actually some other issues which were crashing the app, causing a restart and when that happen the second branch subscription was failing, hence the error reported.

Fixing the actual issues on our screens (MapView and Camera issues) was the actual solution. This error was a side effect of the real ones.

So once you’re app stopped crashing Branch was actually working correctly? My app is stable, it’s not crashing. I can try upgrading again and see if it still breaks for me.

I’m curious too if the Branch.subscribe needs to be unsubscribed on a useEffect? If it is, it isn’t documented that way. The documentation shows that it can be used top level in the example. Maybe someone from Expo can chime in…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.