Using different version of lib through cocoapod for different project - ios

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

Related

Installing a react native package with Podfile

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.

How to add native modules in React Native 0.60+?

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

do i need to install alamofire in code if share the code to other system

I have installed alamofire using PODS on my macbook in my current project.
Now if i share same project to some other person, do he/she also need to install alamofire to run the project ?
Thanks
Yes, They have to install pods. If the other user don't have cocoapods. They have to install cocoapods first.
1.First open your terminal
2.Then update your gem file with command
sudo gem install -n /usr/local/bin cocoapods
3.Then give your project path
cd /Path of project
pod install
How are you going to share the project with the other person?
If you're using git the common approach is to have Pods/ directory declared in .gitignore file. In such case the person needs to run pod install after fetching the project. This requires Podfile and Podfile.lock files to make sure that you both work on the same version of the library.
If you simply copy-paste the directory then it's not required at all, as all the files (including workspace and pods) are already attached.
Yes, they will have to install alamofire.
They will have to navigate to the project's root directory and then in their terminal run the following command pod install

Cannot Install Cocoapods - No podfile found in the project directory

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

How do I use CocoaPods correctly

I have some doubt on CocoaPods
I think the 1st rule is that keep Podfile and ignore pods folder entirely. But I am so confused about this after I have used some time
Since I insist on #1, somebody says *.lock should be kept in repo. Do I need do this?
Pods generates some xconfig files, it seem I can't add HEADER_SEARCH_PATH in it ?
if YES, it breaks my rule #1 again. Please see this question the-target-overrides-the-other-ldflags-build-setting-defined-in-pods-pods
some buddies modify codes managed by CocoaPods such as AFNetworking rather than from custom repo. I told him NEVER do this because it will recover to origin version after pod update/install but after pod update/install his code didn't change. that's WHY?
My opinion is DON'T MODIFY EVERTHING IN PODS PROJECT EXCEPT PODFILE
You should always check in your Podfile and Podfile.lock.
Checking in your Pods directory is debatable. If you would like to be able to clone the project and run it without requiring users to have CocoaPods you should check this in. I personally do not check this directory in, instead you just have to run pod install after cloning the project for the first time.
If you want to alter the xcconfig files with changes such as HEADER_SEARCH_PATH you should check this in so those settings don't get overwritten unintentionally. Really the podspec should handle all of these settings so you probably shouldn't be changing much in there.
If you're planning on altering the code included by a Pod you should either check in your Pods folder or fork the repo and redirect it to in your Podfile. Documentation on that here. This way you can specify that CocoaPods uses the given spec but uses your fork instead.
EDIT The Podfile.lock (similar to the Gemfile.lock) stores information on the actual version included during the install. Consider this:
You require a spec like pod 'foo', '~> 1.0.0 in your Podfile.
You run pod install and it installs the newest version of foo matching the semantic versioning conventions (specified by ~>)
You don't check in your Podfile.lock
Another developer clones the repo, the newest version of foo is now 1.0.3.
They run pod install. Version 1.0.3 is installed even though they didn't run pod update.
This information is 'locked' in the Podfile.lock so that to do this you have to run pod update which should be very intentional.

Resources