Can you change info.plist inside a Run Script in Xcode's Build Phase?
Asked Answered
P

2

1

I'm trying to add a value to my Info.plist inside a Build Phase Run Script:

/usr/libexec/PlistBuddy -c "Add :BuildDate date `date`" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"

# For debugging:
cat "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}" | grep BuildDate

This works (as proven by the cat), but it seems the result is almost immediately overwritten afterwards, by some other Xcode build step.

Is it simply not possible to modify the Info.plist in the Build Phase? I've seen numerous suggestions around the web to do exactly that.

Property answered 12/11, 2021 at 8:2 Comment(1)
I also tried ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}; like the above, I can see it added to the plist in the compiled app, but just prior to the build completing, the new entry disappears.Property
C
2

I assume you're trying to modify the Info.plist (and not a plist.info as I don't know what that is).

It's absolutely possible to create, modify, or delete the Info.plist during the Build Phase. However, you need to do so before the build process needs to make use of Info.plist. The exact timing of this varies, but the earlier the better - I'd recommend doing so right after the Dependencies step.

I have a sample Xcode project that does this for a macOS app and a macOS Command Line Tool. It's considerably more complicated than what you're likely trying to do, but it might be helpful to take a look and see how it's configured.

Cellobiose answered 20/11, 2021 at 1:43 Comment(1)
Marking this as the accepted answer as it is an accurate answer to my question as it was asked, complete with a repo providing evidence to study, thanks! However I guess more pertinent to me, and others with the same issue, is why it doesn't work in specific circumstances and/or what can be done to coax it to do so. I believe I have discovered one or two things in this regard so will add another answer describing them.Property
P
6

So I never did really discover exactly why this doesn't work for me but does for others. However, I did come across a post which resolved the issue for me. The solution is to add the Info.plist file as an input file in your Build Phase.

${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}

Xcode config screenshot

Property answered 15/12, 2021 at 7:25 Comment(1)
In Xcode 15.0 beta I was running into the issue where my build increment script was causing the build to fail because of a sandbox issue. Adding the info.plist file in the input files field fixed it for me. Bravo!Jolley
C
2

I assume you're trying to modify the Info.plist (and not a plist.info as I don't know what that is).

It's absolutely possible to create, modify, or delete the Info.plist during the Build Phase. However, you need to do so before the build process needs to make use of Info.plist. The exact timing of this varies, but the earlier the better - I'd recommend doing so right after the Dependencies step.

I have a sample Xcode project that does this for a macOS app and a macOS Command Line Tool. It's considerably more complicated than what you're likely trying to do, but it might be helpful to take a look and see how it's configured.

Cellobiose answered 20/11, 2021 at 1:43 Comment(1)
Marking this as the accepted answer as it is an accurate answer to my question as it was asked, complete with a repo providing evidence to study, thanks! However I guess more pertinent to me, and others with the same issue, is why it doesn't work in specific circumstances and/or what can be done to coax it to do so. I believe I have discovered one or two things in this regard so will add another answer describing them.Property

© 2022 - 2024 — McMap. All rights reserved.