Do we need to run `pod install` with React Native 0.60? - reactjs

I'm using React Native 0.60.5 and am linking this module. It says that for React Native 0.60+, "CLI autolink feature links the module while building the app", so all we need to run is yarn add #react-native-community/async-storage.
However, on the main page describing autolinking it says that we need to run:
yarn add #react-native-community/async-storage
cd ios && pod install && cd ..
What I Want To Know:
Do we have to run pod install for all native modules with React Native 0.60+?

There are 2 types of linking in react-native
1 ) Manual linking
2 ) Pod linking
As described in official site
"If your iOS project is using CocoaPods (contains Podfile) and linked library has "podspec file", then react-native link will link library using Podfile."
Now when you
react-native link
If you project has CocoaPods (contains Podfile) and linked library has podspec file then it will add pod path of linked library in podfile like this
pod 'RNImageCropPicker', :path => '../node_modules/#react-native-community/async-storage'
But you still have to run pod install command
If project does not have pod file or linked library does not have podspec file then you have to do manual linking as described in site
Now coming to question from react-native 0.60 this process is now automatic. You do not have to run "react-native link " . It will automatically do pod work for you when you install library using npm/yarn but still you have to run "pod install" command

Related

React Native 'autolinks' module that I removed

I have react-native-sharing-winstagram in my React Native project. I tried to remove all references to it in the project: I removed it from 'package.json', did yarn install and cd ios && pod deintegrate. I searched through the project and didn't find any remaining references to the package. I did pod install and it said:
Auto-linking React Native modules for target <main target>: BVLinearGradient, RNFirebase, RNReactNativeSharingWinstagram, ...
RNReactNativeSharingWinstagram is causing problems, and I can't figure out how to totally remove it. What can I do besides remove it from package.json?

yarn link to a <relative-path>

I'm using yarn to develop local lib for React. because you can't run 2 versions of React I'm usually doing npm link ..\node_modules\react in the test project to use the same react version as my linked package.
but I don't want to use npm, so I tried yarn link ..\node_modules\react which does not work, and also the docs does not mention an option to do so.
I need to cd ..\node_modules\react and then yarn link then I could do yarn link react - but wants to avoid it, because who knows how many projects will need different versions of React.
so, there is a way to yarn link a directory that includes package.json file(yarn link <relative-path>)?

pod is not recognized as an internal or external command in react native

I've installed image picker in my react native project and i am going to link the package in ios
I run these commands:
cd ios && pod install
But i'm getting this error:
pod is not recognized as an internal or external command
I am coding in windows 7 and my react native version is: "0.61.5"
How can i fix this?
pod is command for Cocoapods, dependency manager for xcode project, so it means that cocoapods is expected to be running on macOS. However if you want to try, you can see this article about running pod commands on windows.
In windows you add path of npm module (C:\Users\your user name\AppData\Roaming\npm) to system variables instead of user variables
In Mac or Linux:
Try installing react-native-cli globally by
npm install -g react-native-cli

What exactly does `pod install` do in react-native's autolinking?

I'm using React Native 0.61, and have been reading about the new auto-linking feature. If you have any insight on ANY of the following questions, I'd appreciate it.
My Questions Are:
1) My understanding of react-native link <module> is that it adds a line for <module> to your Podfile, and then you run pod install. However, for the last year I've been using react-native link and linking manually, and have never run pod install. So am I right that react-native link does more than just add lines to your Podfile?
2) In the past, when react-native link failed to link the module, I manually linked it by dragging the .xcodeproj and .a files into Xcode as described here. Does react-native link (when it works) add the line to your Podfile AND add .xcodeproj and .a files into Xcode for you?
3) Is there anything involved in native modules being linked other than the .xcodeproj and .a files being added to Xcode?
4) What exactly does pod install do? Does it take all the native modules referenced in your Podfile and add .xcodeproj and .a files into Xcode? If so, that would involve two steps: adding the line to your Podfile and then running pod install. Why not just react-native link?
5) My understanding of auto-linking is that it adds lines for all native modules to your Podfile, and then you still have to run pod install. Isn't this just accomplishing the same thing as react-native link?
6) In this guide to auto-linking, it says "Autolinking is a replacement for react-native link. If you have been using React Native before version 0.60, please unlink native dependencies if you have any from a previous install.". Why does it tell you to unlink? If the module is already linked, what will unlinking it and re-linking it do? This implies there's a difference between the way modules are linked with react-native link and via auto-linking. What happens if you auto-link and then pod install, and then try using react-native link, or vice versa?
7) I outlined this in the previous questions, but just to make it concise, what is the difference between auto-linking + pod install and react-native link?
All of your questions are closely intertwined so I'm going to just give you the details that will hopefully clear up things for you.
If React Native version <= 0.59 AND Cocoapods is NOT used in
the project :
react-native link will just add the .xcodeproj file and the .a file to the XCode Project. It will NOT add any lines to the Podfile because in this case, the Podfile doesn't exist.
If React Native version <= 0.59 AND Cocoapods is used in the
project :
react-native link will add the lines to the Podfile and install pods. It will NOT add .xcodeproj or .a file to the XCode Project. This is assuming that the library supports Cocoapods installation. How do you know if the library supports Podfile installation ? They mention it on their Github page/NPM page. Also, such libraries will have a .podspec file as well.
Example : https://github.com/react-native-community/react-native-device-info
See that this library has a .podspec file -> RNDeviceInfo.podspec. So this supports Cocoapods installation.
If the library doesn't support Cocoapods installation, react-native link will just add xcode.proj and .a file to the XCode Project like the above case.
If React Native version >= 0.61 (Cocoapods is default in this case)
react-native link is NOT required anymore.
You just install the library (yarn add or npm install)
And then do pod install.
What happens here is, Cocoapods grabs the library from the node_modules folder, checks if there is a .podspec file and then installs the pods. But it DOESN'T add any lines to the podfile. This is auto-linking that's been introduced in React Native version 0.60.
In case of older libraries that DO NOT have a .podspec file, you need to manually link the library by react-native link.

error while trying to install react-native -floating-action

when I'm trying to install some package
like:
react-native-floating-action
or:
react-native-action-button
I'm running the
npm i react-native-floating-action --save
and when I run react-native link
i get this error:
PS C:\Projects\projectname> react-native link
rnpm-install info Linking assets to ios project
rnpm-install ERR! Something went wrong while linking. Error: Cannot read property 'pbxprojPath' of null
Please file an issue here: https://github.com/facebook/react-native/issues
Cannot read property 'pbxprojPath' of null
TypeError: Cannot read property 'pbxprojPath' of null
at Object.linkAssetsIOS [as copyAssets] (C:\Projects\projectname\node_modules\react-native\local-cli\link\ios\copyAssets.js:24:41)
at C:\Projects\projectname\node_modules\react-native\local-cli\link\link.js:104:12
at Array.forEach (<anonymous>)
at linkAssets (C:\Projects\projectname\node_modules\react-native\local-cli\link\link.js:94:28)
at C:\Projects\projectname\node_modules\react-native\local-cli\link\link.js:171:30
these are my versions:
react-native-cli: 2.0.1
react-native: 0.57.1
npm --version
6.4.1
expo --version
2.6.14
Expo does not support linked binaries. If you require linked binaries, you must first Eject from Expo to ExpoKit or initialize your project using react-native init MyProjName
Reference
If you know that you'll eventually need to include your own native code, Expo is still a good way to get started. In that case you'll just need to "eject" eventually to create your own native builds. If you do eject, the "Building Projects with Native Code" instructions will be required to continue working on your project.
https://facebook.github.io/react-native/docs/getting-started.html
This worked for me:
npm update
react-native link
Eventually, I found the problem,
I needed to run react-native upgrade, and had a different version of react-native in the package.json from the node_modules
writing ^0.57.8 (current react-native version) on the packge.json:
"react-native": "^0.57.8",
running npm install
setting a name for the project in the package.json:
"name":"somename"
and running
react-native upgrade
react-native link
everything was ok
seems to me that it's always a matter of versions with react-native errors

Resources