Build iOS App Extension through command line - ios

I'm trying to build an iOS app containing an app extension from the command line. However when I use the following xcodebuild command to build:
xcodebuild -sdk iphoneos -configuration "Debug" -workspace "/Users/user/build/app_extension_demo/app_extension_demo.xcworkspace" -scheme "AppExtensionDemo" -CODE_SIGN_IDENTITY="iPhone Developer: ios developer" PROVISIONING_PROFILE=34070551-ebe8-412a-b57c-9fbdf9a42ed4 derivedDataPath "/Users/user/build/app_extension_demo/Build/Products/Debug-iphoneos" OBJROOT="/Users/user/build/app_extension_demo/Build/" SYMROOT="/Users/user/build/app_extension_demo/Build/Products" CONFIGURATION_BUILD_DIR=/Users/user/build/app_extension_demo/Build/Products/Debug-iphoneos
I get the following error:
ERROR: Code Sign error: Provisioning profile does not match bundle identifier: The provisioning profile specified in your build settings ("XC Ad Hoc: com.mycompany.AppExtensionDemo") has an AppID of "com.mycompany.AppExtensionDemo" which does not match your bundle identifier "com.mycompany.AppExtensionDemo.NumberWidget".
I'm using a provisioning profile (XC Ad Hoc: com.mycompany.AppExtensionDemo) with AppID of com.mycompany.AppExtensionDemo, but the app extension is expecting a different AppID (com.mycompany.AppExtensionDemo.NumberWidget). Everything builds fine when done through the Xcode app. I noticed that Xcode automagically created the provisioning profile for "com.mycompany.AppExtensionDemo.NumberWidget" for the app extension target. However when building through the command line, I'm not sure how to associate app extension profile to the app extension target. Any help would be appreciated!

So I've just figured this out and posted my answer here: https://stackoverflow.com/a/29605731/1153630
Basically you can set an $ENVIRONMENT_VARIABLE into the Provisioning Profile field in your targets's Build Settings and assign it from the command line instead of using PROVISIONING_PROFILE=... - have a look at my other answer for more detail.

Related

Xcode signing using Jenkins

I am trying to sign and archive my Unity application with Jenkins. I have the Xcode jenkins plugin installed and everything seems to run well except for a strange problem.
During the xcodebuild phase, when the archive should be signed, I get the following error:
error: No signing certificate "iOS Development" found: No "iOS
Development" signing certificate matching team ID "QF6V2M666X" with a
private key was found. (in target 'Unity-iPhone')
Now the problem is that I am not trying to build for development, but for production. I have a production provisioning profile used, which is pointing the production certificate. The team id is the production team id (changed here for security reasons). Here is another part of the build output:
Going to invoke xcodebuild:, scheme: Unity-iPhone, sdk: DEFAULT,
project: DEFAULT, configuration: Release, clean: NO, archive:YES,
consolelog:YES, symRoot: DEFAULT, buildDir: DEFAULT,
developmentTeamID: QF6V2M666X
[sr-ios] $ /usr/bin/xcodebuild -scheme
Unity-iPhone -configuration Release archive -archivePath
When I open the project in Xcode, I can see that for some reason Xcode selects "IOSDeveloper" in the code signing identities part and not "IOSDistribution" (or the actual certificate in the provisioning profile):
I don't know if this can be changed from Jenkins, but I think Xcode should pick this up from the provisioning profile.
So I managed to find the problem and solve it, here is the solution for others.
In Unity 2018 they added a new option to the iOS player settings, in the "Other settings" section, called IOS Provisioning Profile->Profile type:
This option is used to select the signing identity. I guess you can use "Automatic" but in my case, since I am using Jenkins, I am setting it on a build script like this:
PlayerSettings.iOS.iOSManualProvisioningProfileType =
ProvisioningProfileType.Distribution;
When this option is set, xcode is able to sign the app correctly for distribution.

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!

xcodebuild cannot find correct iOS Development Certificate under cron

I am currently using xcodebuild command line tool to build and deploy the app to iPhone as follows.
I saw in my login keychain that the iOS Development Certificate does exist but the key does not match Key1 as shown in the output. My question is how to allow xcodebuild to pick the correct iOS Development Certificate that is currently in the keychain.
Build Command
HOME=/Users/mcj xcodebuild build-for-testing -project ios/ios_test_app/HXKPIIOS/HXKPIIOS.xcodeproj -scheme HXKPIIOS -destination 'platform=iOS,id=<iPhoneUDID>' -derivedDataPath /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhoneUDID>/build_derived_data | tee /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhone UDID>/uitest/build1.log
Output
User defaults from command line:
IDEDerivedDataPathOverride = /opt/HX/HXKPI_Logs/kpi18_iOS_2018-06-23-21-20-01-149882/<iPhoneUDID>/build_derived_data
=== BUILD TARGET HXKPIIOS OF PROJECT HXKPIIOS WITH CONFIGURATION Debug ===
Check dependencies
Code Signing Error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "<Key1>" with a private key was found.
Code Signing Error: Code signing is required for product type 'Application' in SDK 'iOS 11.2'
Go to the Project Navigator >> "General" tab. Look for the "Signing" section and you will see your Team, Provisioning Profile, Signing Certificate, and your Signing Status. Perhaps there is an issue with your Status as you were unable to sign in with your account. In that case, simply press Sign In... and re-enter your credentials. Or, perhaps, you are signed in on a team that does not have your Signing. In that case, go to the Team section and simply change which team you are signed in with. And finally, check your signing certificate in the Signing section. If its empty, that's why Xcode doesn't recognize your certificate.

xcodebuild provisioning profiles not found?

I'll try to be polite talking about xCode.
Issue:
we updated provisioning profiles because prev ones are expired.
Now I can archive/build from xCode but can't using xcodebuild (which must be the same)
I did everything:
removing, adding profiles, recreating ...
reinstalling ... restarting...
removing account, adding back and a lot more
sudo xcodebuild -scheme nl.xxx.demo.iphone -workspace xxx.xcworkspace clean build
error:
=== BUILD TARGET xxxWatchAppDemo Extension OF PROJECT xxx WITH CONFIGURATION Debug ===
Check dependencies
Code Sign error: No provisioning profiles found: No non–expired provisioning profiles were found.
But when I'm archiving or building through xCode everything is just fine, and inside ipa, embedded.mobileprovision is actually our new mobileprovision with UUID d9179316-6950-4369-94dc-b7d71bba25a1
And if I explicitly set provisioning profile - it doesn't work out:
sudo xcodebuild -scheme nl.xxx.demo.iphone -workspace xxx.xcworkspace archive PROVISIONING_PROFILE=d9179316-6950-4369-94dc-b7d71bba25a1
error
Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “d9179316-6950-4369-94dc-b7d71bba25a1”, however, no such provisioning profile was found.
Not found??? Really?
I checked /Users/xxx/Library/.../Provisioning Profiles/... and it's there.
I deleted it, added, repeated it 10 times, no result.
What kind of magic it is?
Any help appreciated.
Thanks
So Jenkins has been running under buildagent user, however provisioning profiles weren't found.
I created symbolic link to my
/buildagent/Library/MobileDevice/ProvisioningProfiles/ in very root folder - /Library/.
That solved my issue

Code Sign error in xcodebuild archive

I am trying to generate a .ipa file only through command line,
xcodebuild archive -project someproject.xcodeproj -scheme somescheme -
archivePath /somepath/someproject.xcarchive
This command still depends on the provisioning profile I have selected in xcode, and fails if a wrong profile is chosen.
The error generated is :
Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “some UUID”, however, no such provisioning profile was found.
Is there a way I can make archive command independent of provisioning profile chosen in Xcode ? Or can this be a configurable parameter in the command. Do we have a file where this value is mentioned, in that case I can overwrite it.
It looks like you should be able to use an additional parameter on the xcodebuild command you mentioned above.
There is an additional option called exportProvisioningProfile that allows you to specify the provisioning profile to use.
From Apple Docs:
-exportProvisioningProfile profilename
Specifies the provisioning profile that should be used when exporting the archive.
Link to documentation:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html

Resources