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

Error: null is not an object (evaluating '_reactNative.NativeModules.RNShare.FACEBOOK') when importing library on Android. #837

Closed
padapada09 opened this issue Jul 31, 2020 · 27 comments
Labels
bug needs more info stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@padapada09
Copy link

Steps to reproduce

  1. npx react-native init Example
  2. npm install react-native-share
  3. Add (import Share from 'react-native-share';) to App.js
  4. run (npx react-native run-android)
  5. Error: TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNShare.FACEBOOK')

Expected behaviour

It should have no problem importing it.

Actual behaviour

It triggers an error: Error: TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNShare.FACEBOOK')

Environment

  • React Native version: 0.61.4
  • React Native platform + platform version: Android 9 PKQ1.180904.001 MIUI Global 11.0.6

react-native-share

Version: 3.7.0/

@padapada09 padapada09 added the bug label Jul 31, 2020
@ronbel
Copy link

ronbel commented Aug 2, 2020

I had the same problem, I linked the library manually (react-native link react-native-share) and it worked. Still haven't tested on iOS but I believe it should also be resolved there.

@tomyedlp
Copy link

tomyedlp commented Aug 2, 2020

I had the same problem, I linked the library manually (react-native link react-native-share) and it worked. Still haven't tested on iOS but I believe it should also be resolved there.

I tried it and did'nt work. Any idea?
I use React-Native version 0.62.2 with Expo.

@padapada09
Copy link
Author

react-native link react-native-share

I tried it... no luck...

@clems36
Copy link

clems36 commented Aug 3, 2020

Same issue on both android & iOS, react-native link react-native-share does not fix it.

@clems36
Copy link

clems36 commented Aug 3, 2020

Fixed on iOS by downgrading to 3.3.3, but not on android. @MateusAndrade could you help us out ?

@mikehardy
Copy link
Collaborator

Wow, I tried to reproduce this, I forgot how awfully slow npm is. Can't believe everyone doesn't use yarn, and usually I don't care at all what tools people use. But npm is just...really painfully slow. Waiting on it was the majority of the reproduction time on my machine.

I was unable to reproduce with those commands (which generate an example using react-native 0.63.2, it should be noted, use npx react-native init RNShare837 --version="0.61.4" to get the specified version, and you also need to run npx react-native start at least on my machine, but I couldn't reproduce it there either react-native version)

I think you need to try to reproduce it with the example (and if you can reproduce it, publish that as a github project) so people can see what's wrong. Manual linking is for react-native <= 59, which is more than a year out of date, auto-linking is for everything current and stable, and seems to work for correctly configured projects, with (as far as I remember?) exactly zero reproductions of problems on correct configurations. Could be the first though: reproduce the problem in a repo and we can see

@clems36
Copy link

clems36 commented Aug 4, 2020

Indeed using react-native-share in a brand new project with my react-native version (0.62.2) works.
But still, in my own project i reverted the react-native link changes and re-ran yarn add react-native-share and i'm getting the same error.

When comparing the new project to mine, i see that the new one contains import cl.json.RNSharePackage; and new RNSharePackage() inside android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java(similar to what we would have in old projects after running react-native link), but that file (PackageList.java) is not being created after installing the package in my project.

I'm having a hard time turning my project into a minimal example (sorry about that, been trying for a few hours) because it has a lot of dependencies but it really looks like the package is not being linked correctly.

@MateusAndrade
Copy link
Collaborator

I'm having a hard time turning my project into a minimal example (sorry about that, been trying for a few hours) because it has a lot of dependencies but it really looks like the package is not being linked correctly.

Hi @clems36 , thanks for sharing your insights. I think we can try reproducing that with just the rn-version(which looks to be 62.2), rn-share version and other native dependencies? Would you mind sharing your deps and dev-deps?

Also, if you try installing the project without react-native link you still get the same error?

@clems36
Copy link

clems36 commented Aug 4, 2020

Hi @MateusAndrade , thank you for answering.

if you try installing the project without react-native link you still get the same error

Indeed, i've tried that in the first place but then still tried to link because someone suggested that above.

Here are my dependencies; the react-native version of https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz is 0.62.2.

"dependencies": {
    "@accountable-computations": "git+ssh://git@bitbucket.org:accountableapp/computations.git#1.0.4",
    "@emotion/core": "^10.0.28",
    "@emotion/native": "^10.0.27",
    "@kazzkiq/react-native-modalbox": "^2.1.0",
    "@react-native-community/cameraroll": "^4.0.0",
    "@react-native-community/netinfo": "5.9.2",
    "@react-native-community/viewpager": "3.3.0",
    "@welldone-software/why-did-you-render": "^4.1.1",
    "accounting": "^0.4.1",
    "apisauce": "^0.14.1",
    "babel-plugin-convert-to-json": "^0.1.0",
    "buffer": "^5.2.1",
    "bugsnag-react-native": "^2.23.2",
    "color": "^3.1.0",
    "d3-shape": "^1.2.2",
    "deep-diff": "^1.0.2",
    "expo": "^38.0.0",
    "expo-ads-facebook": "~8.3.0",
    "expo-analytics-amplitude": "~8.2.1",
    "expo-asset": "~8.1.7",
    "expo-branch": "~2.2.1",
    "expo-constants": "~9.1.1",
    "expo-font": "~8.2.1",
    "expo-image-picker": "~8.3.0",
    "expo-linear-gradient": "~8.2.1",
    "expo-linking": "^1.0.3",
    "expo-local-authentication": "~9.1.1",
    "expo-localization": "~8.2.1",
    "expo-notifications": "~0.3.3",
    "expo-permissions": "~9.0.1",
    "expo-splash-screen": "^0.3.1",
    "expokit": "^38.0.0",
    "fuse.js": "^3.3.0",
    "googleapis": "39",
    "hoist-non-react-statics": "^3.3.0",
    "ibantools": "^2.0.0",
    "jsvat": "MattivdWeem/jsvat#4708b26",
    "lodash": "^4.17.4",
    "lottie-react-native": "~2.6.1",
    "memoize-one": "^5.1.1",
    "mime": "^2.3.1",
    "mobx": "^3.3.1",
    "mobx-persist": "^0.4.1",
    "mobx-react": "^4.3.3",
    "moment": "^2.19.1",
    "numeral": "^2.0.6",
    "patch-package": "^6.2.2",
    "postinstall-postinstall": "^2.1.0",
    "prop-types": "^15.6.1",
    "pusher-js": "^5.0.3",
    "ramda": "^0.25.0",
    "react": "16.11.0",
    "react-devtools": "3.6.3",
    "react-dom": "16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    "react-native-android-open-settings": "^1.3.0",
    "react-native-animatable": "^1.2.4",
    "react-native-animate-number": "^0.1.2",
    "react-native-calendars": "^1.300.0",
    "react-native-circular-progress": "^1.3.6",
    "react-native-communications": "^2.2.1",
    "react-native-config": "^0.11.7",
    "react-native-console-time-polyfill": "^1.2.1",
    "react-native-dash": "0.0.9",
    "react-native-device-info": "^5.2.1",
    "react-native-document-picker": "^3.4.0",
    "react-native-easy-toast": "^1.0.9",
    "react-native-fcm": "https://github.com/Accountable-app/react-native-fcm.git",
    "react-native-gesture-handler": "~1.6.0",
    "react-native-haptic-feedback": "^1.10.0",
    "react-native-iap": "^4.5.0",
    "react-native-image-pan-zoom": "^2.1.3",
    "react-native-indicators": "^0.13.0",
    "react-native-intercom": "^13.0.1",
    "react-native-keyboard-aware-scroll-view": "^0.9.1",
    "react-native-linear-gradient": "^2.5.4",
    "react-native-localize": "^1.3.2",
    "react-native-masked-text": "^1.10.1",
    "react-native-modal-translucent": "^5.0.0",
    "react-native-pdf": "^5.1.0",
    "react-native-reanimated": "~1.9.0",
    "react-native-restart": "^0.0.7",
    "react-native-screens": "~2.9.0",
    "react-native-segmented-control-tab": "^3.2.2",
    "react-native-share": "^3.7.0",
    "react-native-signature-pad": "^0.1.0",
    "react-native-snap-carousel": "^3.7.5",
    "react-native-status-bar-height": "^2.0.0",
    "react-native-svg": "12.1.0",
    "react-native-svg-charts": "^5.2.0",
    "react-native-swipe-list-view": "^3.1.3",
    "react-native-swiper": "^1.5.14",
    "react-native-touch-id": "^4.0.4",
    "react-native-unimodules": "~0.10.1",
    "react-native-webview": "9.4.0",
    "react-navigation": "^4.0.10",
    "react-navigation-drawer": "^1.4.0",
    "react-navigation-props-mapper": "^0.4.0",
    "react-navigation-stack": "^1.7.3",
    "react-navigation-tabs": "^1.2.0",
    "react-redux": "^7.2.0",
    "react-transition-group": "^4.3.0",
    "recompose": "^0.30.0",
    "redux": "^4.0.5",
    "redux-debounced": "^0.5.0",
    "redux-form": "^8.2.6",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0",
    "relative-date": "^1.1.3",
    "remote-redux-devtools": "^0.5.13",
    "reselect": "^4.0.0",
    "rn-fetch-blob": "^0.12.0",
    "string-format": "^2.0.0",
    "util": "^0.10.3",
    "validator": "^10.8.0",
    "zxcvbn": "^4.4.2"
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "@babel/plugin-proposal-class-properties": "^7.5.5",
    "@babel/plugin-proposal-decorators": "^7.4.4",
    "@babel/plugin-transform-flow-strip-types": "^7.4.4",
    "@babel/runtime": "^7.4.5",
    "@commitlint/cli": "^7.5.2",
    "@commitlint/config-conventional": "^7.5.0",
    "@emotion/styled-base": "^10.0.31",
    "@emotion/types": "^0.7.0",
    "@types/enzyme": "^3.10.4",
    "@types/enzyme-adapter-react-16": "^1.0.5",
    "@types/lodash": "^4.14.134",
    "@types/pusher-js": "^4.2.2",
    "@types/react": "~16.9.41",
    "@types/react-native": "~0.62.13",
    "@types/react-native-communications": "^2.2.1",
    "@types/react-native-indicators": "^0.13.3",
    "@types/react-native-modalbox": "^1.4.8",
    "@types/react-native-svg-charts": "^5.0.2",
    "@types/react-navigation": "^3.0.7",
    "@types/react-redux": "^7.1.0",
    "@types/react-transition-group": "^4.2.4",
    "@types/recompose": "^0.30.7",
    "@types/redux-form": "^8.2.0",
    "@types/string-format": "^2.0.0",
    "ava": "^0.23.0",
    "babel-cli": "^6.26.0",
    "babel-eslint": "^10.0.1",
    "babel-jest": "23",
    "babel-plugin-module-resolver": "^4.0.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-dirname-filename": "^1.1.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-expo": "^8.2.3",
    "chai": "^4.2.0",
    "del": "^4.1.1",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.15.1",
    "eslint": "^7.5.0",
    "eslint-config-airbnb": "^18.2.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-import-resolver-babel-module": "^5.1.0",
    "eslint-plugin-class-property": "^1.1.0",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-native": "^3.6.0",
    "expo-cli": "^3.1.0",
    "husky": "^1.3.1",
    "jest-expo": "^38.0.0",
    "jetifier": "^1.6.4",
    "mockery": "^2.1.0",
    "nyc": "^11.2.1",
    "prettier": "^1.13.7",
    "react-addons-test-utils": "^15.6.2",
    "react-native-debugger-open": "^0.3.15",
    "react-native-mock": "^0.3.1",
    "react-native-scripts": "1.12.0",
    "react-native-typescript-transformer": "^1.2.12",
    "react-test-renderer": "16.8.3",
    "reactotron-react-native": "^3.2.2",
    "reactotron-redux": "^3.1.0",
    "sinon": "^7.5.0",
    "snazzy": "^7.0.0",
    "standard": "10.0.3",
    "tslint": "^5.16.0",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "~3.9.5"
  }

@MateusAndrade
Copy link
Collaborator

Thank's @clems36. I saw that you are using expo, and I don't know if we are able to use react-native-share with expo out fo the box. 🤔

But let me understand: when you remove react-native-share, you are able to run your project. But when you add this dependency doesn't matter which version you start facing this error?

Also, did you try the sharing module from expo? Maybe this can attend your needs while we try to find what's happening.

@clems36
Copy link

clems36 commented Aug 4, 2020

Yes, no matter the version i'm facing that error when importing Share.

Also, did you try the sharing module from expo?

Well, I just found out about that one haha, thank you! I'm guessing that module will probably work better in my environment, even though it seems to have way less features that yours (but hopefully that will be enough). I will try with that one and keep you posted!

@clems36
Copy link

clems36 commented Aug 4, 2020

After hitting a few walls, i was able to successfully use expo-sharing. I'm missing a couple of feature but that will do for now.
I also believe that getting out of ExpoKit in favour of a bare expo project will allow me to come back to react-native-share in the future. Thanks for your help @MateusAndrade !

@RealDyllon
Copy link

RealDyllon commented Aug 11, 2020

To anyone who has this issue on bare react native, or the "bare" expo workflow, installing pods and restarting metro server resolved it.

@andrew1404
Copy link

I got this error when I tried to include v3.8.0 in my Android project. What worked for me to overcome it:

npm uninstall react-native-share
npm install react-native-share@3.3.2
react-native link react-native-share

Why 3.3.2? -> I was using this version successfully in another project a few months ago. I dunno whether it was the version, or the manual link, or something else which resolved it. Hope it helps.

@kcchan1680
Copy link

I had the same problem, I linked the library manually (react-native link react-native-share) and it worked. Still haven't tested on iOS but I believe it should also be resolved there.

Hi, I have same issues on react-native-share@4.0.2, May I know how to link the library manually (react-native link react-native-share), I don't know how to do this? Can you teach me, thanks

@stale
Copy link

stale bot commented Jan 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and i will leave this open.

@stale stale bot added the stale There has been a lack of activity on this issue and it may be closed soon. label Jan 6, 2021
@stale
Copy link

stale bot commented Jan 13, 2021

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

@stale stale bot closed this as completed Jan 13, 2021
@twp520
Copy link

twp520 commented Feb 3, 2021

hey guys, on IOS, Add the following line of code to the Podfile file:
pod 'RNShare', :path => 'xxx/node_modules/react-native-share/RNShare.podspec'
then run pod install , now it's right.

@mikehardy
Copy link
Collaborator

@twp520 so you would have people ignore they have an auto-linking problem and manually link, despite that not being necessary at all over react-native 0.60? That does not seem like sound advice. Your project has a problem I think, which should be fixed, so auto-linking works

@Isaacmeedinaa
Copy link

Has anyone fixed this?

@karna419
Copy link

Still not clear if this library will work in expo. I want to share post image with text on Facebook. Is there any workaround? thanks

@mikehardy
Copy link
Collaborator

@karna419 if you use Expo, stick with Expo docs https://docs.expo.dev/versions/latest/react-native/share/

In general if you use Expo, whatever native module you want (this one or any other one) probably won't work unless you eject or switch to a non-managed workflow or whatever method they employ in the future.

@karna419
Copy link

karna419 commented Oct 2, 2021

Hi. Thanks for your guidance. I did expo eject. Now I can be able to share.

@iheidari-aci
Copy link

I had the same issue with android. What solved my problem was to follow the manual installation of react-native-share:
https://react-native-share.github.io/react-native-share/docs/install#manual-linking

@Souvik4444
Copy link

for me, just closing the app and rebuilding using 'react-native run-android' worked.

@GaryGiebler
Copy link

None of the above solutions or any others I've found work for me.
I'm still failing on Android - works great on iOS.

@mikehardy
Copy link
Collaborator

@GieblerGary there's no other way to say it: your auto-linking is broken on android then, or you somehow are not building out the native code that you think you are building out, for android. If autolinking is working and you have actually built and installed react-native with this module installed, the native module will be there. Carefully examine the top and bottom of your build.gradle to make sure auto-linking is there

https://github.com/facebook/react-native/blob/e23520bb567f5956b59fb5381ff4de3f1caaaf4f/template/android/app/build.gradle#L84
https://github.com/facebook/react-native/blob/e23520bb567f5956b59fb5381ff4de3f1caaaf4f/template/android/app/build.gradle#L316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs more info stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests