How do I fix "Missing Private Key" for xcode apple provisioning?

dapug picture dapug · Feb 12, 2018 · Viewed 13.7k times · Source

On a new mac, I installed xcode and needed to set up provisioning for a hello-world project to deploy to my iPad.

NOTE: I am using the new FREE provisioning (do not have a paid Apple account)

  1. I went to Preferences/Account signed in to my Apple account
  2. In the project, General tab, Team is set to my (free) Apple Dev account. (all seemed well, it recognized this as valid)
  3. I tried to deploy to the iPad and I got a build error "codesign failed with exit code 1"
  4. Supposedly this is to do with certificates. I went to Keychain Access and found "iPhone Developer: [email protected] (...)" in there, which was added when I signed in via my Apple Account.
  5. I DELETED this key (thinking I would simply re-add my Apple Account and thus this key)
  6. I then removed and re-added my Apple account from xcode preferences
  7. I can sign-in, I can see it adds keys, and Keychain Access Get Info on the keys indicates no issues (valid, etc)
  8. In xcode Preferences, when I click Manage Certificates, it shows "David's MacBook Pro (2)" and a bunch of "Untitled" keys ALL of which have a status of "Missing Private Key".
  9. xcode/General/Status section says "The username or passphrase you entered is not correct" even though my "Team" is signed in and valid
  10. Clicking "Try Again" shows "Waiting to repair", followed by "revoking...", followed by "Generating certificates" - which sounds promising, like it's doing exactly what I need, but then fails, private keys still missing, and back to step 9 here in a loop of hell.

ok? How do I get this resolved without flattening my OS back to factory and starting completely over?

Note: there are resolutions on SO that talk about Revoking the keys and generating new private keys from the Dev Console, like this one: How can I add private key to the distribution certificate?

HOWEVER, on a "free" account I have NO access to the Certificates section! I can't manage anything from the Dev portal online. I do, however, see xcode specifically set up to handle certs (see step 9-10 above) but it is not working. I really don't know where to go from here. I'm new to all things Mac and iOS and xcode. Frustrated. Thanks Apple, so much for a simple on-boarding experience on a simple hello-world app.

Answer

resurrecteds picture resurrecteds · Jun 26, 2018

After two bounties for this question which gave no results, I managed to find a solution to this problem. Apparently, it was some keychain related problem.
To fix it:

  1. Open Keychain Access on your Mac.
  2. Right click on the "login" keychain in the left side of the window.
  3. Press Lock keychain "login".
  4. Then do the same to Unlock it.
  5. Go back to Xcode and try to set your app to run with your personal account.

Solution was found using the first comment here: https://github.com/desktop/desktop/issues/3625