[android] Swap std::ostringstream usage for std::to_string #8542
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.
Why
Eric reported native crashes when running older experiences on Expo client after RN 0.62 upgrade.
How
The first problem I had was reproducing it — after some testing @wkozyra95, @tsapeta and I realized it was only happening on Android 10.
The stacktrace didn't show too much information, but there was the most interesting part:
It looked like it threw a native exception when… building a description for
JSCRuntime
. The implementation of this method is:where
to_string
is defined asThe
use_facet
methods fromc++_shared
aren't very helpful either:Then, fortunately, I realized I saw a PR removing
std::stream
usage recently — #8352.I decided to follow its example and see whether changing:
could let the crash go, so I checked out the
sdk-37
branch, applied the change, rebuilt thehost.exp.reactandroid-abi37_0_0
, copiedmaven
folder, checked outmaster
, pastedmaven
folder, rebuilt Expo client and lo and behold, SDK 37 didn't crash anymore! Opening SDK36 experience didn't crash anymore either!Then I started testing more and I realized Expo client still crashed if the first experience opened after running the app was a not-patched SDK (eg. SDK36). So I went on and applied the fix for all other SDKs.
I also tried building projects with newer NDK (RN 0.62 uses r19c, this didn't help either).
If I understand the problem correctly, only one version of some symbol is used in Expo client—the one that is loaded first. For some reason the version loaded by unversioned Home doesn't count. Moreover,
<<
-ing tostd::ostringstream
may cause bugs in some circumstances.I understand that this may fix the problem and nobody will experience any crash whatsoever anymore or this may fix only one probable cause of crashes and we only QA and users may figure out whether it's safe now.
Thanks to @wkozyra95 for assistance and answers during the whole day!
Test Plan
Running Expo client on Android 10 emulator does not cause a crash anymore no matter experience of which SDK is run first.