Reach User Defined Build Settings inside exportOptionsPlist - ios

I have a project which consists of different targets for different build environments. I'm getting IPA file on Jenkins with xcodebuild. I want to define one exportOptionsPlist file and assign a different variable for different targets. For example, for method, Dev target should have development and Prod target should have app-store. For achieving this I'm defining User-Defined settings in Build Settings.
P.S: Every target has only Debug and Release options and every target has IPA_EXPORT_METHOD.
My problem is that I'm getting below error when trying to get the IPA (Reading IPA_EXPORT_METHOD from the ExportOptionsPlist file):
Error Domain=IDEFoundationErrorDomain Code=1 "exportOptionsPlist error for key 'method': expected one of {app-store, ad-hoc, enterprise, development, validation}, but found ${IPA_EXPORT_METHOD}" UserInfo={NSLocalizedDescription=exportOptionsPlist error for key 'method': expected one of {app-store, ad-hoc, enterprise, development, validation}, but found ${IPA_EXPORT_METHOD}}
How can I get the archive:
$ xcodebuild -workspace CLI.xcworkspace -scheme CLI -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/CLI.xcarchive
How can I get the IPA:
$ xcodebuild -exportArchive -archivePath $PWD/build/CLI.xcarchive -exportOptionsPlist exportOptions.plist -exportPath $PWD/build
Export Options Plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<false/>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>${IPA_EXPORT_METHOD}</string>
<key>provisioningProfiles</key>
<dict>
<key>com.iamdeveloper.myproject.dev</key>
<string>My Provision File</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Developer</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>XXXXXXXXX</string>
<key>thinning</key>
<string><thin-for-all-variants></string>
</dict>
</plist>
EDIT: I can define different exportOptionsPlists for different targets. This solves my problem but I want to achieve it with one plist file.

Related

publish an xcodebuild iOS app with an healthkit based watchOS extension

I am using the xcodebuild for creating a package for publishing
The app bundle contains: the iOS app itself, the push notification extension, the watchos app with its extension.
The watchOS app is using the healthkit for retrieving heart rate data.
xcodebuild archive -configuration Release -workspace $(system.defaultworkingdirectory)/MyApp/MyApp.xcworkspace -scheme MyApp -archivePath $(system.defaultworkingdirectory)/MyAppArchive CODE_SIGNING_ALLOWED=NO
xcodebuild -exportArchive -archivePath $(system.defaultworkingdirectory)/MyAppArchive.xcarchive -exportPath $(system.defaultworkingdirectory)/Final -exportOptionsPlist $(system.defaultworkingdirectory)/MyApp/ExportOptions.plist
The ExportOptions.plist contains the info for signing the app
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>provisioningProfiles</key>
<dict>
<key>fit.myapp.watchkitapp.watchkitextension</key>
<string>ProvisioningProfileGUID1</string>
<key>fit.myapp.watchkitapp</key>
<string>ProvisioningProfileGUID2</string>
<key>fit.myapp.notification</key>
<string>ProvisioningProfileGUID3</string>
<key>fit.myapp</key>
<string>ProvisioningProfileGUID4</string>
</dict>
<key>signingCertificate</key>
<string>Apple Distribution: MY COMPANY</string>
<key>signingStyle</key>
<string>manual</string>
<key>method</key>
<string>app-store</string>
<key>teamID</key>
<string>MYTEAMID</string>
<key>uploadBitcode</key>
<false/>
</dict>
</plist>
The ipa file is successfully created but when the ipa file is uploaded (by Transporter app) the package analysis fails with the following errors:
Asset validation failed (90701)
Missing entitlement. watchOS app bundle 'MyApp.app/Watch/MyAppWatch.app/PlugIns/MyAppWatch Extension.appex' uses 'UIBackgroundModes' value 'workout-processing' without the required entitlement 'com.apple.developer.healthkit' signed into the bundle. (ID: cc87a6cd-2084-4712-9f45-b22b35e9574a)
Asset validation failed (90334) Invalid Code Signature Identifier. The
identifier "com.apple.WK" in your code signature for "MyAppWatch"
must match its Bundle Identifier "fit.myapp.watchkitapp" (ID:
bb9a56d3-949c-4b49-ad86-3cf7a26a91a2)
Extra note: If the build has performed directly in Xcode/Organizer then the issue is not present.
What am I missing?
How can I debug this kind of issues?

Flutter. IOS signing issue. "Runner" requires a provisioning profile with the Push Notifications feature

