1

Actually based on configuration I want to remove and add one key in Info.plist. To make it dynamic. I have taken approach of Adding a script to accomplish this.

What I tried and what problem I faced is here.

Added a Build Script: Added script using Editor -> Add Build Phase -> Add Run script.

Output: I can see key is deleted in Xcode file but when I am going to see it in iPA key is still there. So, I believe Build system has copied that file before deleting the key. Looks like issue in sequence of executing script.

Pre-Action Build scheme is looks promising.

Problem: I added simple echo statement in Pre-Action script. But I am not able to see it’s output. On few question of stack overflow I found that we can see it on console.app. But I tried lot I am not able to see it in Console.app. I am using Xcode 5.1.1.

Anybody can point out where can I see output of my pre-action script?

External Build System: I also tried this Running script only for an 'Archive' build in Xcode 4

Problem in solution provided in above link:

  1. Not sure how to provide path of script file relative to project
  2. Not able to find environment variable like ${INFOPLIST_File}
Community
  • 1
  • 1
Iducool
  • 3,543
  • 2
  • 24
  • 45
  • In my project I increment CFBundleVersion in Run script just after "Target Dependencies". – Szu Aug 04 '14 at 10:56

1 Answers1

1

It's much better to create a new target using the External Build System template (and make it run the script) and then make the app/library/whatever target dependent on this new target.

That way it will be run before Xcode even touches your Info.plist and there used to be issues with Xcode (in 4.2 if I remember right) where running scripts that modified the Info.plist in a build phase would make it crash.

I use this approach to build spritesheets using the TexturePacker command line and to bump my build number using a python script.

EDIT Here's an example of the settings to use, assuming the script is in a directory called tools (my preferred location) in a sibling directory to the Xcode Project, so:

MyProject/
    MyProject.xcodeproj/
    MyProject/
        (source files)
        MyProject-Info.plist
    tools/
        the_script.sh             (see below)

Then the External Build System would be configured with:

Build Tool: tools/the_script.sh
Arguments: MyTarget1/MyTarget1-Info.plist MyTarget2/MyTarget2-Info.plist
Working Directory: $(SRCROOT)

Then the_script.sh will expect the Info.plist path as its only argument (don't forget to chmod 0755 before running it):

#!/bin/sh

# Don't do anything when cleaning
if [ "$ACTION" = "clean" ]; then
    exit 0
fi

if [ $# -eq 0 ]; then
    echo usage: $0 info-plist \[ ... info-plist \]
    exit 1
fi

while (( "$#" )); do

    plist=$1

    # Do work
    /usr/libexec/PlistBuddy ... $plist

    shift
done
Droppy
  • 9,691
  • 1
  • 20
  • 27
  • Already tried this. Previously question was not formatted properly. But now it is clearly saying what issues I am facing in you mentioned approach. – Iducool Aug 04 '14 at 11:09
  • @Iducool I have updated my answer with some example settings. – Droppy Aug 04 '14 at 11:21
  • Any way to get build dynamic path of plist. As I have lots of targets. I tried to use $INFOPLIST_FILE and $INFOPLIST_PATH. but its not working – Iducool Aug 05 '14 at 07:28
  • That will be similar to the script I used to bump my build number then (except that uses Python) and what I do is pass the path to every `Info.plist` file on the command line and the script iterates through them. Won't be too hard to modify. I'll update my answer. – Droppy Aug 05 '14 at 07:51
  • @Iducool OK updated; the reason you cannot use `$INFOPLIST_FILE` is that the *External Build System* is its own target with potentially its own `Info.plist` file, so you have to explicitly name each `Info.plist` file when invoking the script. – Droppy Aug 05 '14 at 07:57