Per configuration app group entitlement strings in Xcode?
You can use a different entitlements file for each configuration. This can be specified in the Xcode "Build Settings" user interface, or done through build configuration files (.xcconfig).
Example xcconfig:
CODE_SIGN_ENTITLEMENTS = Debug.entitlements
Where the value for CODE_SIGN_ENTITLEMENTS
points to the correct entitlements file for this configuration. You can create as many configurations as you want in Xcode. By default Xcode creates Debug and Release, you may add Enterprise and use a build configuration file which points CODE_SIGN_ENTITLEMENTS
to the correct entitlements file for Enterprise builds.
The Xcode "Capabilities" user interface will create and manage an entitlements file that is named after your build product. You can edit this file directly if you desire.
- Create an XCConfig build configuration file for each of your build configurations. For this example we will just use Debug and Release, it's simple to add your own build configurations such as Enterprise.
- As described above, populate the xcconfig files with the appropriate
CODE_SIGN_ENTITLEMENTS
settings. - In the Project "Info" user interface, set the build configuration to use the appropriate XCConfig file:
- You can confirm by looking at the Code Signing Entitlements build setting for your build product. You should see something like this:
If you see bold text there, highlight that build setting and hit delete. This will remove the Xcode build setting that is overriding your xcconfig setting.
You can setup this via the "Build Settings". Same way as setting up different bundle ids.
Steps:
- Add a new "User-Defined Setting"
- Specify the "APP_GROUP_ID" for each scheme/config
- Test it out, create an IPA for your app and unzip it.
- Check out the .app and right click then choose "Show Package Contents"
- Look for entitlements file. (if incase you can't find the entitlements file look for .xcent file and change the extension to .entitlements
- Validate if the app group value in the entitlements file is the correct app group id you specified on step 2.
Cheers!
Xcode 8 seems to have a bug as the comments in this question indicate.
I think I have a very rough and dangerous, but working workaround.
The idea is to have just 1 entitlements file that Xcode 8 sees andhave a script replace it with the correct file for the configurationyou are trying to build.
This workaround has many steps and not all of them may be necessary.I will try to update this post as more information is obtained.If you dare to test something like this, please add comments.
Additionally old provisioning profiles probably need to be deletedbefore reopening Xcode 8.
Deleting derived data before opening Xcode 8 also seems to help.
WARNING! TEST THIS AT YOUR OWN RISK. THIS CAN DO IRREVOCABLE DAMAGE
- deletes all provisioning profiles
- deletes DerivedData
SETTING UP THIS HACK
- Save this script below to your project folder.
- Patch in your project name and target names where it reads MyProject*
- patch in your configuration names
- Check the per configuration entitlements file names this script tries to copy on top of MyProject.entitlements
- Configure MyProject.entitlements as entitlements file in all configurations
- Do the same for all targets (if you have eg. watchkit app)
- Before running the script:
- Choose the correct Scheme in Xcode
- Close Xcode
The script template:
#!/bin/bash echo if [ ! -n "$BASH" ] ;then echo Please run this script $0 with bash; exit 1; fi if [ $# -ne 1 ]; then echo echo "ERROR: one of the following expected as parameter: release alpha debug" echo exit -2 fi chosen=$1 echo "You have chosen build configuration $chosen" echo echo "This script is a workaround for Xcode 8 bug in handling different build configs and app groups." echo "(This scenario is most likely not on Apples list of things that developers are expected to do.)" echo echo "See comments in this SO answer" echo "http://stackoverflow.com/a/25734318/1148030" echo echo "1) This script must be run with Xcode 8 shut down." echo "2) All old provisioning profiles will be deteled. Xcode 8 will recreate them with hopefully correct build config." echo echo echo "WARNING: This will delete ALL provisioning profiles for all apps!" echo "WARNING: This will delete ALL MyProject named DerivedData." echo read -n 1 -s -p "Press any key to continue or Ctrl-C to cancel" echo # NOTE ABOUT DELETING DERIVED DATA # Deleting derived data fixes 2 bugs: # 1) Xcode 8 stubbornly generating some distribution profiles for old entitlements files # 2) Install from HockeyApp fails due to signing verification error echo "Deleting derived datas" rm -vrf /Users/pelam/Library/Developer/Xcode/DerivedData/MyProject-* echo echo "Deleting provisioning profiles" rm -v ~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision echo echo "Replacing target entitlements files" echo cp -v "./MyProjectTarget/MyProjectTarget.$chosen.entitlements" "./MyProjectTarget/MyProjectTarget.entitlements" || exit -1 cp -v "./MyProjectAnotherTarget/MyProjectAnotherTarget.$chosen.entitlements" "./MyProjectAnotherTarget/MyProjectAnotherTarget.entitlements" || exit -1 echo ADD COPY COMMANDS FOR OTHER TARGETS HERE echo echo "SUCCESS! Now run Xcode and verify that correct profiles are created." echo echo "NOTE:" echo "Running following command after starting Xcode 8 and waiting a bit can show you what appgroup is selected in each profile." echo "There should only the one correct app group or the release group. No duplicates in one file or mixed." echo "If you are not using multiple app groups, you can view the provisioning profile files in text editor to see that they contain correct settings for the configuration you are trying to build" echo "grep -a appgroup ~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision" echo echo