32

I'm trying to build my app with xcodebuild:

xcodebuild -workspace "RG.xcworkspace" -scheme "Production" -configuration "Release" build CONFIGURATION_BUILD_DIR="${TEMP_DIR}" PROVISIONING_PROFILE="1234-5678-9098-7654-3210"

My scheme has two targets. One target is the app, the other is the app extension (I built an extension for Safari). The app extension is a target dependency. Each target requires a separate provisioning profile. I don't know how to specify the PROVISIONING_PROFILE for the dependency. I'm getting this error, as expected:

CodeSign error: code signing is required for product type 'App Extension' in SDK 'iOS 8.1'

StackOverflow and the man page for xcodebuild don't seem to come up with anything. Does anyone know how to build a project with xcodebuild that relies on two provisioning profiles?

Rey Gonzales
  • 836
  • 1
  • 8
  • 17

4 Answers4

61

I spent far too long working on this today. I was on my way to bed when the answer hit me:

In each of your targets's Build Settings you should set a $VARIABLE for the profile name. To do this, selected "Other" from the bottom of the list of profiles. Doing this will open a text field - choose a different $VARIABLE for each target - for example I chose $APP_PROFILE for the container app target and $EXTENSION_PROFILE for my Today extension target

Adding a build variable variable...

This will result in something like the following:

Profiles

Finally, when building with xcodebuild, specify the profile UUIDs as you did with PROVISIONING_PROFILE:

xcodebuild ... APP_PROFILE="85b6f019-d5e5-43a7-9e8f-e3aaed64a7e4" EXTENSION_PROFILE="e50cf605-ab63-40ad-8329-2758359ea748"

Building from within XCode seems to be unaffected - as far as I could tell XCode is selecting the default profiles (as if in "Automatic" mode)

Theoretically this would support multiple extensions too.

Works for me with XCode 6.3 :)

Max Chuquimia
  • 7,494
  • 2
  • 40
  • 59
  • 1
    Hey, very nice. Thanks! – Rey Gonzales Apr 15 '15 at 16:50
  • 5
    i was going nuts, you deserve a medal... I still can't believe the distribution mechanics of app extensions is so poorly undocumented by Apple – apouche Apr 23 '15 at 20:53
  • @apouche if you're still using this, you may prefer another solution - I've added another answer :) – Max Chuquimia May 13 '16 at 00:25
  • 1
    Just create more configuration. Then, you have no need to specify profile name in command line. – DawnSong Feb 28 '18 at 10:55
  • I tried this, but then contrary to what you said in the third from last paragraph, Xcode started complaining about a mismatch between an explicit profile mentioned here, and "Automatic" mentioned elsewhere. Hmm. – SuddenMoustache Mar 12 '20 at 14:43
  • This is not a great solution if you do not own the project you are trying to build. Esp. if you want an automated build. The manual process of opening xcode and creating env variables every time we pull a fresh release of a project is not optimal. – lostintranslation Mar 24 '21 at 17:20
1

Months later... Found a solution that doesn't involve settings values within Xcode: Within sigh there is a script that is capable of resigning an ipa file with given profiles. The following works for me:

bash resign.sh Experiments-AdHocProd.ipa "iPhone Distribution: Company Pty Ltd" output.ipa -p com.company.experiments.AudioPlugin=Experiments-AdHocProd_com.company.experiments.AudioPlugin.mobileprovision -p com.company.experiments=Experiments-AdHocProd.mobileprovision --verbose

where:

  • Experiments-AdHocProd.ipa is the existing ipa
  • com.company.experiments.AudioPlugin is the extension bundle ID
  • Experiments-AdHocProd_com.company.experiments.AudioPlugin.mobileprovision is the extension profile
  • com.company.experiments is the main app bundle identifier
  • Experiments-AdHocProd.mobileprovision is the main app profile

Each profile's bundle identifier must match that of the app it will be signed with.

Something I found that is important to note is that if a bundle identifier has a wildcard (in my case Experiments-AdHocProd.mobileprovision does) then the profiles with explicit IDs must be passed into -p first.


Alternatively, you could use sigh to perform the resign. Unfortunately, sigh --help doesn't say anything about resigning binaries with extensions, however sigh resign --help does.

Max Chuquimia
  • 7,494
  • 2
  • 40
  • 59
1

Solution Without Variable

There is an option, -exportSigningIdentity which can help you, because provisioning profiles of Application & Extension/Widget may be different, but signing identities of app & extension are supposed to be same.

For example, you will see that,

  • TargetApp -> Build Settings -> "Code Signing Identity (id)" (Release)
  • TargetExtension -> Build Settings -> "Code Signing Identity (id)" (Release)

are essentially same string, lets say this identity is "Code Signing Identity (id)". So to build & export archive, what you can run, are simply,

Cleaning

xcodebuild clean -workspace HelloWorld.xcworkspace -scheme HelloWorld

Building

xcodebuild -workspace HelloWorld.xcworkspace -scheme HelloWorld archive -archivePath ~/output/HelloWorld.xcarchive

Exporting

xcodebuild -exportArchive -exportFormat ipa -archivePath ~/output/HelloWorld.xcarchive -exportPath "HelloWorld.ipa" -exportSigningIdentity "Code Signing Identity (id)"

Reference: xcodebuild documentation

Community
  • 1
  • 1
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
  • Does that only help when one has multiple apple accounts? In maintaining profiles, I don't think this will help me switch from an old to a new profile. Btw, doc page is for xcode5 2013 vs we're on 8.3 now. I don't think new xcode's have any separate doc online for cli now. – AnneTheAgile Apr 06 '17 at 16:55
  • Both target should be under same account which is usual case. Yes it works. – Sazzad Hissain Khan Apr 06 '17 at 23:28
  • This is not working for me. When trying to build the TargetApp in your example, I am getting an error for both the TargetApp and TargetExtension, "requires a provisioning profile with the Associated Domains, App Groups, and Push Notifications features". Seems that not setting or providing a provisioning profile does work. In my case I am trying to build a 3rd party app, I do not have control over the xcode project settings and would like to build command line to automate this process. – lostintranslation Mar 24 '21 at 17:17
0

In Swift, Pod files framework will be packaged separately. Following steps solved the problem.

 1. Select pods 
 2. Targets
 3. General
 4. Edit bundle id
 5. Build Settings
 6. Code Signing
 7. Provisioning profile -> select the valid profile
 8. Code Signing Identity -> Select the respective identity from
    profile.

Repeat the same for all targets.

I am able to generate build.

PradeepKN
  • 617
  • 7
  • 10