var DeviceInfo = require(‘react-native-device-info’);
console.log(DeviceInfo.getDeviceId());
Android 5.1
Filtering out the most rated answers from issues on Github |||||||||||_______|||| Also a sharing corner
var DeviceInfo = require(‘react-native-device-info’);
console.log(DeviceInfo.getDeviceId());
Android 5.1
Comments are closed.
var DeviceInfo = require(‘react-native-device-info’);
console.log(DeviceInfo.getDeviceId());
Android 5.1
That error happens when the java module is not being loaded somehow.
Make sure that you’ve done ALL of https://github.com/rebeccahughes/react-native-device-info#installation-android.
After doing the above, do a “Clean” then “Run”.
I had the same issue after installing the module with npm. It seems like the problem was that i didn’t link the module https://github.com/rebeccahughes/react-native-device-info/#automatically-link . I solved the problem running react-native link react-native-device-info
. I’m running my app on an actual device using react-native run-android
As @jorge8989 said, after running react-native link react-native-device-info
error’s gone. However you have to restart the app after running this, quit the simulator and then run react-native run-ios
again.
I had the same problem.The solve way I use is:
Open your Xcode or AndroidStudio,then clean and build your project,last run app.
Developing in Expo and none of the previous solutions have helped. Any suggestions?
Same problems here also with Expo….
make sure your android file MainApplication.java
, have RNDeviceInfo()
+import com.learnium.RNDeviceInfo.RNDeviceInfo;
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNDeviceInfo(),
new MainReactPackage()
);
}
I am using Expo and none of the above solutions worked for me. I am using Expo to create a standalone iOS app
@kmakihara @Lawrence23 @encorex
For Expo users, it seems like this library isn’t compatible as far as I can tell. The workaround for this is to use Expo Constants https://docs.expo.io/versions/latest/sdk/constants.html. Hope this helps future Expo users trying to use this library!
For those facing this on iOS, the complete steps for me were to:
Shut down packager
Uninstall app from simulator
Shut down simulator
Run react-native unlink react-native-device-info
Run react-native link react-native-device-info
Open project in Xcode, clean and build
Start packager react-native-start
Start the simulator react-native run-ios --simulator "iPhone 8 Plus"
or whichever simulator you use
It then worked no problem. Really not sure what the actual issue was, my guess is that the package was not properly linked. (I always use react-native link
)
Thanks @bencodezen for the workaround, my code snippet for those trying to use react-native-device-info with Expo
var deviceSerial =0;
try {
if(Expo.Constants.appOwnership == 'expo')
{
console.log('Running in expo');
deviceSerial = Expo.Constants.deviceId;
}
else
{
var DeviceInfo = require('react-native-device-info');
deviceSerial = DeviceInfo.getUniqueID();
}
console.log('DEVICE ID FOUND: '+deviceSerial);
}
catch(e)
{
console.log('error reading device ID');
deviceSerial =1;
}
In my case
libRNDeviceInfo.a
was missing in Link Library With Binary (Build phases)
Comments are closed.
Copyright © 2022 Fantas...hit
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
That error happens when the java module is not being loaded somehow.
Make sure that you’ve done ALL of https://github.com/rebeccahughes/react-native-device-info#installation-android.
After doing the above, do a “Clean” then “Run”.
Same issue here for iOS
I installed it via
rnpm
I had the same issue after installing the module with npm. It seems like the problem was that i didn’t link the module https://github.com/rebeccahughes/react-native-device-info/#automatically-link . I solved the problem running
react-native link react-native-device-info
. I’m running my app on an actual device usingreact-native run-android
As @jorge8989 said, after running
react-native link react-native-device-info
error’s gone. However you have to restart the app after running this, quit the simulator and then runreact-native run-ios
again.Had the same issue (runnig on ios real device) and re-linking solved that for me, why “relinking”? cause apparently my first trying to link it manually effected so I ran: react-native unlink react-native-device-info and afterwards react-native link react-native-device-info
I had the same problem.The solve way I use is:
Open your Xcode or AndroidStudio,then clean and build your project,last run app.
Developing in Expo and none of the previous solutions have helped. Any suggestions?
Same problems here also with Expo….
make sure your android file
MainApplication.java
, haveRNDeviceInfo()
I am using Expo and none of the above solutions worked for me. I am using Expo to create a standalone iOS app
react-native link OR react-native link react-native-device-info.
@Lawrence23
After that close any previously running react packager. Don’t just simply reload the app.
Now run it. This fixed in my case.
@kmakihara @Lawrence23 @encorex
For Expo users, it seems like this library isn’t compatible as far as I can tell. The workaround for this is to use Expo Constants https://docs.expo.io/versions/latest/sdk/constants.html. Hope this helps future Expo users trying to use this library!
For those facing this on iOS, the complete steps for me were to:
Shut down packager
Uninstall app from simulator
Shut down simulator
Run
react-native unlink react-native-device-info
Run
react-native link react-native-device-info
Open project in Xcode, clean and build
Start packager
react-native-start
Start the simulator
react-native run-ios --simulator "iPhone 8 Plus"
or whichever simulator you useIt then worked no problem. Really not sure what the actual issue was, my guess is that the package was not properly linked. (I always use
react-native link
)Thanks @bencodezen for the workaround, my code snippet for those trying to use react-native-device-info with Expo
In my case
libRNDeviceInfo.a
was missing in Link Library With Binary (Build phases)
For anyone still having this issue even after following the manual linking steps.
new RNDeviceInfo()
fromgetPackages()
RNDeviceInfo()
insidecreateAdditionalReactPackages()
In case you don’t have
createAdditionalReactPackages()
in yourMainApplication.java
, here is the code: