Xcode 5 Build With Post Action

I build the library(SDK) file for iOS. I have a one problem. That is to support both simulator and device. After building both simulator and device , I need to do

  1. copy the files from Debug-iphoneos folder to release folder
  2. change mylib.a to mylibDevice.a
  3. copy mylib.a from Debug-iphonesimulator folder to release folder
  4. change mylibSimulator.a
  5. After that merge with lipo -create mylibDevice.a mylibSimulator.a -output mylib.a

I always need to do when release the library.

It’s really troublesome for doing many time.

So, I decided to create the script in post-action.

Go to the Product > Scheme > Edit Scheme.

And then Duplicate Scheme because we will only do post action when it ready to release. Give a name , release build.

Chose the release build scheme and Build > Post Action.

post action

Click the + icon.

plus icon

Need to choose the target build in Provide build setting from .

I create a script like that

rm -r ~/Desktop/mylib
mkdir ~/Desktop/mylib
mkdir ~/Desktop/mylib/Device+Simulator
mkdir ~/Desktop/mylib/Device

cd ..
cd Debug-iphoneos
cp mylib.a ~/Desktop/eb/Device+Simulator/mylibDevice.a
cp -r mylib.bundle ~/Desktop/eb/Device+Simulator/mylib.bundle
cp -r usr ~/Desktop/eb/Device+Simulator/usr

cp mylib.a ~/Desktop/eb/Device/mylib.a
cp -r mylib.bundle ~/Desktop/eb/Device/mylib.bundle
cp -r usr ~/Desktop/eb/Device/usr

cd ..
cd Debug-iphonesimulator
cp mylib.a ~/Desktop/eb/Device+Simulator/mylibSimulator.a

cd ~/Desktop/mylib/Device+Simulator
lipo -create mylibDevice.a mylibSimulator.a -output mylib.a
rm mylibSimulator.a
rm mylibDevice.a

After ready to publish , I built the app that use mylib static library project for both device and simulator.

And then choose the release build and build again.

After that I got mylib static library on my desktop. Nothing to do anymore and ready to use.

comments powered byDisqus