project 'YourProject.xcodeproj' to your Podfile target definition.Why this happens
CocoaPods expects exactly one Xcode project (.xcodeproj) in the directory where you run pod install. When it finds zero or more than one, it cannot automatically determine which project should receive the Pods integration, so it aborts with the error:
[!] Could not automatically select an Xcode project. Specify one in your Podfile like so:
project 'path/to/Project.xcodeproj'
Common causes include:
- An old or backup
.xcodeprojfile left in the project root alongside the current one. - A workspace (
.xcworkspace) already exists from a previouspod install, but the project file was renamed or moved. - The Podfile sits in a subfolder (for example, a monorepo with multiple apps) and CocoaPods cannot infer the correct project path.
How to fix it
1. Remove duplicate or stale .xcodeproj files (most common fix)
- Open your project folder in Finder.
- Look for any
.xcodeprojfiles besides the one you actually use. - Move the unwanted ones to Trash (or rename them with a
.bakextension if you want a safety net). - Run
pod installagain.
Why this works: CocoaPods scans the current directory for
*.xcodeproj. If it finds exactly one, it uses that project automatically. Removing the extra file restores the single-project expectation.
2. Explicitly declare the project in your Podfile
If you intentionally keep multiple Xcode projects (for example, a framework project and an app project in the same repo), tell CocoaPods which one belongs to each target.
# Podfile
platform :ios, '15.0'
use_frameworks!
target 'Posting' do
project 'Posting.xcodeproj' # <-- add this line
pod 'ALCameraViewController'
end
Replace Posting.xcodeproj with the actual filename of your project. After editing, run pod install.
Tip: The argument to
projectis a path relative to the Podfile. If your project lives in a subdirectory, useproject 'Subfolder/MyProject.xcodeproj'.
3. Ensure you are running pod install from the correct directory
If your Podfile is inside a subfolder (common in monorepos), cd into that folder before running the command:
cd path/to/subfolder/containing/Podfile
pod install
Running from the repo root when the Podfile is deeper will cause CocoaPods to scan the wrong directory.
How to prevent it
- Keep only one
.xcodeprojfile in the directory that holds your Podfile. - If you rename your Xcode project, update the
projectline in the Podfile at the same time. - Add the Podfile and the
.xcodeprojreference to version control so the whole team uses the same structure. - Avoid copying or backing up
.xcodeprojfiles inside the project root; use Git history instead.
FAQ
Does this error appear after upgrading Xcode or CocoaPods?
It can. A version upgrade might change how CocoaPods discovers projects, but the root cause is still multiple or missing .xcodeproj files in the working directory. Apply the same fixes.
Can I have multiple targets in one Podfile pointing to different projects?
Yes. Each target block can have its own project declaration:
target 'App' do
project 'App.xcodeproj'
pod 'Alamofire'
end
target 'Framework' do
project 'Framework/Framework.xcodeproj'
pod 'SwiftyJSON'
end
What if I already have a .xcworkspace and still get the error?
The workspace is generated after a successful pod install. The error happens during the analysis phase before the workspace is created or updated. Fix the project selection first, then pod install will regenerate the workspace correctly.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
