question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash: HostObject::get(propName:RNDeviceInfo)

See original GitHub issue

Bug

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).

Screen Shot 2019-10-11 at 4 14 32 PM

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 to CFBundleDisplayName, 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

  1. Run an app that includes this repo but does not include the CFBundleDisplayName key in it’s info.plist file.
  2. Notice that the app crashes almost immediately with the obscure HostObject::get(propName:RNDeviceInfo) error
  3. Modify return values of getAppName to prove the concept

Describe what you expected to happen:

  1. 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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
mikehardycommented, Oct 15, 2019

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 😉 )

1reaction
tgvishalcommented, Sep 22, 2022

For me, it happened because of using the wrong variable name in the “Info.plist” file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash: HostObject::get(propName:RNDeviceInfo) #846 - GitHub
1, we have noticed an issue with the app crashing almost immediately on launch, citing a HostObject::get(propName:RNDeviceInfo) fatal error ( ...
Read more >
Exception in HostObject - React Native Build Android
In my case, the problem was with react-native-device-info. Try this in your app/build.gradle dependencies:
Read more >
Exception in HostObject::get(propName:RNDeviceInfo)
On startup, the app is crashing and displays this error message: When we remove the lib, everything works fine. We already tried to...
Read more >
java.lang.SecurityException: Settings key: <bluetooth_name ...
Error: Exception in HostObject::get(propName:NativeUnimoduleProxy): java.lang.SecurityException: Settings key: <bluetooth_name> is only ...
Read more >
react-native-device-info - Bountysource
With the hook useIsHeadphonesConnected I only get the following back: { "loading": ... a native module is required named RNDeviceInfo as it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found