I am using react-native-device-info library, and it works fine for iOS simulator. But for Android I receive an error:
undefined is not object (evaluating 'RNDeviceInfo.deviceId')
What can be the problem? I installed it like is described in the guide on the library's page (using rnpm). Then in ponentWillMount() I am trying to get the device id:
import DeviceInfo from 'react-native-device-info';
...
ponentWillMount() {
let clientId = DeviceInfo.getUniqueID();
}
I am using react-native-device-info library, and it works fine for iOS simulator. But for Android I receive an error:
undefined is not object (evaluating 'RNDeviceInfo.deviceId')
What can be the problem? I installed it like is described in the guide on the library's page (using rnpm). Then in ponentWillMount() I am trying to get the device id:
import DeviceInfo from 'react-native-device-info';
...
ponentWillMount() {
let clientId = DeviceInfo.getUniqueID();
}
Share
Improve this question
asked Jul 10, 2016 at 10:43
ReynardReynard
1,10215 silver badges29 bronze badges
9
- What version of RN are you using? – Barnabus Commented Jul 10, 2016 at 11:36
- "react-native": "^0.27.1" – Reynard Commented Jul 10, 2016 at 12:03
- And you've followed the other steps on the readme for android? Specifically you've added the code to MainActivity? – Barnabus Commented Jul 10, 2016 at 12:06
- The guide says: "rnpm install react-native-device-info. rnpm will install (--save) this module then linking for react-native, so you don't have to link for each platforms maually as the following." - so it looks like I don't need to do that. – Reynard Commented Jul 10, 2016 at 12:09
- I looked at the MainActivity - rnpm added those lines automatically. – Reynard Commented Jul 10, 2016 at 13:10
5 Answers
Reset to default 2In addition to rnpm install react-native-device-info
and instruction from here, I had to manually add some lines to the following files:
<YourReactProject>/android/settings.gradle
:rootProject.name = 'YourReactProject' include ':app', ':react-native-device-info' project(':react-native-device-info').projectDir = newFile(rootProject.projectDir, '../node_modules/react-native-device-info/android')
<YourReactProject>/android/app/build.gradle
:... dependencies { pile fileTree(dir: "libs", include: ["*.jar"]) pile ".android.support:apppat-v7:23.0.1" pile ".facebook.react:react-native:+" // From node_modules pile project(':react-native-device-info') } ...
Rebuild by running
react-native run-android
First check is it added to your package.json or not? Then link the package with react native using following mand
react-native link react-native-device-info
It manually links the package with react-native.
I am facing this issue in IOS.
Even I link the package it showing the same issue.
open your project in Xcode, then under build phases add a binary file of react-native-device-info by clicking on the + button.
Rerun the project, It worked for me.
Firstly, make sure that react-native-device-info
is linked in your project if you are using react-native version < 0.60.
If not linked, link it using react-native link react-native-device-info
and then run react-native run-android
mand.
If using react-native version >= 0.60 skip this link mand as auto-linking should work but make sure to run react-native run-android
mand.
and then use it using,
import DeviceInfo from 'react-native-device-info';
DeviceInfo.getUniqueId()
There is a small typo. You are using DeviceInfo.getUniqueID(); instead of DeviceInfo.getUniqueId()
Review in the documentation here
It looks like this package now uses Cocoapods. Run react-native link
then check your Podfile for something like this:
pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
If that's in there, then you just need to install / update your pods.
cd ios
pod install
or
cd ios
pod update
Make sure you restart the metro server and re-run react-native run-ios
use the manual installation and change
your project\node_modules\react-native-device-info\android\build.gradle'
dependencies {
def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION
pile '.facebook.react:react-native:+'
pile ".google.android.gms:play-services-gcm:$googlePlayServicesVersion"}
in here implementation as a pile