Keep the watch app away from Release Build

In recent time, My colleague and I have developed a WatchOS App prototype. Then Our boss wanted to merge that POC to the production branch. That means the end users will have a chance to uncover our POC. That shouldn’t happen.

WatchOS app is an extension, it doesn’t stand alone. It basically needs a host app. The WatchOS project usually is a sub-project which eventually its product will be attached to the main app. But XCode doesn’t give us an option to keep the extension out for Release Build. (The release build is the build which will be submitting it to App Store, and reaches out to end users)

Can we do the proccess differently? OK, I’m going to write a tutorial to handle this situation.


First of all, I create a new iOS app project and add an additional target for the WatchOS app. It will look like this

This slideshow requires JavaScript.

I’m going to explain a bit.

  • We see 3 targets on the left-hand side (MyApp is the host app which will attach the WatchApp inside of it)
  • In the project’s build phases, We see 2 sections marked with stars
    • Section 1 – Target dependencies: This section basically triggers building the WatchApp target.
    • Section 2 – Embed Watch Content: This is created by XCode automatically when creating the WatchApp target. What this section will do is embed the WatchApp into MyApp. This is the way We publish the WatchOS App. When building the project, We will find the app which includes the watch folder.


Because We don’t have much control with this section. We can’t customize it like ask it to embed the watch app for DEBUG build only, so We need to remove this section and handle by ourself.


Shell Scripting

This slideshow requires JavaScript.

And then We need a little bit of magic. I have prepared a script to fill out. Please take a look at the script below.

#The script is used to embed Watch App into the mobile app.
#Prepare some directory paths
WATCH_APP_NAME="" # <--- put your watch app name here
#By checking this condition, the script is valid for Debug configuration only
if [ $CONFIGURATION == "Debug" ]
#Check if the directories are valid
if [ -d "${WATCH_APP_DIR}" ] && [ -d "${APP_BUILD_DIR}" ]
#Create a dir if it does not exist
mkdir -p "${DESTINATION_DIR}"
#Attach file to host app
echo "hk >>> Attach ${WATCH_APP_NAME} successfully"
echo "hk >>> Cannot attach the content to host app, because not find ${WATCH_APP_DIR} or ${APP_BUILD_DIR}"

We need some more steps

It is not done yet, We need some more steps:

  • On the top-left corner, click on + icon to add new “copy files phrase”.
  • We must place the “Copy Files” phase ahead of the script section
  • Set the destination to “Absolute Path”, the “Path” value will be $(TARGET_BUILD_DIR)
  • Add the file which we need to copy. Click + icon at the bottom to add, then choose “”

This slideshow requires JavaScript.


Ok, everything is in place, Press the shortcut CMD + R to build the iOS app. You would find the message hk >>> Attach successfully”


One thought on “Keep the watch app away from Release Build

  1. Instead of cp -a,
    prefer using the original copy command :

    builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks “${WATCH_APP_DIR}” “${DESTINATION_DIR}”


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s