I'm following instructions here to add a package: https://github.com/joltup/rn-fetch-blob
It says to do npm install OR add to Podfile. What I did was
yarn add rn-fetch-blob
Then
cd ios
pod install
Is that correct? I didn't edit the Podfile but somehow it still knew to get the dependency. Output:
Analyzing dependencies
Downloading dependencies
Installing rn-fetch-blob (0.12.0)
Generating Pods project
Integrating client project
The Podfile doesn't have any reference to rn-fetch-blob. Can someone explain if I did it right or if I needed to edit the Podfile?
When you do pod install, it actually looks into your package.json dependancies to see what dependency requires pod installation. As you have already added it to node_modules but not in Podfile.
Assuming that you are using the latest React Native version like 0.60 and above, this process is simply called Autolinking
Basically, whenever you add a new library to your package.json as you did for rn-fetch-blob and run pod install after adding it, the whole node_modules folder is being scanned thanks to a script file called native_modules.rb to find an appropriate podspec file and install what is necessary to install a pod.
This is the definition of how iOS auto-linking works from the community docs:
Platform iOS
The native_modules.rb script required by Podfile gets the package
metadata from react-native config during install phase and:
Adds dependencies via CocoaPods dev pods (using files from a local
path). Adds build phase scripts to the App project’s build phase. (see
examples below) This means that all libraries need to ship a Podspec
either in the root of their folder or where the Xcode project is.
Podspec references the native code that your library depends on.
Related
I want to use MapBox Search SDK for iOS. So I've followed this official documentation
Firstly, I've created ".netrc" in my /home directory as instruction and then add this -
use_frameworks!
target "TargetNameForYourApp" do
pod 'MapboxSearchUI', ">= 1.0.0-beta.3", "< 2.0"
end
to podfile. Then run pod install and got this in terminal -
Analyzing dependencies
Downloading dependencies
Installing MapboxCommon (9.0.2)
Installing MapboxMobileEvents (0.10.8)
Installing MapboxSearch (1.0.0-beta.4)
Installing MapboxSearchUI (1.0.0-beta.4)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `MapBox.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 4 total pods installed.
[!] Automatically assigning platform `ios` with version `12.1` on target `MapBox` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
But after running all this I'm getting this error in Xcode -
Framework not found MapboxCommon.xcframework
I've also tried this -
pod deintegrate && pod cache clean --all
pod install
but still the same error.
I think I've followed correctly the documentation and entered the secret API Key correctly. So why am I getting this error?
Edit:
In Project Targets the installed pods are not listed -
But In pod folder in Project directory -
there are other frameworks available which are not available in Xcode Pods Target.
Is that the pointing that the frameworks are not available in the projects?
Edit:
I've checked in my project directory if the Mapbox.common.xcfreamework present or not. And I found that file under pod/mapboxCommon folder
I've been opening my project using MapBox.xcworkspace which file was generated after running pod install.
You are facing this error because you are still trying to build the project file (xcodeproj), not the generated workspace by CocoaPods.
To resolve this issue, open up 'MapBox.xcworkspace' file and use that file to access your projects from now on.
I'm trying to understand the difference between the autolinking that exists in React Native 0.60+ and the automatic / manual linking we have in previous React Native versions.
When I add react-native-gesture-handler with npm i react-native-gesture-handler, no lines are added to my Podfile. So when I do pod install, I assume the Gesture Handler module isn't linked. However, if I link it manually as I did with previous React Native versions, by dragging the .xcodeproj files into Libraries etc, it throws an error and tells me to unlink it.
What I Want To Know:
Am I right that what autolinking does is adds a line for the given module to your Podfile, which then gets linked when you pod install? If so, why might it be that when I did npm i react-native-gesture-handler nothing was added to my Podfile? And given that nothing was added and linking the module manually throws an error, how should I link the module?
When you create a new project and react-native version >=60 , this line is automatically added in pod file (official site)
# example/ios/Podfile
require_relative '../../node_modules/#react-native-community/cli-platform-ios/native_modules'
This is path of script , so when you run "pod install" , it will check all libraries and install all pods files required
So when you add new library , no lines are added to my Podfile but you have to run "pod install" so that script file can run and install new pod files .
Please do not use manual linking as described in official site
This means that all libraries need to ship a Podspec either in the
root of their folder or where the Xcode project is. Podspec references
the native code that your library depends on.
The implementation ensures that a library is imported only once. If
you need to have a custom pod directive then include it above the
use_native_modules! function.
You have to do 2 steps
1 : Add library "yarn add react-native-gesture-handler"
2 : cd ios && pod install
I am trying to link the #segment/analytics-react-native library in my iOs react-native project.
I followed these two steps given in their docs.
yarn add #segment/analytics-react-native
yarn react-native link
However the yarn react-native link step doesn't seem to work, as all it does is add a pod in the podfile, and modify some android project files that I don't need.
The project.pbxproj file is showed as modified but when I inspect it inside vs code, the only thing it does in that file is removing a line.
Please explain why is this happening
From the docs about linking
If your iOS project is using CocoaPods (contains Podfile) and linked
library has podspec file, then react-native link will link library
using Podfile.
This means that it will not add the dependencies inside your Xcode project.
If you are happy with this then make sure you cd into you iOS folder and run pod install
If you don’t want it installed via CocoaPods then you can either install it manually using the instructions on the dependencies repo (remembering to delete the line added to your pod file); or you can rename your podfile, run react-native link so it adds the files without the updating the podfile, then rename the podfile back to what it should be.
One further point to note you shouldn’t run react-native link without the dependency name. You should run react-native link <dependency name>. You can end up with duplicate entries and unforeseen issue if you don’t.
I downloaded a sample project to learn how to make a UIPageViewController, and I am trying to essentially fork that project and need to add a third-party library. Right now, it does not look like I have a .xcworkspace file in my project. When I try and install the cocoapods, I first run
sudo gem install cocoapods - in the specific project directory in my terminal
pod install - in that same directory
I am receiving an error in the terminal "No podfile found in the project directory."
Is this happening because I don't have a .xcworkspace file? Am I installing the podfile correctly?
Steps to add CocoaPods to manage dependencies in your project:
sudo gem install cocoapods -> This installs CocoaPods as a piece
of software on your machine.
Go to the root of your project directory and execute pod init ->
This will add a base Podfile to your project.
Add the external dependencies that you have to this Podfile by editing it.
Run pod install which will fetch all the external dependencies
mentioned by you, and associate it with a .xcworkspace file of
your project. This .xcworkspace file will be generated for you if
you already do not have one.
From here on, you should use .xcworkspace file instead of .xcproject / .xcodeproj.
Example Podfile Syntax:
target 'MyApp' do
pod 'AFNetworking', '~> 3.0'
end
Where AFNetworking is the pod and 3.0 is the specific version that I want to install.
Documentation: Using CocoaPods
Just posting for anyone that encountered this issue while working on a react native project.
sudo gem install cocoapods
this installs cocoa pods to your machine
cd projectDirectory cd into your project directory
cd ios cd into the ios directory of your project, is you list items that are in this folder, you would most likely see a podfile there.
pod install
If you want to add a library from GitHub to your own project, after installing gems, do firstly pod init look at from GitHub cocoapod description and then add it after target line in podfile.
Save and run "pod install".
It would be successfully added on your project.
Don't forget to call pod install in the Project folder of your project (not in the root).
Open a terminal, if you use VSCode, you can just run the following from the terminal
Do a cd <project_name> to your flutter project directory
Run cd iOS
Then run pod install
This is a tiny doubt which I want to get clarified.
I have a project which is lets say Project-1 which uses a library of ytr (cocoapod version 0.1.13).
I have another project which is lets say Project-2 which I am planning to use library of ytr (cocoapod version 0.2.0).
Now if I do "pod install" in second project, will this also update the pod which is with "Project-1"?
When you run pod install it is in the context of the Podfile you are referencing. i.e. running pod install in the directory where Project-1 resides will install it's dependencies (and run whatever else you have defined in the podfile) for that Podfile under the $PROJ1_PODFILE_LOCATION\Pods directory
Doing the same for project-2 will install that project's dependencies under its own $PROJ2_PODFILE_LOCATION\Pods directory.
You can see the actual versions it downloaded for each project inside the Podfile.lock file it creates after resolving the dependencies (it's kinda like Gem's Gemfile.lock if you are familiar).
You can read more about this behavior and the Podfile.lock file here