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

NativeModule.RNCNetInfo is null #63

Closed
mattvaldez opened this issue Apr 14, 2019 · 40 comments
Closed

NativeModule.RNCNetInfo is null #63

mattvaldez opened this issue Apr 14, 2019 · 40 comments
Labels
bug Something isn't working released

Comments

@mattvaldez
Copy link

Environment

React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
      Memory: 350.61 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 11.12.0 - /usr/local/bin/node
      Yarn: 1.12.3 - /usr/local/bin/yarn
      npm: 6.7.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 19, 21, 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 25.0.2, 26.0.3, 27.0.3, 28.0.3
        System Images: android-19 | Google APIs ARM EABI v7a, android-21 | Google APIs ARM EABI v7a, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-27 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 2.3 AI-162.4069837
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.4 => 0.59.4 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Platforms

Versions

  • Android: 7.1.1
  • iOS: 12.1
  • react-native-netinfo: 2.0.1
  • react-native: 0.59.4
  • react: 16.8.3

Description

Just used yarn to add the package, and I am getting this error. I have followed the instructions suggested in the message. I am not using CocoaPods.
Screen Shot 2019-04-14 at 4 34 22 PM

Reproducible Demo

Simply importing the library as described in the README documentation produces the error.

import NetInfo from '@react-native-community/netinfo';
@mattvaldez mattvaldez added the bug Something isn't working label Apr 14, 2019
@bitkidd
Copy link

bitkidd commented Apr 14, 2019

Yeap, 2.0.1 has this bug, 2.0.0 works fine.

@matt-oakes
Copy link
Collaborator

👋 Thanks for reporting this. I have an idea what this is and will work to have a fix out by tomorrow

react-native-community-bot pushed a commit that referenced this issue Apr 15, 2019
## [2.0.2](v2.0.1...v2.0.2) (2019-04-15)

### Bug Fixes

* Ensure the correct files are included in the NPM package ([d9fc04f](d9fc04f)), closes [#62](#62) [#63](#63)
@react-native-community-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 2.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mattvaldez
Copy link
Author

Thanks for fixing!

@matt-oakes
Copy link
Collaborator

@mattvaldez No problem! Sorry for the issues. It's because I changed the way the module was packaged and didn't test it fully. I might add a step to CircleCI to catch issues like this, but it's not likely to happen again now it's all set up.

Let me know if you have any other issues.

@mattvaldez
Copy link
Author

@matt-oakes I just installed 2.0.2 and it works, thanks for the fast fix!

@ryekerjh
Copy link

I installed the most recent version (2.0.3) and went back and installed 2.0.2 (npm install --save @react-native-community/netinfo@2.0.2) and I am getting the same error. Is there anything I may be missing?

@matt-oakes
Copy link
Collaborator

@ryekerjh Have you rebuilt the native code and rerun the app? You also might need to check that it is liked correctly by running the link command again.

@ryekerjh
Copy link

@matt-oakes Thanks for the quick response! I did rebuild (shut down the server, wiped the emulator, closed the terminal and ran react-native run-ios from scratch.) I also ran the link command again, but same error.

@matt-oakes
Copy link
Collaborator

@ryekerjh can you open a new issue with the details for a bug report. It's likely that linking is the issue. Can you also let me know in the issue if you're using Cocoapods and the contents of the Podfile and Podfile.lock

@guptayash
Copy link

Same issue with me. Unable to solve it with new update(@2.0.2)

@ryekerjh
Copy link

@guptayash after installing and linking, are you trying to clean and build the project in XCode? If so, are you getting any errors?

@guptayash
Copy link

@ryekerjh Hey!
I have installed version 2.0.2 and linked it again using react-native link @react-native-community/netinfo that linked it successfully but didn't work while I was building the app from xcode.
So I manually dragged RNCNetInfo.xcodeproj (which is located at node_modules/@react-native-community/netinfo/ios/RNCNetInfo.xcodeproj) into root of xcode project. And after that go to build phase in xcode and click Link binary with libraries and add libRNCNetInfo.a there. That worked for me

@matt-oakes
Copy link
Collaborator

@guptayash In that case, the link command was actually failing. You either have a non-standard project structure that the CLI can't read correctly or there is a bug in the CLI link command. Either way, it's unrelated to this library.

@dongcaiying
Copy link

@guptayash Also worked for me. Libraries--RCTNetInfo.xcodeproj--Products--libRNCNetInfo.a drag to targets--Build Phases --Link Binary With Libraries.

@SourceCipher
Copy link

2.0.10 still has the bug. Linking didn't help at all

@matt-oakes
Copy link
Collaborator

@SourceCipher Can you send over:

  • Contents of your .gradle files
  • Contents of your MainApplication.java
  • Screenshot of your iOS linked libraries

If you are running the react-native link command, it's likely that it's only partly completed. The most likely place that it's failed in in adding the module to the android MainApplication.java. Double check that and follow the instructions for manual linking to double check.

@SourceCipher
Copy link

@matt-oakes that was a quick reply! I am not using iOS. Android dont seem to have manual linking guide nor I have seen on the npm docs. From what I can see is that MainApplication was not changed at all after linking so it must be the case that it was not added to the MainApplication

@matt-oakes
Copy link
Collaborator

@SourceCipher Manual linking guides for both platforms are in the README. Search for "Manually link the library on Android" and click the arrow to expand the instructions. If MainApplication was not changed, then that is your issue.

@SourceCipher
Copy link

@matt-oakes Oh I did not see the manual, thanks, that was the problem. Havent linked properly!

@ngoctan95
Copy link

same issue. @matt-oakes . ios and android manual linking. but not work in release. crash app. it is maybe critical bug,

@matt-oakes
Copy link
Collaborator

@ngoctan95 This is working if you have the library linked correctly. If you search for RNCNetInfo in the issues there are already lots of discussions for the different scenarios where linking was not performed correctly. It's 99% certain that your issue is one of those. Take a look through them and if it really isn't one of those, open a new issue with as much information as you can, including why it's not any of the previously mentioned issues.

https://github.com/react-native-community/react-native-netinfo/issues?utf8=✓&q=RNCNetInfo

@sagargulati
Copy link

sagargulati commented Sep 30, 2019

Any solution with auto-linking on react-native 0.61.1? The same issue coming.

@ghost
Copy link

ghost commented Oct 14, 2019

Rebuilding the app again solved the issue for me.

Uninstall the app first, run the command "cd android && gradlew clean && cd.." then run "react-native run-android".

@LucaKIN
Copy link

LucaKIN commented Oct 17, 2019

@sagargulati

I recommend unlink everything that you do manually related this dependency and add the following line in your Podfile.
pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'

Then pod install and it should work.

@sagargulati
Copy link

sagargulati commented Oct 22, 2019

@LucaKIN: I'm not building for iOS nor I'm on Mac

@defcon8
Copy link

defcon8 commented Dec 10, 2019

Same problem here with react-native 0.61.5. Unable to use this module with auto-linking.

@mikehardy
Copy link
Contributor

npx react-native-clean-project clean-project-auto

this happens all the time for react-native-device-info (I maintain there) and that command above frequently clears things up (except when it doesn't, but doesn't hurt to try)

the module definitely works with auto-linking.

@emersonhsieh
Copy link

Unfortunately, I had to link the package manually to get it to work on iOS as well. I have a freshly ejected Expo 36 (React Native 0.61.4) app with the Bare workflow, and I tried the solution above to no avail.

Here is my system info; hopefully this helps pin down the issue.

info Fetching system and libraries information...
System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
    Memory: 129.51 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    npm: 6.13.2 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 23, 26, 27, 28, 29
      Build Tools: 26.0.2, 28.0.3, 29.0.1
      System Images: android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
  npmPackages:
    react: ~16.9.0 => 16.9.0 
    react-native: ~0.61.4 => 0.61.4 
  npmGlobalPackages:
    react-native-cli: 2.0.1

@mikehardy
Copy link
Contributor

Podfile would be more useful, I bet it's missing something like the pair of https://github.com/facebook/react-native/blob/master/template/ios/Podfile#L2 and https://github.com/facebook/react-native/blob/master/template/ios/Podfile#L78

@emersonhsieh
Copy link

@mikehardy you were right, the line require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' was missing from my Podfile. use_unimodules! was in the Podfile though.

I tried adding the missing line to the Podfile, cleared node_modules and ran npm install and pod install, but my Podfile didn't change and the NetInfo pod still didn't install without linking manually. Should Podfile be modified automatically after installing the NetInfo npm package?

Here is my original Podfile for reference:

platform :ios, '10.0'

require_relative '../node_modules/react-native-unimodules/cocoapods'

target 'Waves' do

  rnPrefix = "../node_modules/react-native"
  
  # React Native and its dependencies
  pod 'FBLazyVector', :path => "#{rnPrefix}/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "#{rnPrefix}/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "#{rnPrefix}/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "#{rnPrefix}/Libraries/TypeSafety"
  pod 'React', :path => "#{rnPrefix}/"
  pod 'React-Core', :path => "#{rnPrefix}/"
  pod 'React-CoreModules', :path => "#{rnPrefix}/React/CoreModules"
  pod 'React-RCTActionSheet', :path => "#{rnPrefix}/Libraries/ActionSheetIOS"
  pod 'React-RCTAnimation', :path => "#{rnPrefix}/Libraries/NativeAnimation"
  pod 'React-RCTBlob', :path => "#{rnPrefix}/Libraries/Blob"
  pod 'React-RCTImage', :path => "#{rnPrefix}/Libraries/Image"
  pod 'React-RCTLinking', :path => "#{rnPrefix}/Libraries/LinkingIOS"
  pod 'React-RCTNetwork', :path => "#{rnPrefix}/Libraries/Network"
  pod 'React-RCTSettings', :path => "#{rnPrefix}/Libraries/Settings"
  pod 'React-RCTText', :path => "#{rnPrefix}/Libraries/Text"
  pod 'React-RCTVibration', :path => "#{rnPrefix}/Libraries/Vibration"
  pod 'React-Core/RCTWebSocket', :path => "#{rnPrefix}/"
  pod 'React-Core/DevSupport', :path => "#{rnPrefix}/"
  pod 'React-cxxreact', :path => "#{rnPrefix}/ReactCommon/cxxreact"
  pod 'React-jsi', :path => "#{rnPrefix}/ReactCommon/jsi"
  pod 'React-jsiexecutor', :path => "#{rnPrefix}/ReactCommon/jsiexecutor"
  pod 'React-jsinspector', :path => "#{rnPrefix}/ReactCommon/jsinspector"
  pod 'ReactCommon/jscallinvoker', :path => "#{rnPrefix}/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "#{rnPrefix}/ReactCommon"
  pod 'Yoga', :path => "#{rnPrefix}/ReactCommon/yoga"
  pod 'DoubleConversion', :podspec => "#{rnPrefix}/third-party-podspecs/DoubleConversion.podspec"
  pod 'glog', :podspec => "#{rnPrefix}/third-party-podspecs/glog.podspec"
  pod 'Folly', :podspec => "#{rnPrefix}/third-party-podspecs/Folly.podspec"

  # Other native modules
  pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
  pod 'RNReanimated', :podspec => '../node_modules/react-native-reanimated/RNReanimated.podspec'
  pod 'RNScreens', :path => '../node_modules/react-native-screens'

  # Automatically detect installed unimodules
  use_unimodules!
end

@mikehardy
Copy link
Contributor

@emersonhsieh read that second link I sent very carefully https://github.com/facebook/react-native/blob/master/template/ios/Podfile#L78

It does not contain the characters 'unimodules'

@emersonhsieh
Copy link

emersonhsieh commented Dec 13, 2019

@emersonhsieh read that second link I sent very carefully https://github.com/facebook/react-native/blob/master/template/ios/Podfile#L78

It does not contain the characters 'unimodules'

Got it, I'll add those lines manually to the Podfile since Expo did not generate them on ejection. Thank you so much!

@im-amir
Copy link

im-amir commented Dec 18, 2019

If anyone still facing this problem, I have resolved it by installing the required library by running:
yarn add @react-native-community/netinfo

and it's working now. For:
"react-native": 0.61.2
"react-native-offline": "^5.2.0",

@ChathuraPrabhash
Copy link

This issue still has I'm testing on android 9.

@kylanhurt
Copy link

So, I feel compelled to tell this because it took me an entire day to figure out how to fix the issue. I was getting this error during unit tests and was somehow able to "fix" the issue by changing my component imports, which were being imported via an index file with import { CustomeButton } from '../index' to import CustomeButton from '../CustomeButton' (ie directly from the file, without an intermediate index file).

I don't know how this fixes anything but I figure it may help for others. The good thing is that it appears I only need to change the import syntax in the test files (and not component source files).

@rahul-spericorn
Copy link

I am using
"react-native": "0.62.2",
"@react-native-community/netinfo": "^5.9.2",
distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip

I am getting this error "NativeModule.RNCNetInfo is null" in android

I tried with manual linking no use.

Anyone, please help

@rahul-spericorn
Copy link

This issue still has I'm testing on android 9.

have you fixed this issue in android?

@john-harding
Copy link

ios fix for me:
cd ios
rm Podfile.lock
pod install
cd ..
react-native run-ios

@mikehardy
Copy link
Contributor

For future people: this is ALWAYS an integration issue. You have not integrated the module correctly somehow. Either auto-linking wasn't implemented correctly in a react-native upgrade, or you did not pod install, or you have cached build artifacts (npx react-native-clean-project might help) or a few other things but it is NOT the module's fault. You need to fix your project, then it will work

@react-native-netinfo react-native-netinfo locked as resolved and limited conversation to collaborators Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests