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 and
have a script replace it with the correct file for the configuration
you 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 deleted
before 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 "https://mcmap.net/q/563112/-per-configuration-app-group-entitlement-strings-in-xcode"
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
CODE_SIGN_ENTITLEMENTS
from a .xcconfig file now works as of Xcode 8.2.1. This definitely wasn't working with 8.0 and possibly 8.1 (haven't checked), so it may be the case that the bug referenced in some of the answers/comments is now fixed. – Caudle