Crash: HostObject::get(propName:RNDeviceInfo)
See original GitHub issueBug
When upgrading this project from v3.1.4 -> current 4.0.1, we have noticed an issue with the app crashing almost immediately on launch, citing a HostObject::get(propName:RNDeviceInfo)
fatal error (that doesn’t seem to give much more info than what’s shown in this screenshot).
Numerous other references to this same obscure error seem to mention the possibility of nil return values in the NSDictionary that is returned over the bridge via the constantsToExport
function.
I have narrowed this particular instance of the error down to the call of [self getAppName]
in RNDeviceInfo.m
here. Commenting out that line seems to resolve the crash.
Digging deeper, it looks like the implementation of that function retrieves CFBundleDisplayName
which can be nil and get us into the state described above (indeed, this was exactly what was going on in our project).
According to Apple Docs, it looks like CFBundleDisplayName
is now marked as ‘required’ and the older CFBundleName
is ‘recommended’ despite there not being any enforcement of that rule (to date?) and despite conflicting info on this page (conversely saying it is ‘recommended’ for ios).
For good measure I will implement CFBundleDisplayName
in our app to get around this, but thought I would suggest these fixes to resolve the issue for anyone who may be in a similar scenario (upgrading an older project to newer RN + newer library versions):
- Update the getAppName function to grab the value of
CFBundleName
as a fallback toCFBundleDisplayName
, since that can be nil (as other repos do) - OR Return an empty string that does not cause this nil issue (and therefore have no fallback, if that’s not desired)
Environment info
React native info output:
System:
OS: macOS Mojave 10.14.5
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 1.59 GB / 32.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: 1.15.2 - ~/.nvm/versions/node/v10.15.3/bin/yarn
npm: 6.11.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
IDEs:
Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-clean-project: 3.2.4
react-native-cli: 2.0.1
react-native: 0.60.5
Library version: 4.0.1
Steps To Reproduce
- Run an app that includes this repo but does not include the
CFBundleDisplayName
key in it’s info.plist file. - Notice that the app crashes almost immediately with the obscure
HostObject::get(propName:RNDeviceInfo)
error - Modify return values of
getAppName
to prove the concept
Describe what you expected to happen:
- Out of the box, the app should run normally and not crash before making any calls to DeviceInfo functions.
Reproducible sample code
Using the example project in this repo, remove CFBundleDisplayName
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top GitHub Comments
This is fantastic sleuthing @renatoniro - thanks for opening an issue on it with the details all included. I’ll see if I can get a patch release out quickly, in the meantime feel free to use patch-package to make a quick patch in node_modules (with patch-package persisting it across all your team / installs) that alters https://github.com/react-native-community/react-native-device-info/blob/643577cfadd92b9577b68ff2906af931ae81689b/ios/RNDeviceInfo/RNDeviceInfo.m#L142 to use CFBundleName to get you moving - that’d be the work of maybe 10 minutes
The real fix will probably be a CFBundleDisplayName attempt with fallback to CFBundleName but that’s a few more minutes work of course (unless you want to make a PR, then I’m sure it’ll just be 2 minutes, no more 😉 )
For me, it happened because of using the wrong variable name in the “Info.plist” file.