Is there a way to avoid running `pod install` manually and not commiting Pods directory at the same time? - xcode

On my current project I am asked not to commit my Pods directory, and at the same time, guys want me to 'add some script' to XCode build phases which will run 'pod install' automatically before each installation if needed.
The goal is not to run pod install manually in terminal after you clone the repo.
I have spend a day trying to solve this and I've found a couple of references with no much detail:
iOS using pod install as Pre-action run script for building the project
CocoaPods version control, must use pod install when cloning repo
I've also found out that for CI the same problem is solved by setting actions in .yml file:
Travis-CI is unable to open file
Do you know what this kind of script could look like?

Maybe it would be best if this could be separated in 2 different questions.
But now that we are here already, to avoid the pods directory on your repository, add this line to your .gitignore file:
Pods/
For your second question regarding running pod install. On Xcode:
Click your scheme icon on the top left and select "Edit Scheme..."
Alternatively select from the menu "Product -> Scheme -> Edit scheme..."
In Scheme Window expand "Build"
Select "Pre-actions"
Click on + and choose "New Run Script Action"
Select to provide the build settings from your target
Add the script:
cd ${PROJECT_DIR}
test -e Pods || pod install && sleep 30
Description of the script:
Changes directory to the project's main folder
Checks if there is a file or folder named Pods, if not runs pod install and waits 30 seconds (before continue with the build). You might want to adjust to wait more or less, according to how long you need to wait for the pods to be downloaded.

Related

Swift - Unable to open file in target Xcode 10

I am trying to run Aplication which I have downloaded from GitHub.
When I run get error unable to open file in target, I have Xcode 10.
I already searched for solution and get this one.
I had the same problem, but in Xcode 6.1.1 - what fixed it for me was to change the configuration file setting to None for the two Pods-related targets, then run pod install again.
The configuration file setting is found by selecting the project (not the target) and then the Info tab.
But cant find configuration file location.
Here is the error picture:
https://i.stack.imgur.com/Ql3M5.png
In File -> Project setting -> select Legacy Build System
Make sure you have opened .xcworkspace file and pod installed properly.
A solution I found to work for me was
Inside the project root directory
root
|- <ProjectName>
|- <ProjectName>.xcodeproj
|- <ProjectName>.xcworkspace
|- <ProjectName>Tests
|- Podfile
|- Podfile.lock
|- Pods
Delete the following files. Ensure you have copied the contents of Podfile.
Podfile
Podfile.lock
Pods Folder
Open your .xcodeproj using Xcode or using terminal command
open <ProjectName>.xcodeproj
Inside Xcode, locate the "Pods" folder which should contain something along the lines of...
Pods
|- Pods-<ProjectName>.debug.xconfig
|- Pods-<ProjectName>.release.xconfig
Delete those references and select "move to trash" when prompted.
Close Xcode
Now run the following:
pod init && pod install
Open your Podfile and paste in your previously copied old Podfile that was deleted earlier.
run the following command:
pod install
In terminal open Xcode again with the following command
open <ProjectName>.xcworkspace
Note: that I opened the xcworkspace file NOT the xcodeproj file.
At this point for me I was able to compile my code as normal without having to change back to the Legacy Build System.
Reinstall the pods to get everything cleaned up:
pod deintegrate
pod cache clean --all
pod install
This happened due to change the Project Name or Miss the Pods from Your Project
if the Pods are Miss Then Following Method
open the Project and Command + Shift + K
Close the Project
Open Terminal got to Your Xcode Project Directory cd /your-Xcode-project
if coca pods are already installed so skip this Point if not sudo gem install cocoa pods run this Command on terminal
pod install
If Above Method not Working so its Project name Issue then Go with following Method
First, open your Pod File and change the target
target 'your Xcode project name' do
run the Following Commands from Terminal
go to Your directory from terminal
pod deintegrate
pod clean
pod install
Done now open your xcWorkSpace file
For me it works, update the version of CocoaPods and reinstall the pods
sudo gem install cocoapods
Run following commands after you have downloaded Xcode project from GitHub:
cd /your-xcode-project
pod install
This worked on Xcode 10.2.
I had this issue too with project I cloned from GitLab. Your error looks extremely similar to mine. I solved it by running this in Terminal:
cd path/to/your/project
pod install
When I checked project folder in Finder, there was a Podfile. But same project viewed in Xcode had nothing under 'Pods' module. From this I figured out the pods are not installed (or installed properly?) and installing them solved this error.
If there is some Pods or .xcworkspace file, it might be worth doing pod deintegrate before installation - just to be sure :)
I was facing the same error opening an old project in a new macbook with a recent installation of Xcode and no cocoa pods or anything related on it.
My way to fix this was following some of the steps en the issues #1727 of alamofire and change some things. Open the terminal and cd project where the pod file is.
So, this is what worked for me:
sudo gem install cocoa pods
pod repo remove master
pod setup
pod repo update
pod install
Then just, clean build folder and build the project.
Quit Xcode
Open Terminal
Change to directory (where podfile is present)
pod install
I was trying to do pod install after removing unwanted pod(steps 2,3 & 4), but it still was not working. Quitting Xcode (steps 1, 2, 3 & 5) worked.
If you suddenly start seeing this issue on an existing project, before you try anything else, try
pod update
Make sure your pod build settings looks good
Clean build folder
Retry building
1-
in xcode
menu --> project --> clean build files
2-
close project
3-
in terminal
cd
4-
in terminal
pod update
5-
re-open
project..xcworkspace file
6-
clean, build
good luck
delete file name "Podfile.lock" and try pod install again.
Just stumbled into the issue recently myself. It seems it's a bug in CocoaPods.
Possible fix: gem install cocoapods --pre
I tried below and error went away !!
project name - SwiftExample
Went to Pods -> Info -> Configurations -> Debug
Change to None for Pods-SwiftExample
Code compiles even after setting it back to original.
I can see many solutions already given there. But I believe the easiest way to resolve this problem is
Open the project directory in Terminal
Delete .xcworkspace file
Run pod install
That's it. The newly created .xcworkspace file will work without any problem.
Open your project file (project.pbxproj) and check of 'Pods' is added to the path before the 'Target Support Files' folder. Remove that and i got it to build fine.

Run older commits of project in Xcode

I am using Xcode with source control. Is it possible to select an older commit of the actual project (just like in the Revisions tab) and run it without the need of git cloning?
It's relatively straightforward using the command line.
If the commit you want to target is named 0ad5a7a7, then you can create a new branch via this:
git checkout -b old-project-state 0ad5a7a7
After creating that branch, you can change to it via Xcode's "Switch To Branch" menu item and you can then build it.
Follow this answer
Then additionally you may need to run
pod install
or
bundle exec pod install
based on your project dependency.

Issues with adding a pod file to my Xcode project

I've been trying to create a pod file for my project in my directory using the terminal, but I'm running into the issue shown below, any suggestions?
I tried restarting my Mac and even tried to add one to a different project but to no avail. Also couldn't seem to find any other instances of this occurring.
Here's the terminal output:
Matts-Mac-mini:~ sarabytestudios$ cd /Users/sarabytestudios/Desktop/Blurr\Messenger/Blurr\ Messenger.xcodeproj
Matts-Mac-mini:Blurr Messenger.xcodeproj sarabytestudios$ pod init
[!] No xcode project found, please specify one
Matts-Mac-mini:Blurr Messenger.xcodeproj sarabytestudios$
You have to create your PodFile in the same directory as your Blurr Messenger.xcodeproj.
In your case should be in /Users/sarabytestudios/Desktop/Blurr\Messenger/.
In that directory, create a file called PodFile where you must declare the cocoapods you want to include in your project (you can do it by hand or call pod init). The you must type pod install.
After that, you must open the new generated file called Blurr Messenger.xcworkspace.
1) Run 'pod init' command inside the project directory(directory containing YourProject.xcodeproj file)(This will create a Podfile, a YourProject.xcworkspace file, Podfile.lock file and a Pods folder)
2) Run 'pod install' command inside the same directory.
3)Open your project using YourProject.xcworkspace file and NOT the YourProject.xcodeproj file(otherwise build fails).

Why doesn't source control check in my CocoaPods?

I have a few Cocoapods installed for my project. For one particular pod, KVNProgress, Xcode doesn't commit it to GitHub. Each time I check my project out I get 'can't find KVNProgress.h' blah blah...
So I run 'pod update' from terminal and immediately all is fixed.
After running 'pod update', I check my project navigator and there are no 'A' or 'M' or anything else for that matter indicated a new or modified file. Therefor nothing to commit.
Any ideas how to fix this so I don't have to update the pods each time I check out the project?
You should use the Terminal to figure out if it's an Xcode problem or a git problem.
Run git status --ignored in the project directory. If the Pods directory is shown in the Ignored files section you have to remove Pods from your .gitignore file.
If the files appear in the untracked files section Xcode messed up the git status.
You can use git add . to add all untracked files.
As a side note, I would recommend to use a dedicated git client like SourceTree, GitHub Mac, or Tower instead of Xcode. Xcodes git implementation is not the best (feature wise) and it's a bit buggy.

Trouble installing CocoaPods - already tried solution given elsewhere

I'm having trouble installing CocoaPods. I've already googled for a solution, and followed the answer in How do I select a project in my Podfile? I'm getting the error: Unable to find the Xcode project for the target 'Pods'. Can anyone say what I'm doing wrong?
Michaels-MacBook-Air:~ michael$ cd ~/Documents/Chinese\ Restaurants/
Michaels-MacBook-Air:Chinese Restaurants michael$ pod install
[in /Users/michael]
Analyzing dependencies
[!] Could not automatically select an Xcode project. Specify one in your Podfile like so:
xcodeproj 'path/to/Project.xcodeproj'
Michaels-MacBook-Air:Chinese Restaurants michael$ cd ~/Documents/Chinese\ Restaurants/Chinese\ Restaurants.xcodeproj/
Michaels-MacBook-Air:Chinese Restaurants.xcodeproj michael$ pod setup
Setting up CocoaPods master repo
Already up-to-date.
Setup completed (read-only access)
Michaels-MacBook-Air:Chinese Restaurants.xcodeproj michael$ touch Podfile
Michaels-MacBook-Air:Chinese Restaurants.xcodeproj michael$ open -e Podfile
Michaels-MacBook-Air:Chinese Restaurants.xcodeproj michael$ pod install
Analyzing dependencies
[!] Could not automatically select an Xcode project. Specify one in your Podfile like so:
xcodeproj 'path/to/Project.xcodeproj'
In my case the error was because I had two .xcodeproj files in my Xcode project.
So the solution was remove the unnecessary .xcodeproj file and then doing again
pod install
I tried editing the file in vim, as in https://www.youtube.com/watch?v=9_FbAlq2g9o, and that solved it. Hopefully knowing that is useful to others.
Here's solution. In fact the solution has been shown clearly.
Could not automatically select an Xcode project. Specify one in your Podfile like so:
xcodeproj 'path/to/Project.xcodeproj'
I couldn't understand the tips above.Later I got it.
First,you should run the terminal and cd into the directory of your project.
Second,type "vim podfile" and run.
Third, click button 'i' and change to editing mode.
Fourth,now you can type 'xcodeproj projectname.xcodeproj'
Then,click ESC and type ':wq'. It means save and quit.
In the end,you retype 'pod install' and it will run normally.

Resources