208

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

 4 years ago
source link: https://sarunw.com/posts/how-to-fix-duplicate-references-warning/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

02 Jan 2021 ⋅ Xcode

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.

Practical Sign in with Apple

Learn everything you need to know about Sign in with Apple to be able to integrate it in your existing app or a new one.

Get it now

Solutions

There are three ways to tackle this.

Update to recommended settings

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.
    skipping-duplicate-autofix.png
  3. Click on the "Update to recommended settings" warning, and you will see a popup dialog show all the changes.
    skipping-duplicate-changes.png
  4. If you see the "Remove Duplicate References in Build Phase" change, accept it by click "Perform Changes," and you are done.
    skipping-duplicate-perform-changes.png

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).
    skipping-duplicate-problem.png

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.
    skipping-duplicate-text-edit.png
  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 SourcesDuplicate 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 ResourcesDuplicate 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 */ = {
...

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.

Related Posts

Browse all content by tag

How to create a new Xcode project without Storyboard

Modify AppDelegate or SceneDelegate to support a non-storyboard approach.

Xcode
How to fix "Build input file cannot be found" error in Xcode

There might be several reasons that cause this error. I will share one solution that fixes the one that happened to me the most.

Xcode

Get new posts weekly

If you enjoy this article, you can subscribe to the weekly newsletter.

Every Friday, you’ll get a quick recap of all articles and tips posted on this site — entirely for free.

← Home


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK