Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined is not object (evaluating 'RNDeviceInfo.deviceId') #52

Closed
jurajkrivda opened this issue Jun 14, 2016 · 57 comments
Closed

undefined is not object (evaluating 'RNDeviceInfo.deviceId') #52

jurajkrivda opened this issue Jun 14, 2016 · 57 comments

Comments

@jurajkrivda
Copy link

var DeviceInfo = require('react-native-device-info');
console.log(DeviceInfo.getDeviceId());

Android 5.1

@heyalexchoi
Copy link

having a similar issue. in my case DeviceInfo seems to not be importing properly.

screen shot 2016-06-14 at 3 34 29 pm

@spukhov
Copy link
Contributor

spukhov commented Jul 10, 2016

The same story. Android 6.0.

@mehcode
Copy link
Contributor

mehcode commented Jul 10, 2016

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

@alma-socar
Copy link

alma-socar commented Jul 21, 2016

Same issue here for iOS

2016-07-21 13:57:23.197 [error][tid:com.facebook.react.JavaScript] undefined is not an object (evaluating 'RNDeviceInfo.uniqueId')

I installed it via rnpm

@heyalexchoi
Copy link

heyalexchoi commented Jul 21, 2016

I fixed my issue by relinking the native dependency. It was improperly linked (or its linking wasn't properly checked into .pbxproj) so I suppose it was undefined at runtime.

Although on closer look, it seems my issue is not what is reported here.

@manupytwn
Copy link

manupytwn commented Jul 26, 2016

"react": "15.2.1",
"react-native": "^0.29.2",
"react-native-contacts": "0.2.8",
"react-native-device-info": "^0.9.3"

I've got this error after install the module and use it in my code, when I try to configure "react-native-device-info" from "pod install". A version of React (0.11.0) is installed and duplicate symbols:

duplicate symbol _OBJC_METACLASS_$_RCTNavigatorManager in:
    /Users/manupytwn/GitHub/TheApp/ios/build/Debug-iphonesimulator/libReact.a(RCTNavigatorManager.o)
    /Users/manupytwn/GitHub/TheApp/node_modules/react-native/React/build/Debug-iphonesimulator/libReact.a(RCTNavigatorManager.o)
ld: 458 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If I try to configure manually I've got this error:

ld: warning: object file (/Users/manupytwn/GitHub/TheApp/node_modules/react-native-device-info/build/Debug-iphonesimulator/libRNDeviceInfo.a(RNDeviceInfo.o)) was built for newer iOS version (8.0) than being linked (7.0)

@krishbhattacharyya
Copy link

krishbhattacharyya commented Aug 17, 2016

Hi,
The same problem arise to me. Is there any solution?
screenshot from 2016-08-17 12 49 11

@manupytwn
Copy link

My solution was to downgrade react and react-native:

"react": "0.14.8",
"react-native": "0.25.1",
"react-native-contacts": "0.2.8",
"react-native-device-info": "^0.9.3"

Good luck!

@krishbhattacharyya
Copy link

krishbhattacharyya commented Aug 25, 2016

Thanks @manupytwn I will try it very soon. ( I am facing another problem also I have added the "react-native-device-info" in packages but not used for the above error, In my simulator the build is working fine but if someone clone the project & wants to run the project in simulator it caused error but if I uninstall the "react-native-device-info" package and remove the added portion "MainActivity.java & AndroidManifest.xml" it works fine. Is there any reason for that? Do you have any idea? )

@page-fault-in-nonpaged-area

Exactly the same problem. Ran it last night it was okay. This morning this error magically appeared.

@goodhyun
Copy link

goodhyun commented Oct 8, 2016

First I got this error on the red screen, but after I rebuilt all again, my android app started to force-close. to make matters worse...

@afilp
Copy link

afilp commented Oct 11, 2016

Hi, I get the same error on Android, when running "react-native run-android" on a device:

MainApplication.java:41: error: cannot find symbol
new RNDeviceInfo(),

Is there any solution imminent? We cannot release without this unfortunately (because it works on iOS but not on Android...)

@aamir-munir
Copy link

Anyone found a solution? I am getting the same error on Android and I have to upload the application ASAP.

@jorge8989
Copy link

jorge8989 commented Oct 18, 2016

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

@breadadams
Copy link

breadadams commented Oct 19, 2016

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.

@aamir-munir
Copy link

@breadadams I did that but still getting the same error I am using RN 0.34 and it run perfectly fine on iOS only android have this issue.

@breadadams
Copy link

breadadams commented Oct 20, 2016

Hmm, that's weird @itcurves. I'd only tested on iOS so far, but just ran on android (simulator) & working fine there too. Maybe it's an incompatibility? The app I'm testing on is pretty barebones at the mo' - just default react-native components & some firebase connections.

@aamir-munir
Copy link

Yes @breadadams it is. Look at this I just try to link again:

rnpm-install info Android module react-native-device-info is already linked
rnpm-install info iOS module react-native-device-info is already linked

but still same error:

Cannot read property 'uniqueId' of undefined
Object.getUniqueID
deviceinfo.js:11
new
index.android.bundle?platform=android&dev=true&hot=false&minify=false:80800:42
ReactCompositeComponentWrapper._constructComponentWithoutOwner
ReactCompositeComponent.js:296
ReactCompositeComponentWrapper._constructComponent
ReactCompositeComponent.js:278
ReactCompositeComponentWrapper.mountComponent
ReactCompositeComponent.js:190
Object.mountComponent
ReactReconciler.js:47
Constructor.mountChildren
ReactMultiChild.js:240
Constructor.initializeChildren
ReactNativeBaseComponent.js:69
Constructor.mountComponent
ReactNativeBaseComponent.js:187
Object.mountComponent
ReactReconciler.js:47

@LironHazan
Copy link

LironHazan commented Nov 5, 2016

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

@xiaoleiooo
Copy link

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.

@salujaharkirat
Copy link

salujaharkirat commented Jan 12, 2017

After Linking I got this:-

relay-react-native-app aragorn$ react-native link react-native-device-info
rnpm-install info Linking react-native-device-info android dependency
rnpm-install info Android module react-native-device-info has been successfully linked
rnpm-install info Linking react-native-device-info ios dependency
rnpm-install info iOS module react-native-device-info has been successfully linked

But still error was coming. So I cleaned the project and build it again. Works perfectly after that

@ThunderDev1
Copy link

ThunderDev1 commented Mar 4, 2017

I have a similar error on android 4.4 device (works ok in emulator):

undefined is not an object (evaluating 'RNDeviceInfo.deviceLocale')

Have double checked https://github.com/rebeccahughes/react-native-device-info#installation-android

Have run ./gradlew clean

When I run react-native link react-native-device-info is says module is already linked

Any ideas ?

@holgersindbaek
Copy link

I've got the same issue. @ThunderDev1 solution didn't work for me. Any other suggestions?

@holgersindbaek
Copy link

I've tried all the suggestions above and I'm still getting the same error. Does everyone still have this issue after it was first reported almost a year ago? Nobody found the cause of the bug?

@kmakihara
Copy link

Developing in Expo and none of the previous solutions have helped. Any suggestions?

@encorex
Copy link

encorex commented Apr 5, 2017

Same problems here also with Expo....

@GantMan
Copy link
Collaborator

GantMan commented Apr 5, 2017

did you eject from Expo? So you have an ios/android project?

@adamnator92
Copy link

adamnator92 commented Apr 20, 2017

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()
      );
    }


@Lawrence23
Copy link

Lawrence23 commented Jul 27, 2017

I am using Expo and none of the above solutions worked for me. I am using Expo to create a standalone iOS app

@ts-ign0re
Copy link

@Lawrence23 try

$ react-native link react-native-device-info

@Lawrence23
Copy link

Lawrence23 commented Jul 28, 2017

@tronin Tried that. Didn't work

@jiteshwadia
Copy link

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.

@bencodezen
Copy link

@jiteshwadia Are you using Expo? It seems like that may be the issue. I'm not able to link it using Expo either.

@jiteshwadia
Copy link

@bencodezen , No, I am not using Expo

@bencodezen
Copy link

@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!

@betoharres
Copy link

Same here, I just createad a fresh new project and then tried to use it on iOS emulator and failed with this message..

Is this a particular OS problem or is something with the library?

@betoharres
Copy link

betoharres commented Sep 13, 2017

I got it working after linking it again(for some reason you need to do 2x, react-native link react-native-device-info && react-native link) and shut down any open process and build everything again.

@davebro
Copy link

davebro commented Oct 8, 2017

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)

@erwan-lcs
Copy 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;
    }

@chiragpurohit71085
Copy link

In my case

libRNDeviceInfo.a
was missing in Link Library With Binary (Build phases)

@dann1609
Copy link

dann1609 commented Feb 7, 2018

In my case I import node_modules/react-native-device-info/RNDeviceInfo.xcodeproj to libraries inside Xcode project. then link libRNDeviceinfo.a to build phases then build project from Xcode.

captura de pantalla 2018-02-06 a la s 11 14 47 p m
captura de pantalla 2018-02-06 a la s 11 15 51 p m

@machour
Copy link
Collaborator

machour commented Feb 14, 2018

Closing this old issue which became a melting pot of ios/android build issues..
If anyone still face this problem, please submit a new issue.

@machour machour closed this as completed Feb 14, 2018
@sterswift
Copy link

@bencodezen Saved me, thank you very much!

@bakedbird
Copy link

bakedbird commented Jul 13, 2018

For anyone still having this issue even after following the manual linking steps.

  • Go to MainApplication.java
  • Delete new RNDeviceInfo() from getPackages()
  • Add RNDeviceInfo() inside createAdditionalReactPackages()

In case you don't have createAdditionalReactPackages() in your MainApplication.java, here is the code:

public class MainApplication extends NavigationApplication {
    ...
    @Override
    public List<ReactPackage> createAdditionalReactPackages() {
        return Arrays.<ReactPackage>asList(
                // eg. new VectorIconsPackage()
                new RNDeviceInfo()
        );
    }
    ....
}

@TheAznShumai
Copy link

Commenting on @bakedbird fix. I had the problem where the Main Application never created a new instance for RNDdeviceInfo().

I fixed it by adding it in RNDeviceInfo into the following code in MainActivity. Please note I changed my java file to use kotlin and dont forget to import com.learnium.RNDeviceInfo.RNDeviceInfo

override fun getPackages(): List<ReactPackage> {
            return Arrays.asList(
                    MainReactPackage(),
                    FastImageViewPackage(),
                    PlayerPackage(),
                    RNDeviceInfo(),
                    RNI18nPackage()
            )
        }

@yusuf987
Copy link

thanks chiragpurohit71085 your solution worked for me

@mikehardy
Copy link
Collaborator

This issue is popular, but it is always an installation/configuration issue. There is a clean example in the repository built following the instructions and working well. If you can reproduce your problem in the example, open a new issue. If not, then study the example again to see how to integrate things and make sure you followed the instructions...

@Bill-Niz
Copy link

Bill-Niz commented Apr 4, 2019

Commenting on @bakedbird fix. I had the problem where the Main Application never created a new instance for RNDdeviceInfo().

I fixed it by adding it in RNDeviceInfo into the following code in MainActivity. Please note I changed my java file to use kotlin and dont forget to import com.learnium.RNDeviceInfo.RNDeviceInfo

override fun getPackages(): List<ReactPackage> {
            return Arrays.asList(
                    MainReactPackage(),
                    FastImageViewPackage(),
                    PlayerPackage(),
                    RNDeviceInfo(),
                    RNI18nPackage()
            )
        }

Ho man!! Wasted 3 days on this!!
Thank you!!

@CoryWritesCode
Copy link

If anyone is still having issues with this I found that I had this issue when upgrading from v2.2.2 to v3.1.4 and noticed the function name change in this beta version from getDeviceID to getDeviceId. Changing this, and rebuilding worked for me.

@mikehardy
Copy link
Collaborator

@CoryWritesCode if you haven't seen https://github.com/react-native-community/react-native-device-info/wiki/V2-to-V3-Migration-Guide you should check it out - there were quite a few moves, but all documented with the from what -> to what

@digitaluniverse
Copy link

@CoryWritesCode I would have never noticed this thank you

@mikehardy
Copy link
Collaborator

@digitaluniverse most of the API name changes are similarly subtle re-capitalizations - please look at the inventory on the v2->v3 page, I would hate for anyone else to waste any more time than needed

@CoryWritesCode
Copy link

@mikehardy Thanks for the link! I had not seen that at all. Might be good to have that linked on the README.

@mikehardy
Copy link
Collaborator

@CoryWritesCode oh dang - I thought I did? It is definitely in the changelog, but you're right. The more linkage the better - the v3 release is breaking but it is not supposed to suck as an upgrade :-)

mikehardy added a commit that referenced this issue Sep 25, 2019
Related to #52 - came up in the comments it could be linked more prominently
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests