Skip to content

Instantly share code, notes, and snippets.

@mxpr
Last active January 14, 2016 23:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mxpr/ff29b55242e81873f83d to your computer and use it in GitHub Desktop.
Save mxpr/ff29b55242e81873f83d to your computer and use it in GitHub Desktop.
watchkit command line builds
import plistlib
# Read Plists
myAppInfoPlist = plistlib.readPlist(“MyApp/Info.plist”)
watchKitExtensionInfoPlist = plistlib.readPlist(“WatchKitExtension/Info.plist”)
watchKitAppInfoPlist = plistlib.readPlist(“WatchKitApp/Info.plist”)
# Update Watch Kit Extension Plist
watchKitExtensionInfoPlist[“NSExtension”][“NSExtensionAttributes”][“WKAppBundleIdentifier”] = watchKitAppInfoPlist[“CFBundleIdentifier”]
watchKitExtensionInfoPlist[“CFBundleVersion”] = myAppInfoPlist[“CFBundleVersion”]
WatchKitExtensionInfoPlist[“CFBundleShortVersionString”] = myAppInfoPlist[“CFBundleShortVersionString”]
# Update Watch Kit App Plist
watchKitAppInfoPlist[“WKCompanionAppBundleIdentifier”] = myAppInfoPlist[“CFBundleIdentifier”]
watchKitAppInfoPlist[“CFBundleVersion”] = myAppInfoPlist[“CFBundleVersion”]
watchKitAppInfoPlist[“CFBundleShortVersionString”] = myAppInfoPlist[“CFBundleShortVersionString”]
# Save the Plists
plistlib.writePlist(myAppInfoPlist, “MyApp/Info.plist”)
plistlib.writePlist(watchKitExtensionInfoPlist, “WatchKitExtension/Info.plist”)
plistlib.writePlist(watchKitAppInfoPlist, “WatchKitApp/Info.plist”)
xcrun xcodebuild -sdk iphoneos -config "Release"
cp watchkitapp.mobileprovision MyApp.app/WatchKitExtension.appex/WatchKitApp.app/embedded.mobileprovision
cp watchkitextension.mobileprovision MyApp.app/WatchKitExtension.appex/embedded.mobileprovision
cp myapp.mobileprovision MyApp.app/embedded.mobileprovision
xcrun codesign -d --entitlements :- MyApp.app/WatchKitExtension.appex/WatchKitApp.app 2>/dev/null > watchkitapp.xcent
xcrun codesign -d --entitlements :- MyApp.app/WatchKitExtension.appex 2>/dev/null > watchkitextension.xcent
xcrun codesign -d --entitlements :- MyApp.app 2>/dev/null > myapp.xcent
# Order is important!!
# WatchKit App
rm -rf MyApp.app/Plugins/MyWatchKitExtension.appex/MyWatchKitApp.app/_CodeSignature
xcrun codesign -f -s "Certificate Name" -- entitlements watchkitapp.xcent MyApp.app/Plugins/MyWatchKitExtension.appex/MyWatchKitApp.app
# WatchKit Extension
rm -rf MyApp.app/Plugins/MyWatchKitExtension.appex/_CodeSignature
xcrun codesign -f -s "Certificate Name" -- entitlements watchkitextension.xcent MyApp.app/Plugins/MyWatchKitExtension.appex
# Main App
rm -rf MyApp.app/_CodeSignature
xcrun codesign -f -s "Certificate Name" -- entitlements myapp.xcent MyApp.app
xcrun -sdk iphoneos PackageApplication MyApp.app -o MyApp.ipa
# Extract the contents of the ipa
unzip MyApp.ipa
# Include WatchKitSupport
mkdir WatchKitSupport
cp "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/Library/Application\ Support/WatchKit/WK" WatchKitSupport/WK
# Repackage
zip -qr MyAppWithWatchKit.ipa Payload WatchKitSupport
# https://github.com/mxpr/ios-build-utils
from utils.packager import Packager
def package():
ipa = Packager("MyAppWithWatchKit.ipa")
ipa.add("MyApp.app","Payload/MyApp.app")
ipa.add("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/Library/Application\ Support/WatchKit/WK", "WatchKitSupport/WK")
ipa.package()
@AliAyasrah
Copy link

hello
thanks for the that .

i tried to do that but i cant find "WatchKitExtension.appex" inside "MyApp.app" folder

please i need help about that
thanks

@mxpr
Copy link
Author

mxpr commented Jun 27, 2015

its under the Plugins folder
e.g. MyApp.app/Plugins/MyWatchKitExtension.appex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment