Getting a (null) reference in the Xcode pbxproj file

11.7k Views Asked by At

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.

6

There are 6 best solutions below

1
Nikolay Shubenkov On

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.

1
Uladzimir On

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

sed -i '' '/(null) in Sources /d' YOURPROJECT.xcodeproj/project.pbxproj
2
muhasturk On

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
0
Adrian On

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.

0
ratbum On
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.

0
katleta3000 On

Actually, all solutions above fix only the null references in pbxproject, but not the root reason.

If you're using SPM, try to remove .git from the name of the packages and their reference all over the pbxproject. It helped me.

Inspired by the solution from XCRemoteSwiftPackageReference .git suffix constantly changing in project.pbxproj

enter image description here