How to fix "Skipping duplicate build file" warning in Xcode

⋅ 4 min read ⋅ Xcode

Table of Contents

There might be several reasons that cause the "Skipping duplicate build file" warning. I will share solutions that fix it for me.

"Skipping duplicate build file" warning

Cause of the problem

When working in a team there always be a merge conflict over project structure. For me I always get merge conflict on project.pbxproj that look something like this:

A000701D256E5ADF009F48A4 /* UsageDetailViewModelTests.swift in Sources */,
17E973942505E3EA0084D10D /* MainTabBarViewModelTests.swift in Sources */,
174BF411251C9C1E00FE6214 /* CommonNotificationIconViewTests.swift in Sources */,
=====
NOT_A000701D256E5ADF009F48A4 /* UsageDetailViewModelTests.swift in Sources */,
NOT_17E973942505E3EA0084D10D /* MainTabBarViewModelTests.swift in Sources */,
NOT_174BF411251C9C1E00FE6214 /* CommonNotificationIconViewTests.swift in Sources */,

It is hard to make this right, and sometimes resolve this wrongly leads to the "Skipping duplicate build file" warnings.

You can spot this issue in Issue navigator, where you can see a file that causes the problem under the warning. If you go to Build Phases of the target problem, you should see duplicate files under Compile Sources or Copy Bundle Resources.

Solutions

There are three ways to tackle this.

This is the easiest way, but it is up to Xcode's mercy whether to show up or not. Most of the time, it will.

  1. Open the "Issue navigator" (Menu View > Navigators > Issues ⌘ - command + 5).
  2. If you see the "Update to recommended settings" warning, good luck to you.
  3. Click on the "Update to recommended settings" warning, and you will see a popup dialog show all the changes.
  4. If you see the "Remove Duplicate References in Build Phase" change, accept it by click "Perform Changes," and you are done.

If you don't see the "Update to recommended settings" warning or the "Remove Duplicate References in Build Phase" change not show up in the popup dialog, you can keep reading for more solutions.

Manually remove the duplicate file within Xcode

  1. Open "Project Navigator" (Menu View > Navigators > Project ⌘ - command + 1).
  2. Select Build Phases under your problem target.
  3. Open Compile Sources or Copy Bundle Resources section based on your warning.
  4. Find the problem files and delete one of them (You should see two files with the same name).

Manually remove the duplicate file within Text Editor

The only problem with the Manually remove the duplicate file from Xcode is for a large project; it is difficult to find the duplicate files. You can also fix this from the project.pbxproj, but make sure you save and commit everything before doing this. Anything can go wrong when you try manually edit project.pbxproj file.

  1. Open project.pbxproj with your preferred text editor.
  2. Search for [FILE_NAME] in Sources.
  3. You might find that in many places. Make sure it is the one under /* Begin PBXSourcesBuildPhase section */ section if your files are in the Compile Sources section and /* Begin PBXResourcesBuildPhase section */ section if your files are in the Copy Bundle Resources section.
  4. Remove one of them.

Duplicate file in Compile Sources

Duplicate files in Compile Sources
Duplicate files in Compile Sources

Search for [FILE_NAME] in Sources under PBXSourcesBuildPhase section

/* Begin PBXSourcesBuildPhase section */
A01010E6259F2F48000747F9 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A01010F2259F2F48000747F9 /* ViewController.swift in Sources */,
A01010EE259F2F48000747F9 /* AppDelegate.swift in Sources */,
A01010F2259F2F48000747F9 /* ViewController.swift in Sources */,
A01010F0259F2F48000747F9 /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
A01010FC259F2F4F000747F9 /* Sources */ = {
....

Duplicate file in Copy Bundle Resources

Duplicate files in Copy Bundle Resources
Duplicate files in Copy Bundle Resources

Search for [FILE_NAME] in Sources under PBXResourcesBuildPhase section

/* Begin PBXResourcesBuildPhase section */
A01010E8259F2F48000747F9 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A01010FA259F2F4F000747F9 /* LaunchScreen.storyboard in Resources */,
A01010FA259F2F4F000747F9 /* LaunchScreen.storyboard in Resources */,
A01010F7259F2F4F000747F9 /* Assets.xcassets in Resources */,
A01010F5259F2F48000747F9 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
A01010FE259F2F4F000747F9 /* Resources */ = {
...

Read more article about Xcode or see all available topic

Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.

If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.

Become a patron Tweet Share
Previous
How to convert a String to an Int in Swift

Learn to convert a string "123" to an integer 123.

Next
How to change the color of SF Symbols

SF symbols are icon sets that Apple design to work with their system font. Learn how to change its color and how to show them in multicolor style.

← Home