1

In my project i have Frameworks different for iPhone Simulator and iPhone Device for example like in Rest kit "libRestKit_simulator.a" for simulator and "libRestKit.a" for device,

My requirement is to write a "Run Script" in Xcode to include the frameworks based on the Simulator or device.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
kiri
  • 1,977
  • 5
  • 27
  • 55

1 Answers1

2

Not sure if this is the best solution but it appears to work for me.

If you add a build script below target dependancies then add in the following code. This assumes you have 2 libraries

  1. library.a
  2. library_simulator.a

The project would be set up to use library.a and if you are using the simulator the script will remove library.a and replace it with library_simulator.a. You would need to add the simulator to your build scheme to make sure it is built when doing a build and both libraries would need the same interface.

if [[ "${SDKROOT}" == *Simulator* ]]
then

    if [[ -f "${BUILT_PRODUCTS_DIR}/library.a"]]
    then
        rm -rf "${BUILT_PRODUCTS_DIR}/library.a"
    fi

    mv "${BUILT_PRODUCTS_DIR}/library_simulator.a" "${BUILT_PRODUCTS_DIR}/library.a"
fi

Not sure how much use this is to you, I only tested it briefly. Hope it helps.

Rob Gill
  • 327
  • 1
  • 10
  • Rob, I tried to change ur code to use for "RestKit" like this, if [[ "${SDKROOT}" == *Simulator* ]] then if [[ -f "${BUILT_PRODUCTS_DIR}/libRestKit.a"]] then rm -rf "${BUILT_PRODUCTS_DIR}/libRestKit.a" fi mv "${BUILT_PRODUCTS_DIR}/libRestKit_simulator.a" "${BUILT_PRODUCTS_DIR}/libRestKit.a" fi But when i build in Xcode i am getting the error /Users/username/Library/Developer/Xcode/DerivedData/Project-ayvqvnhvwlwekdemwkisegnnowjv/Build/Intermediates/Project.build/Debug-iphonesimulator/project.build/Script-9F52495115B3D745000D929C.sh: line 6: `then' Command /bin/sh failed with exit code 2 – kiri Jul 16 '12 at 05:22
  • Does it tell you what line is causing the error? also check the paths are correct for the libraries as your project setup may be different to how I had it. – Rob Gill Jul 16 '12 at 09:00
  • Rob, I am new to Scripting, i tried to execute line by line code, like first i had given "if [[ "${SDKROOT}" == *Simulator* ]] " Still it is showing error like "syntax error: unexpected end of file Command /bin/sh failed with exit code 2" I changed the "simulator to " to iPhone simulator also still getting error, can u please help me – kiri Jul 16 '12 at 09:18
  • I would guess it won't work from the command line because the variables are xCode specific. There should be more specific error if you open up the log in Xcode. – Rob Gill Jul 16 '12 at 09:22
  • /Users/Username/Library/Developer/Xcode/DerivedData/Project-ayvqvnhvwlwekdemwkisegnnowjv/Build/Intermediates/proj.build/Debug-iphonesimulator/SkyboxMobileSimulator.build/Script-9F50C6DA15B3D7E1001860B4.sh: line 5: syntax error: unexpected end of file Command /bin/sh failed with exit code 2 This is the exact error i am getting – kiri Jul 16 '12 at 09:27
  • Urm not sure what the error is coming from, could you post your version of the script somewhere like paste bin so It's easier to read? – Rob Gill Jul 16 '12 at 09:41