1

I am going to lose my mind over this soon, but here it goes :-)

I am wanting to use RevenueCat/react-native-purchases in my project, but as soon as I import

import Purchases from 'react-native-purchases';

I get the message "Native module cannot be null"

I have a test repo with a bare project where I can't get it to work either

You can see in the repo the package.json and the Podfile - I am using yarn to put it all together.

I have added libRNPurchases.a to my project in Xcode and I have redone these instructions so many times :-$

For a quick reference here is my package.json file

{
  "scripts": {
    "postinstall": "jetify",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "expo": "^35.0.0",
    "react": "16.8.3",
    "react-dom": "16.8.3",
    "react-native": "0.59.10",
    "react-native-gesture-handler": "~1.3.0",
    "react-native-purchases": "^2.4.1",
    "react-native-reanimated": "~1.2.0",
    "react-native-screens": "1.0.0-alpha.23",
    "react-native-unimodules": "~0.5.4",
    "react-native-web": "^0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.6.0",
    "babel-jest": "24.9.0",
    "jest": "24.9.0",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "private": true
}

The PodFile is:

platform :ios, '11.0'

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

target 'IAPTEST2' do
  # Pods for IAPTEST
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTBlob',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
  ]

  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  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'

  use_unimodules!

  pod 'RNPurchases', :path => '../node_modules/react-native-purchases'

  pod 'Purchases', '~> 2.6'

end

I am using React-Native "0.59.10" because of expo - so it is still using the old pod file format.

Any ideas what I need to do?

jwknz
  • 6,598
  • 16
  • 72
  • 115
  • 1
    Something is wrong with your native linking. Don't perform manual linking if you are adding it in cocoapods. – Sanyam Jain Oct 06 '19 at 08:37
  • How do I check what is linked natively? I unlinked the `react-native-purchases` but it doesn't make a difference – jwknz Oct 06 '19 at 08:50
  • Remove it from `Linked Frameworks and Libraries` in xcode and then do `rm -rf Pods Podfile.lock` in ios folder and then do pod install. – Sanyam Jain Oct 06 '19 at 09:10
  • mmm that doesn't really work - the docs say to add it to the `Linked Frameworks and Libraries` so what will that achieve? – jwknz Oct 06 '19 at 09:34
  • Doc also mentions `If you choose to install the framework via CocoaPods you can skip steps 1 through 4 below.` – Sanyam Jain Oct 06 '19 at 09:59
  • I cloned your repo and I have just done npm install, then pod install in the ios folder, and then run the xcode project, and everything works on my end. I am not running Catalina but I am running Xcode 11. If you are running pod install you should not have to do any of the extra steps and the libRNPurchases.a should automatically be added to the Frameworks, Libraries and Embedded content section. I would suggest unlinking, cleaning all the pod cache (you could even do a pod deintegrate) and then linking again. – Cesar Oct 07 '19 at 17:38

0 Answers0