XCode ThirdPartyDependencies signing from command line

Oscar Brito

One of the best things that happened to the mobile development ecosystem recently was when Apple released Swift.

Swift basically makes memory management easier, introducing a garbage collector Automatic Reference Counting and a better language grammar, when compared to ObjectiveC.

But that's not the reason why you're reading this, is it?

Some ObjectiveC libraries like Alamofire and SwiftyJSON if not included as ThirdPartyDependencies will not work on IOS7, because they need to be used as a framework library to work (CocoaPods use_frameworks!).

When building the project from the command line you'll see that your ThirdPartyDependencies also need to be signed.

If you're using a wildcard App Id certificate to sign the project everything is fine. But if you need an explicit App Id certificate you're in troubles.

Code Sign error: a valid provisioning profile matching the application's Identifier ... could not be found  

To fix this issue you must use an explicit App Id Provisioning Profile for your project signing and an wildcard App Id Provisioning Profile for your ThirdPartyDependencies.

To do this you must set the Provisioning Profile of the project and ThirdPartyDependencies projects to different environment variable that you'll set later ($APP_PROVISIONING_PROFILE and $LIBS_PROVISIONING_PROFILE).

Once the environment variables are set we can invoke xcodebuild with their values to create the xarchive and export the signed ipa, as you can see on the following Enterprise build.

#!/bin/sh

#
# CI Integration - Command line Enterprise build.
#

# create enterprise xarchive
xcodebuild -workspace "Project.xcworkspace" \  
    -scheme "Scheme" \
    -sdk "iphoneos8.3" \
    -configuration "Release" \
    -archivePath "Build/Project.xcarchive" \
    clean archive \
    CODE_SIGN_IDENTITY="iPhone Distribution: Certificate Name" \
    APP_PROVISIONING_PROFILE="********-****-****-****-************" \
    LIBS_PROVISIONING_PROFILE="********-****-****-****-************"

# create enterprise IPA
xcodebuild -exportArchive \  
    -exportFormat ipa \
    -archivePath "Build/Project.xcarchive" \
    -exportPath "Build/Project.ipa" \
    -exportProvisioningProfile "Provisioning Profile name"

By providing the environment variables values on the command line we can tweak the behaviour of xcodebuild.


Please note that this problem could now be fixed but the usage of environment variables can be very handy to tweak XCode behaviour.

Oscar out.