Reputation: 1102
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 componentWillMount() I am trying to get the device id:
import DeviceInfo from 'react-native-device-info';
...
componentWillMount() {
let clientId = DeviceInfo.getUniqueID();
}
Upvotes: 4
Views: 6522
Reputation: 5069
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
command.
If using react-native version >= 0.60 skip this link command as auto-linking should work but make sure to run react-native run-android
command.
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
Upvotes: 1
Reputation: 583
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
compile 'com.facebook.react:react-native:+'
compile "com.google.android.gms:play-services-gcm:$googlePlayServicesVersion"}
in here implementation as a compile
Upvotes: 0
Reputation: 1525
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
Upvotes: 0
Reputation: 727
First check is it added to your package.json or not? Then link the package with react native using following command
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.
Upvotes: 1
Reputation: 487
In 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 {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-device-info')
}
...
Rebuild by running react-native run-android
Upvotes: 2