xcodebuild how to sign app with command line?

2020-03-03 08:51发布

问题:

I am trying to export an ipa using the command line, I can't do that within Xcode because the app is made for a client and I am not a member of his team (I really hope Apple changes that and makes it work like in Xcode 5 :/ )

Anyway, I did more research and tried this command:

xcodebuild -exportArchive -archivePath pcdev.xcarchive -exportPath ~/Desktop/playcadeAdHoc.ipa -exportFormat ipa -PROVISIONING_PROFILE= xxxxxxx-8a61-4264-8fe9-0513bd7935e6 -CODE_SIGN_IDENTITY=iPhone Developer:xxxxx

It did export the .ipa but I wasn't able to run it on my phone; I was stuck in the installing state. I went through the logs of the command and I think this one is causing the problem:

Checking original app

  • /usr/bin/codesign --verify -vvvv /var/folders/ks/gxlbsszj7t58y5n6z8d1hpcm0000gn/T/7F8E1EF2-5238-4EC6-AE74-CDEC6C082A76-2731-00000AE5DF0617E4/games.app Program /usr/bin/codesign returned 1 : [/var/folders/ks/gxlbsszj7t58y5n6z8d1hpcm0000gn/T/7F8E1EF2-5238-4EC6-AE74-CDEC6C082A76-2731-00000AE5DF0617E4/games.app: a sealed resource is missing or invalid file missing: /private/var/folders/ks/gxlbsszj7t58y5n6z8d1hpcm0000gn/T/7F8E1EF2-5238-4EC6-AE74-CDEC6C082A76-2731-00000AE5DF0617E4/games.app/archived-expanded-entitlements.xcent ]

Codesign check fails : /var/folders/ks/gxlbsszj7t58y5n6z8d1hpcm0000gn/T/7F8E1EF2-5238-4EC6-AE74-CDEC6C082A76-2731-00000AE5DF0617E4/games.app: a sealed resource is missing or invalid file missing: /private/var/folders/ks/gxlbsszj7t58y5n6z8d1hpcm0000gn/T/7F8E1EF2-5238-4EC6-AE74-CDEC6C082A76-2731-00000AE5DF0617E4/games.app/archived-expanded-entitlements.xcent

I am sure that am using the correct provisioning and code signing name, also in Xcode I changed the scheme archive setting to debug instead of release in order to work with adhoc and development identity.

My experience with Apple tools is very limited so please try to explain the solution as much as possible.

EDIT: I also tried this method it doesn't gave me any error but still the app is stacked in "installing...":

xcrun -sdk iphoneos PackageApplication ~/Desktop/finalX.xcarchive/Products/Applications/games.app -o ~/Desktop/playcadetest.ipa --sign "iPhone Developer: Name Name (xxxxxxxx)" --embed ~/Desktop/p/adhoc.mobileprovision

Thank you

回答1:

It turns out that I was using the wrong commands; specifically this part is wrong:

-PROVISIONING_PROFILE= xxxxxxx-8a61-4264-8fe9-0513bd7935e6 
-CODE_SIGN_IDENTITY=iPhone Developer:xxxxx

The correct one is this:

-exportProvisioningProfile "Provisioning profile full name "

Provisioning profile full name is the same name that appear in Xcode, not the UDID (I don't know why many people suggested that) also there is no need to specify the signing identity.

Anyway, here is the full command line that is working for me now:

xcodebuild -exportArchive -archivePath myArchive.xcarchive -exportPath myApp.ipa -exportFormat ipa -exportProvisioningProfile "Provisioning profile full name"

NOTE:

  • I am running this command after copying the archive in a folder (desktop) then changing the terminal location to that folder (cd desktop) and then running the command
  • Also don't forget to change the provisioning profile based on your archive build configuration (release or debug), you can change that from the scheme setting to either make a debug or a release build.