32

Upon updating/bumping up the version and the build # in Xcode version 9.1, I saw the following upon doing git diff

diff --git a/star.xcodeproj/project.pbxproj b/star.xcodeproj/project.pbxproj
index c4601526..8fa3c762 100644
--- a/star.xcodeproj/project.pbxproj
+++ b/star.xcodeproj/project.pbxproj
@@ -767,7 +767,7 @@

- F4487BE11FB28C400079BAAD /* BuildFile in Sources */ = {isa = PBXBuildFile; };
+ F4487BE11FB28C400079BAAD /* (null) in Sources */ = {isa = PBXBuildFile; };

@@ -5625,7 +5625,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- F4487BE11FB28C400079BAAD /* BuildFile in Sources */,
+ F4487BE11FB28C400079BAAD /* (null) in Sources */,);

    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
-       <string>2.11.4</string>
+       <string>2.11.5</string>
      <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
@@ -39,7 +39,7 @@
            </dict>
    </array>
    <key>CFBundleVersion</key>
-       <string>02110400</string>
+       <string>02110500</string>
    <key>FacebookAppID</key>
    <string>70858204300</string>
    <key>FacebookBetaAppID</key>

All I did was bump up the version of the project. But upon doing a git status and a git diff, I see some null references in the .pbxproj file. Has anybody else seen this. As a side-note we also use Cocoapods in our project.

Dee-Bha
  • 439
  • 1
  • 4
  • 8
  • Is there an actual problem here? Is the project misbehaving in some way? – matt Nov 16 '17 at 20:35
  • 1
    I am not sure if there is a problem yet. I am wondering if this null reference might cause one. As of right now I am able to build and run to a device. I haven't archived yet. – Dee-Bha Nov 16 '17 at 21:01
  • 1
    I had similar problem, I notice I'm getting the null-in-sources when files are getting deleted... this at least should give you a clue. – XcodeNOOB Feb 08 '18 at 09:36

5 Answers5

41

Remove all occurrences of (null) in Sources lines in your project.pbxproj:

sed -i '' '/(null) in Sources /d' YOURPROJECT.xcodeproj/project.pbxproj
Uladzimir
  • 3,067
  • 36
  • 30
  • 3
    I did the same for Resources and Frameworks: ``` sed -i '' '/(null) in Sources /d' YourProject.xcodeproj/project.pbxproj sed -i '' '/(null) in Resources /d' YourProject.xcodeproj/project.pbxproj sed -i '' '/(null) in Frameworks /d' YourProject.xcodeproj/project.pbxproj ``` And after rebuild everything was good. Probably worth it to have this in Build Phases, it reduces the amount of code you need to review in PRs. Good answer! – southfox Oct 10 '19 at 11:54
7

I created simple shell script to remove all null references in project file.

Save as file, give execute permission and call it.

#!/bin/sh
sed -i '' '/(null) in Sources /d' ProjectName.xcodeproj/project.pbxproj
sed -i '' '/(null) in Resources /d' ProjectName.xcodeproj/project.pbxproj
sed -i '' '/(null) in Frameworks /d' ProjectName.xcodeproj/project.pbxproj
muhasturk
  • 2,534
  • 20
  • 16
4

I removed all (null) references in project file and all IDs which mentioned with them. Then tried to build run and archive App - all worked fine. Looks like Xcode did not removed them itself by some reason.

In your case try to remove F4487BE11FB28C400079BAAD with (null), and all lines with this F4487BE11FB28C400079BAAD too. And do this with other (null) references.

Nikolay Shubenkov
  • 3,133
  • 1
  • 29
  • 31
  • Thanks for letting me know. This happened to me just once and never again. I will keep the above in mind for when and if it happens again. – Dee-Bha Jun 05 '18 at 19:26
0

Here's an alternative method for removing the lines using Fastlane based on muhasturk's answer.

  desc 'Clean up null references in project.pbxproj file'
  lane :remove_null_references_in_pbxproj_file do
    path_to_pbxproj = '../YourApp.xcodeproj/project.pbxproj'

    ['Sources', 'Resources', 'Frameworks'].each { |section|
      `sed -i '' '/(null) in #{section} /d' #{path_to_pbxproj}`
    }
  end

This assumes you've got a default Fastlane installation in your project, so the we need a relative path up one level from the fastlane folder for the project.

Within Fastlane, you can just call this lane with remove_null_references_in_pbxproj_file. Note the sed command is surrounded by backticks, not single quotes, which is why interpolation works for dumping vars into the command.

Adrian
  • 16,233
  • 18
  • 112
  • 180
0
sed -i '' '/^.*\/\* (null) in.*$/d' *.xcodeproj/project.pbxproj

This is a one command solution that will delete all null references in all folders without needing to edit the command. It just works.

ratbum
  • 1,030
  • 12
  • 29