xcodebuild how to sign app with command line? - ios

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

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.

Related

xcodebuild using wrong provisioning profile

I have a bash script where I am trying to automate pushing an IPA to TestFlight. Currently this script is successfully uploading to the app-store with an ad-hoc provisioning profile and not my distribution profile as such I am unable to push the build to TestFlight as it does not have the beta-reports-active key. This is easily fixable from within XCode but I have had no luck using command line which is integral to what I want to do. This is my current command trying to use manual signing:
xcodebuild archive -workspace $NAME.xcworkspace -allowProvisioningUpdates -scheme $NAME -configuration Release -archivePath ../builds/$NAME.xcarchive DEVELOPMENT_TEAM=$TEAM_ID CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="iOS Distribution: MY_NAME" PROVISIONING_STYLE=Manual PROVISIONING_PROFILE_SPECIFIER="PROVISIONING PROFILE "
Is there a way of getting the correct provisioning profile through command line
EDIT
Examples of what I have tried:
Downloading and inserting the provisoning profile int0 ~/Library/MobileDevice/Provisioning\ profiles and then using PROVSIONING_PROFILE_SPECIFIER to point to the profile
Inserting the app-store method into the export options plist file
Creating new ExportOptions file that specifies manual signing as well as the provision profile being used - so far getting a signing error due to no provisioning profile being found
Hope this ^ is clear
I had a similar problem, I was using fastlane to push to testflight and it automatically kept pulling the wrong provisioning profile..
When I dug deeper by running
xcodebuild -showBuildSettings -workspace Freshdesk.xcworkspace -scheme <My Build scheme>
I realised that no matter what scheme I picked I kept getting the same provisioning profile in the command line.
I then dug into xcode and chanced on this parameter
This was set to staging and I could never sign my app for the app store build, I changed it to production and it fixed my problems
You can find this under "configurations" in the info tab of your project and not the target
I hope this helps!

xcode9 requires a provisioning profile

I am using xcode plugin (version 2.0.1) with jenkins to generate our builds for multiple targeted app.
With Xcode 9, our jenkins build configuration is able to generate the archive but fails to create the ipa. The error message is as follows:
Error Domain=IDEProvisioningErrorDomain Code=9 ""test.app" requires a provisioning profile." UserInfo={NSLocalizedDescription="test.app" requires a provisioning profile., NSLocalizedRecoverySuggestion=Add a profile to the "provisioningProfiles" dictionary in your Export Options property list.}
I have already added the provisioning profile inside Jenkins Custom xcodebuild arguments section by passing the PROVISIONING_PROFILE, PROVISIONING_PROFILE_SPECIFIER, CODE_SIGN_IDENTITY, CODE_SIGN_STYLE and DEVELOPMENT_TEAM however, it still shoots the same error message. Besides, I also pass the ExportOptions.plist file in the Build phases Run script option but it seems that Xcode generates its own ExportOptions.plist(enterpriseTEAMIDExport.plist) and ignores mine. When I open enterpriseTEAMIDExport.plist file it only contains the teamid and the method of export and so, it doesn't find the provisioning profile.
So, how can I tell xcode to use my ExportOptions.plist file instead? I have followed the image here but unable to find it inside Xcode 9. Also, this post doesn't relate to me.
Another important thing is that I am able to generate the ipa using my own ExportOptions.plist file from command line xcodebuild tool using this command as follows:
xcodebuild -exportArchive -archivePath archive.xcarchive -exportPath /my/export/path -exportOptionsPlist options.plist
So, I don't know why it doesn't work with Jenkins Xcode plugin.
Any help is much appreciated.
Thanks!

xcodebuild command failing on codesign but logs show incorrect profile uuid being used

I try to run this:
xcodebuild -scheme "MobileRenderStress.iOS" -destination "generic/platform=iOS" archive -archivePath /Applications/buildAgent/work/builds/MobileRenderStress-iOS.xcarchive
Which results in this:
<Many lines of irrelevant log that ends with...>
Signing Identity: "iPhone Developer: DK (RYQ82Z5555)"
Provisioning Profile: "iOSTeam Provisioning Profile: com.company.*"
(0b51596e-46c1-456a-a7bc-911858ad275a)
/usr/bin/codesign --force --sign A72FD8239B6355AE7DECC865F1A13226450F76C --entitlements /Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/IntermediateBuildFilesPath/MobileRenderStress.iOS.build/Debug-iphoneos/MobileRenderStress.iOS.build/MobileRenderStress.iOS.app.xcent /Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/InstallationBuildProductsLocation/Applications/MobileRenderStress.iOS.app
/Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/InstallationBuildProductsLocation/Applications/MobileRenderStress.iOS.app: User interaction is not allowed.
Command /usr/bin/codesign failed with exit code 1
** ARCHIVE FAILED **
The following build commands failed:
CodeSign /Users/builder/Library/Developer/Xcode/DerivedData/Technology-ajtzoltdytdzndgefjzzhzhiufjx/Build/Intermediates/ArchiveIntermediates/MobileRenderStress.iOS/InstallationBuildProductsLocation/Applications/MobileRenderStress.iOS.app
(1 failure)
I've been running xcodebuild commands both for building and archiving (in this example I am archiving) but I am receiving codesign errors. The confusion comes especially from the fact that the logs indicate exactly which provisioning profile ID it's trying to use (and successfully finds) but the command line for "codesign" is indicating a different ID. Even if I specify the profile in the xcodebuild command, it still ends up trying to use this different, non-existent ID in the codesign line.
Has anyone come across this before and know where that ID is even coming from? I grep'd my entire project and it's nowhere to be found. It's kinda creepy, really.
Important Notes:
When I update the provisioning profile to get the ID to change, the xcodebuild command STILL tries to use the A72 ID at the codesign line. It's really frustrating!
I do see the part of the log that indicates "User interaction is not allowed." Although this doesn't relate to the issue, do know that it's using the --force command in the line which should bypass that error and also the provisioning profile's signing keys are all fully permissive, which is the other workaround for that kind of issue.
The issue is caused by "User interaction is not allowed." this is because it needs a code signing prompt to be accepted which cannot happen from command line until the keychain has been unlocked.
security unlock-keychain -p YOUR_PASSWORD ~/Library/Keychains/login.keychain
Also you might want to do it directly in xcode and check it works on the machine.

xcodebuild not copying file from .app

I've created a signed .xcarchive file using the xcodebuild command.
Inside the .xcarchive is a .app file. Inside the .app is a file called archived-expanded-entitlements.xcent. This file is the key to my problem.
I run a different xcodebuild command that creates an .IPA file from the .xcarchive.
Creating the IPA fails because the archived-expanded-entitlements.xcent file is missing. The thing is, xcodebuild is creating a temporary directory where it copies over my .app file, and inside THAT .app file, there is no archived-expanded-entitlements.xcent file.
All the other files are in there except this one.
The commands I run are below:
This creates the xcarchive:
xcodebuild -project diplomat.xcodeproj -scheme schemeName archive -archivePath /Path/To/Archive/name.xcarchive -configuration AppStore CODE_SIGN_IDENTITY="identity" PROVISIONING_PROFILE=provProfile
This creates the IPA:
xcodebuild -exportArchive -exportFormat IPA -archivePath /Path/To/Archive/name.xcarchive -exportPath /Path/To/Archive/name.ipa
Despite specifying the location of the .xcarchive, it creates a temporary directory and doesn't include the important file.
Please note, the archived-expanded-entitlements.xcent file is created during the .xcarchive process (the first command that's run) and fails to copy into the temp directory during the second command run.
This is the exact error. Google and StackOverflow have yielded similar errors, but nothing with this actual problem.
Checking original app
+ /usr/bin/codesign --verify -vvvv /var/folders/sl/_wdkd56d5pb05snr559cmcww0000gn/T/D2133E2C-DC66-427C-A3C5-903A88DD0541- 42128-00007ED35037747A/name.app
Program /usr/bin/codesign returned 1 :
[/var/folders/sl/_wdkd56d5pb05snr559cmcww0000gn/T/D2133E2C-DC66-427C-A3C5-903A88DD0541-42128-00007ED35037747A/name.app: a sealed resource is missing or invalid
file missing:
/private/var/folders/sl/_wdkd56d5pb05snr559cmcww0000gn/T/D2133E2C-DC66-427C-A3C5-903A88DD0541-42128-00007ED35037747A/name.app/archived-expanded-entitlements.xcent
]
Codesign check fails :
/var/folders/sl/_wdkd56d5pb05snr559cmcww0000gn/T/D2133E2C-DC66-427C-A3C5-903A88DD0541-42128-00007ED35037747A/name.app: a sealed resource is missing or invalid
file missing:
/private/var/folders/sl/_wdkd56d5pb05snr559cmcww0000gn/T/D2133E2C-DC66-427C-A3C5-903A88DD0541-42128-00007ED35037747A/name.app/archived-expanded-entitlements.xcent
Done checking the original app
This is indeed a weird behaviour of xcodebuild, but you can still use the exportArchive command and specify the provisioning profile using exportProvisioningProfile:
xcodebuild -exportArchive -exportFormat IPA \
-archivePath /Path/To/Archive/name.xcarchive \
-exportPath /Path/To/Archive/name.ipa \
-exportProvisioningProfile 'PROVISIONING_PROFILE_NAME'
This will reembed the provisioning profile within the app and you won't actually need to speciify the code signing identity again, because the archive should already be signed during the archive process.
My answer would be considered a workaround, but it solved the problem. I do not know why the one file was not being copied over, but I found a way so it wasn't important.
Replace the 2nd xcodebuild command with this, which utilizes xcrun:
/usr/bin/xcrun -sdk iphoneos PackageApplication -v /Path/To/Archive/name.xcarchive/Products/Applications/name.app -o /Path/To/Archive/DiplomatStaples.ipa --sign "identity" - -embed "provProfile"
This creates an IPA using the xcarchive and then re-embeds the identity and the provisioning profile, so even though the same error as above still occurs and is printed out,the "double dip" with the code signing identity and provisioning profile makes it meaningless. I can now install the app on devices.
For inquiring minds: The reason I'm not just using xcrun in the first place is because even if I specify a prov profile and signing identity, xcrun will use the embedded profile and signing identity in the project based on the configuration (Debug, AppStore, Release, etc) that I specify. xcodebuild will actually sign with the certs I provide it.
The goal of this operation was to remove the need for provisioning profile certs that the CI system required from developer machines, enabling testing the "AppStore" configuration to be signed with AdHoc distribution certs, and enabling re-signing of the xcarchive later on with the actual App Store distribution certs.

Cannot export unsigned IPA from Xcode 5

Under Xcode 4 I was able to export an unsigned IPA in order to send that to clients with Enterprise accounts for resigning. With the upgrade to Xcode 5 this option has been removed. I found a similar question that found a work around for Cocoa apps, but this won't work for iOS apps as it yields a .app file.
Does anyone know how an unsigned IPA can be generated from Xcode 5, or know of another way to give something to my client for resigning that doesn't involve trading certificates or the project itself?
We had the exact same problem. We used this process for a year to deliver an unsigned IPA to our client, who would then sign it when their Enterprise Profile to release it to all their employee's. The work around turned out to be pretty straight forward. We just signed the IPA with one of our Distribution Profiles, and the customer, in turn, was able to take that signed IPA and resign it with their Enterprise Distribution Profile. It turns out, having the "Don't Resign" option in the drop down was not needed.
You can run this in your *.xcodeproj directory:
xcodebuild -project YOUR_PROJECT.xcodeproj -exportArchive -exportFormat ipa -archivePath $(pwd)/YOUR_PROJECT.xcarchive -exportPath $(pwd)/YOUR_PROJECT.ipa CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -alltargets -configuration Release
You can create .xcarchive by running:
xcodebuild -scheme YOUR_PROJECT_SCHEME archive CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -archivePath $(pwd)/YOUR_PROJECT.xcarchive
You can create scheme by using xcodeproj and this ruby(.rb) script:
require 'xcodeproj'
xcproj = Xcodeproj::Project.open("YOUR_PROJECT.xcodeproj")
xcproj.recreate_user_schemes
xcproj.save
You can install xcodeproj by running:
sudo gem install xcodeproj :)

Resources