In my flutter project I'm using Codemagic as CI/CD tool.
After adding the flavor to the app, I started getting this error on one of the flavours.
> flutter build ios --release --no-codesign --build-name=0.0.1 --build-number=33 --flavor dev
Downloading ios tools... 2.4s
Downloading ios-profile tools... 1.5s
Downloading ios-release tools... 7.3s
Warning: Building for device with codesigning disabled. You will have to manually codesign before deploying to device.
Building se.getgaston.app for device (ios-release)...
Running pod install... 323.3s (!)
Running Xcode build...
Xcode build done. 875.6s
Built /Users/builder/clone/build/ios/iphoneos/Runner.app.
> xcode-project build-ipa --workspace /Users/builder/clone/ios/Runner.xcworkspace --scheme dev --config Release-dev
Archive Runner.xcworkspace
Execute "xcodebuild -workspace /Users/builder/clone/ios/Runner.xcworkspace -scheme dev -config Release-dev -archivePath build/ios/xcarchive/Runner_j1t8laki.xcarchive archive COMPILER_INDEX_STORE_ENABLE=NO DEVELOPMENT_TEAM=28759WZ2NP 'CODE_SIGN_IDENTITY=iPhone Distribution'"
❌ error: "Runner" requires a provisioning profile with the Push Notifications feature. Select a provisioning profile in the Signing & Capabilities editor. (in target 'Runner' from project 'Runner')
I've checked the certificate, provision profile and app id for both working flavour and one with signing issue and didn't find any difference.
This helped me.
My command was flutter build ipa --export-options-plist path/to/export.plist --build-number=123 --release --flavor=prod --dart-define=FLAVOR=prod
Sample export.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<true/>
<key>method</key>
<string>enterprise</string>
<key>provisioningProfiles</key>
<dict>
<key>com.company.appname</key>
<string>provisioningProfiles name </string>
</dict>
<key>signingCertificate</key>
<string>iOS Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>xxxxxx</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>
For us, this was solved by adding a "Info.plist File" setting directly to all build schemes.
Before the change, the Info.plist was inherited from the Runner project:
To fix it, double-click on the top-level "Runner/info.plist":
Delete the text, and press return. This should clear the value for all projects.
Then, double-click in the same place, re-enter the same Runner/info.plist value again, and press return.
This should then update all the schemes to have the setting, rather than inheriting it.
The result should look like this:
This was caused by Codemagic's xcode-project use-profiles command. It expects each scheme to specify the Info.plist location, and doesn't parse inherited values.

Azure Devops Pipelines - Xcode project with multiple provisioning profiles

I have configured pipeline to build an iOS app that is also an AUv3 plugin, it requires two provisioning profiles but I can't manage the Plist to allow the signature for both.
I have installed .p12 and Apple Provisioning Profiles.
This is my Xcode task:
steps:
- task: Xcode#5
displayName: 'Xcode build'
inputs:
actions: 'build'
sdk: iphoneos13.7
xcWorkspacePath: ‘project_name/project.xcworkspace'
scheme: 'project_name - All'
packageApp: true
exportPath: output/
exportOptions: plist
exportOptionsPlist: ‘file.plist'
signingOption: auto
teamId: [10-character development team ID]
useXcpretty: false
And here is my .plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>provisioningProfiles</key>
<dict>
<key>com.company.product_name</key>
<string>UUID_Code</string>
<key>com.company.product_name.product_nameAUv3</key>
<string>UUID_Code</string>
</dict>
<key>signingCertificate</key>
<string>iOS Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>method</key>
<string>app-store</string>
<key>teamID</key>
<string>**********</string>
</dict>
</plist>
but Xcode project with multiple provisioning profiles fails archive and sign:
Code Signing Error: No profiles for 'com.company.product_name.product_nameAUv3' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.company.product_name.product_nameAUv3'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild.
Code Signing Error: Code signing is required for product type 'App Extension' in SDK 'iOS 13.7'
Someone have similar setup? This seems I'm missing something.

Xcodebuild: Creating .ipa using -exportarchive always fails to find provisioning profile?

Trying to create ipa from archive running the following command:
xcodebuild -exportArchive -archivePath $PWD/archive/test.xcarchive -exportOptionsPlist exportOptions.plist -exportPath $PWD/build
Always throws an error as follows though I have the profile installed:
error: exportArchive: No "iOS Ad Hoc" profiles for team 'XXXXXXXXXX' matching 'adhoc_profile' are installed.
Error Domain=IDEProfileLocatorErrorDomain Code=4 "No "iOS Ad Hoc" profiles for team 'XXXXXXXXXX' matching 'adhoc_profile' are installed." UserInfo={NSLocalizedDescription=No "iOS Ad Hoc" profiles for team 'XXXXXXXXXX' matching 'adhoc_profile' are installed., NSLocalizedRecoverySuggestion=Install a profile (by dragging and dropping it onto Xcode's dock item) or specify a different profile in your Export Options property list.}
Update: exportOptions.plist as follow
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <dict>
<key>compileBitcode</key> <true/>
<key>method</key>
<string>ad-hoc</string>
<key>provisioningProfiles</key>
<dict>
<key>com.app.appname</key>
<string>adhoc_profile</string> </dict>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>XXXXXXXXXX</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>

Jenkins automated iOS build has SwiftSupport folder missing

Currently I'm having an issue that when jenkins executes a job to generate a .ipa to submit to testflight, Apple sends me the following email:
We have discovered one or more issues with your recent delivery for "XXXXX". To process your delivery, the following issues must be corrected:
Invalid Swift Support - The SwiftSupport folder is missing. Rebuild your app using the current public (GM) version of Xcode and resubmit it.
Once these issues have been corrected, you can then redeliver the corrected binary.
I opened the .ipa that was uploaded and it's true this folder isn't there.
So I tried doing the build manually... I used the same workspace that jenkins uses to generate the builds, and I manually generated a build to upload to AppStore and everything went well...
What might be the problem with the automated build? Is there a step that jenkins might be missing?
Is anyone having the same issue??
Archive the application
xcodebuild \
-workspace "${WORKSPACE_FILE}" \ # only if you are using workspace
-scheme "${SCHEME_NAME}" \
-sdk "${TARGET_SDK}" \
-archivePath "${PROJDIR}/Build/${SCHEME_NAME}.xcarchive" \
-configuration Release \
archive
Export the archive to an ipa
xcodebuild \
-exportArchive \
-archivePath "${PROJDIR}/Build/${SCHEME_NAME}.xcarchive" \
-exportOptionsPlist "${PROJDIR}/exportOptions.plist" \
-exportPath "${PROJDIR}/Release"
exportOptions.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
</dict>
</plist>
Are you specifying the -exportOptionsPlist option on your xcodebuild command?
See xcodebuild -help for the available keys, but you probably want a plist with at least he method key set to "app-store", like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
</dict>
</plist>

Resources