Search code examples
xcodecode-signingios-provisioningprovisioning-profile

xcode - building app with command line gives provisioning profile error


I'm trying to archive an app from command line but it gives the following error:

Code Sign error: The identity 'iPhone Distribution: XXX' doesn't match any valid, non-expired certificate/private key pair in your keychains

And I'm using the following lines to build and archive the app:

export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

xcodebuild -target TestAppLogicTests \
-sdk iphonesimulator \
-configuration Debug \
TEST_AFTER_BUILD=YES \
clean build | /usr/local/bin/ocunit2junit.rb

# tests passed archive app

export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

/usr/bin/xcrun xcodebuild -scheme TestApp clean archive \
CODE_SIGN_IDENTITY="iPhone Distribution: XXX"

I'm sure that my CODE_SIGN_IDENTITY is correct (I've checked it in the .pbxproj file). I've already tried to redownload my distribution certificate but that didn't work either. It's working fine in xCode itself.

Anyone has an idea on what I could try?

Thanks!


Solution

  • Open keychain. Do you see your developer (or distribution) certificate)?

    If yes, can you click on it to open a dropdown? Under it, do you see a text called private key with something else?

    If you don't see any dropdown and private key, you must:

    • Initiate 'Request certificate from authority' from keychain
    • Export certificate on your hard drive.
    • Upload this certificate to your apple developer account's provisioning profile section (revoke older certificate)
    • Update your provisioning profile with newer certificate (go inside each of them and check your certificate)
    • Download new provisioning profile by opening and refreshing XCode
    • Close XCode.
    • Build using command line.

    If this is confusing, there are plenty of questions that explains this in more details, like this one.