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

1

6

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?

Reft answered 8/2, 2019 at 12:43 Comment(0)
F
8

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
    

enter image description here

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.
Forgotten answered 8/2, 2019 at 12:50 Comment(3)
"Select your scheme on the top left; Select edit scheme" is an extremely unclear way of telling people to go to the "Product -> Scheme -> Edit scheme..." menu. The official Apple docs are also unclear about this exact thing, so it takes a bunch of searching to figure this out. Please clarify.Doublereed
You are completely right, could have been clearer. What I meant for top left is the icon on the top left of Xcode, besides play and stop buttons. But will edit with your feedback @AndrewKosterForgotten
the issue, is that sleep, or wait will cause Xcode to stop the buildNam

© 2022 - 2024 — McMap. All rights reserved.