Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get device Id in expo react native app

I am implementing API to connect app with server. I have to use deviceId there. As mentioned in here we can use third party library 'react-native-device-info'. But when I am using it I am getting errors as attached screenshots. As per error it's saying to do linking but as I am using react version 0.62, so autolinking is there. So What can be issue? It took too much time to search it but till now I didn't get a proper solution.

enter image description here

like image 833
Piyush Naredi Avatar asked Oct 29 '25 05:10

Piyush Naredi


1 Answers

You can use react-native-device-info even in Expo projects. You need to replace Expo Go with a custom build that has react-native-device-info library baked in.

By default, Expo Go used on Android, iPhone Emulators implies managed workflow (aka only expo-* modules are being used). However, using any pure react-native-* libraries falls under bare workflow, so you cannot use Expo Go - the error you see is from Expo Go, not your app.

  1. Build your custom Expo app with expo-dev-client, react-native-device-info libraries included, and install that on your emulators. This needs to be done once when you add a react-native-* library.
  2. Now continue to add code to your project that uses features from react-native-device-info.
  3. npx expo start --dev-client and choose your emulator. Your custom build will be launched and you can make live changes as always like in Expo Go.

Do check out the section on Development Builds from Expo. Needless to say, I have successfully used react-native-device-info on my Expo project, because expo-device cannot provide what I needed.

like image 56
visitsb Avatar answered Oct 30 '25 21:10

visitsb