Getting a (null) reference in the Xcode pbxproj file
Asked Answered
Z

6

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.

Zest answered 16/11, 2017 at 20:23 Comment(3)
Is there an actual problem here? Is the project misbehaving in some way?Tiki
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.Zest
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.Thriller
R
41

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

sed -i '' '/(null) in Sources /d' YOURPROJECT.xcodeproj/project.pbxproj
Roulade answered 20/6, 2018 at 18:51 Comment(1)
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!Habergeon
S
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
Stefa answered 30/9, 2020 at 12:41 Comment(2)
Used this and it worked like charms.Somebody
1. Should I save it with extension .sh? Like: remove_null_pbxproj.sh? 2. where should I keep this file? 3. What terminal command should I run to execute the file? 4. You mentioned about giving execute permission, how to do so?Gymnasiarch
C
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.

Clayborn answered 4/6, 2018 at 13:43 Comment(1)
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.Zest
V
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.

Vantassel answered 5/5, 2022 at 1:30 Comment(0)
W
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.

Wilda answered 17/10, 2022 at 12:4 Comment(0)
U
0

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

Unhook answered 3/10, 2023 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.