unsigned xcarchive aps environment missing - ios

I want to share unsigned xcarchive. To make unsigned xcarchive. I set Provisional profile and Signing Certificate as None.
I have crated Xcarchive with below commands one by one.
xcodebuild -scheme xxxx -workspace xxx.xcworkspace -configuration Release clean archive -archivePath "/Users/exxx/Desktop/PROD/xxx.xcarchive" CODE_SIGN_ENTITLEMENTS=/Users/exxx/Desktop/PROD/Cert/entitlements.plist CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
& without passing CODE_SIGN_ENTITLEMENTS
xcodebuild -scheme xxxx -workspace xxx.xcworkspace -configuration Release clean archive -archivePath "/Users/exxx/Desktop/PROD/xxx.xcarchive" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
when I upload that archive with Organizer then at final check it shows Entitlement summary where 'aps-environemt' key always missing. I have attached screen shot for reference. Both builds having same issue.
I also tried the same exported archive to codesign with entitlement but that also don't work. (With below command)
codesign --entitlements /Users/xxx/Desktop/PROD/Cert/xxx.entitlements -f -s xxx /Users/xxx/Desktop/PROD/xxx.xcarchive
When My upload completed then getting an email from apple as,
Your app appears to register with the Apple Push Notification service, but the app signature's entitlements do not include the 'aps-environment' entitlement...

To add APS entitlement to your xcarchive you should sign your .app file with entitlements.plist that has aps-environment key (and other needed keys) e.g.:
entitlements.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>aps-environment</key>
<string>development</string>
</dict>
</plist>
Next sign embedded frameworks and your app file with the entitlements:
$ codesign -f -s "<codesiging identity>" -v /foo.xcarchive/Products/Application/foo.app/Frameworks/*
$ codesign -f -s "<codesiging identity>" --entitlements /pathToEntitlements/entitlements.plist /foo.xcarchive/Products/Application/foo.app
To get available codesign identities run next command:
security find-identity -vp codesigning

Related

ERROR ITMS-90171: "Invalid Bundle Structure The binary file MyApp.app/libswiftRemoteMirror.dylib is not permitted

I'm getting below error when trying to upload my ipa which is build on Jenkins.
ERROR ITMS-90171: "Invalid Bundle Structure - The binary file 'ideaPitch.app/libswiftRemoteMirror.dylib' is not permitted. Your app can’t contain standalone executables or libraries, other than the CFBundleExecutable of supported bundles. Refer to the Bundle Programming Guide at https://developer.apple.com/go/?id=bundle-structure for information on the iOS app bundle structure."
How I get the ipa on Jenkins
/usr/bin/xcodebuild -list -workspace My_App.xcworkspace
/usr/bin/xcodebuild -scheme My_App -workspace My_App.xcworkspace -configuration Release clean build CONFIGURATION_BUILD_DIR=${WORKSPACE}/build -UseModernBuildSystem=0
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${WORKSPACE}/build/My_App.app" -o ${WORKSPACE}/build/My_App${PRODUCT_VERSION}-${PRODUCT_VERSION}.ipa
ditto -c -k --keepParent -rsrc "${WORKSPACE}/build/My_App.app.dSYM" ${WORKSPACE}/build/My_App-${PRODUCT_VERSION}-${PRODUCT_VERSION}-dSYM.zip
When I get the ipa on Xcode, everything works fine. However, I need to do it on Jenkins. What can cause this problem? Thank you.
EDIT I searched SO and found some posts (like below one). However, I need to find out which line or code this problem so I can't just directly copy and paste the answer. So please don't mark it as duplicate.
ERROR ITMS-90171: "Invalid Bundle Structure The binary file APP.app/libswiftRemoteMirror.dylib is not permitted
The problem was getting the build and then iPA from It. As I searched, the correct path was archiving the project and then get iPA from the archive with xcodebuild.
The correct two line of code is;
/usr/bin/xcodebuild -quiet -workspace ${workspaceName} -scheme ${schemeName} -sdk iphoneos -configuration Release archive -archivePath ${WORKSPACE}/build/${appName}.xcarchive
/usr/bin/xcodebuild -exportArchive -archivePath ${WORKSPACE}/build/${appName}.xcarchive -exportOptionsPlist My_Project_Main_Folder/Resources/${environment}/${environment}_ExportOptions.plist -exportPath ${WORKSPACE}/build
P.S: There is a difference between PackageApplication and Xcodebuild. Xcodebuild needs an export options plist file which tells Xcodebuild, what options does it use like Certificate, Provisioning file and Bitcode Support etc..
Example Export Options 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>compileBitcode</key>
<false/>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>development</string>
<key>provisioningProfiles</key>
<dict>
<key>com.iamdeveloper.myapp.dev</key>
<string>My App Development Provision</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Developer</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>XXXXXXXXXX</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>

Error: no provisioning profile matches xcode build

BuilSettings[REFERENCE IMAGE1][1]I'm creating an script to automate ios build to generate .ipa ... Below is my script,
# xcodebuild -workspace "project.xcworkspace" -scheme "Schemename" clean
# xcodebuild -workspace "project.xcworkspace" -scheme "Schemename" build
# xcodebuild archive -workspace "project.xcworkspace" -scheme "schemename" -archivePath "project.xcworkspace.xcarchive"
# xcodebuild -exportArchive -archivePath "project.xcworkspace.xcarchive" -exportPath "project.xcworkspace" -exportFormat ipa -exportProvisioningProfile "Digi Form Development": *"
while executing above script getting an error of,
--- xcodebuild: WARNING: -exportArchive without -exportOptionsPlist is deprecated error: no provisioning profile matches 'Digi Form
Development: *'
** EXPORT FAILED **
Since I'm new to this ios build deployment using xcode cli kindly help me on to correct my problems,
You need to create a exportOptions.plist file, then add the command line flag as so:
-exportOptionsPlist exportOptions.plist
The export options plist should look something like the following:
<?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>method</key>
<string>ad-hoc</string>
<key>provisioningProfiles</key>
<dict>
<key>my.bundle.idenifier</key>
<string>My Provisioning Profile Name</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>YOURTEAMID</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>
Note that signing style can be manual or automatic. If you are explicitly setting the provisioning profile, which I tend to do, use manual and specify the provisioning profile name explicitly. If automatic, Xcode will try to automatically find a matching profile.
For the method field, the options are: development, ad-hoc, distribution and enterprise.
Here is a link with a more general description on this feature: http://devcenter.bitrise.io/tips-and-tricks/xcodebuild-export-options/

How to sign an ad-hoc iOS build without beta-reports-active entitlement?

I'm trying do an ad-hoc distribution of an app, I'm building it succesfully but getting the next error when trying to install it though iTunes:
MIS: entitlement 'beta-reports-active' has value not permitted by provisioning profile 'name_of_prov_file'
The beta-reports-active field is not set in the ad-hoc provisioning file, which is fine, but for some reason this entitlement is being added to the app in the embedded.mobileprovision file within the IPA. I think this is the problem.
I tried specifying a custom entitlements plist with:
<dict>
<key>application-identifier</key>
<string>xxxxxxxx</string>
<key>beta-reports-active</key>
<false/>
</dict>
This is showing up in the IPA in the archived-expanded-entitlements.xcent file. But the embedded.mobileprovision file still has it set to true.
I'm using these export options:
<key>method</key>
<string>ad-hoc</string>
<key>uploadSymbols</key>
<true/>
<key>teamID</key>
<string>xxxxxxxxxxxx</string>
<key>compileBitcode</key>
<false/>
And these commands:
xcodebuild -alltargets -configuration Release clean build archive -archivePath $PWD/build/archive.xcarchive -scheme projectname -sdk iphoneos9.3 "CODE_SIGN_IDENTITY=${CODE_SIGN_IDENTITY}" "CODE_SIGN_ENTITLEMENTS=entitlements.plist"
xcodebuild -exportArchive -archivePath $PWD/build/archive.xcarchive -exportPath $PWD/build/ -exportOptionsPlist exportOptions.plist
It's a Cordova application so it's not being developed with XCode and this is a Jenkins automated build.
Note: I can successfully do an app-store build for test flight, this is not what this questions is about.

Errors converting xcarchive to IPA - single-bundle archive + missing plist method values

I'm trying to convert my xcarchive to an IPA (XCode 7.1.1). The following command
xcodebuild
-exportArchive -archivePath foo.xcarchive -exportPath . -exportFormat IPA
Fails with the error
the archive at path 'foo.xcarchive' is not a single-bundle archive
Since the above command is technically deprecated, I also tried the new form:
xcodebuild
-exportArchive -archivePath foo.xcarchive -exportPath .
-exportOptionsPlist ipa.plist
Where the ipa.plist is as follows:
<?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>
Which then resulted in the error:
error: exportArchive: exportOptionsPlist error for key 'method':
expected one of {}, but found app-store
Now, trying to debug this I opened the xcarchive folder and inspected its structure. I noticed that I have a folder on the same level as Products\Applications\foo.app so I deleted it and tried again to no avail (same results). I then proceeded to delete files from within foo.app until I remained with nothing but the DWARF binary - still no cigar (same result), though that could have been due to the fact that I messed up the app signature by deleting files manually.
Apple got back to me with a solution. As of Xcode 7 we should use xcodebuild instead of PackageApplication to produce the .ipa file.
xcodebuild has a new -exportArchive option to create an .ipa that works more like Xcode Organizer.
So we should now:
build an archive with xcodebuild archive
create the .ipa with xcodebuild -exportArchive
We now build the archive like this:
xcodebuild -workspace myApp.xcworkspace -scheme myApp -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/myApp.xcarchive
We now export the .ipa like this:
xcodebuild -exportArchive -archivePath $PWD/build/myApp.xcarchive -exportOptionsPlist exportOptions.plist -exportPath $PWD/build
These two command create the files build/myApp.xcarchive and build/myApp.ipa
Note that xcodebuild -exportArchive requires a -exportOptionsPlist argument that points to a .plist file with export options. For a complete list of what you can put in that plist, run xcodebuild -help. The minimal contents of the file looks 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>
<key>teamID</key>
<string>YOUR_TEN_CHARACTER_TEAM_ID</string>
</dict>
</plist>
Since the way you are creating an IPA is deprecated, you should do the following instead:
xcodebuild -scheme "Foo" -configuration Release clean build CODE_SIGN_IDENTITY="iPhone Distribution: Foo Corporation" -derivedDataPath "/path/to/some/folder/"
xcrun -sdk iphoneos PackageApplication "/path/to/some/folder/Build/Products/Release-iphoneos/foo.app" -o "/path/to/some/folder/foo.ipa"
Make sure you replace "Foo" with your schema name, and "iPhone Distribution: Foo Corporation" with your signing identity. And "/path/to/some/folder/" should be some build folder.
I got some similar strange errors from XCode 7.2 when building for the simulator on the command line. You could try to either add -sdk iphoneos to your xcodebuild command (in order to skip simulator builds), or add something like -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' if you're building for the simulator.
Try using absolute paths as parameters to xcodebuild options rather than relative paths.
So something like this:
xcodebuild -exportArchive -archivePath "$PWD/foo.xcarchive" \
-exportPath "$PWD" -exportOptionsPlist "$PWD/ipa.plist"
As long as your .xcarchive is intact and signed correctly, that should work. This is what I'm using in my build system.
I recently switched to using the fastlane gym tool to build and create ipa files... I had a problem where one command line worked for making ad-hoc builds and I needed a different config to make app store builds and couldn't resolve it. The fastlane stuff pretty much worked out of the box.
https://github.com/fastlane/gym
The problem was that one of our post-build steps left a stray folder in the TARGET_BUILD_DIR. This caused the generated xcarchive to be formatted as the dreaded generic archive. My attempts to delete the folder after the fact from the xcarchive itself were doomed to fail since the xcarchive has been flagged generic at the moment of its creation (as evidenced by some missing Info.plist fields). Once I made sure TARGET_BUILD_DIR contained only the .app after all the build phases were said and done, the generated xcarchive was formatted properly as an iOS app archive. That xcarchive, in turn, was easily exported to a proper IPA via xcodebuild -exportArchive -exportPlistOptions, which is the officially supported Apple recommendation that takes care of all the problematic SWIFT support folders and the like.
The archive at path foo.xcarchive is not a single-bundle archive.
About this error:
check edit scheme -> Build
untick other targets, including Analyze, Test, Run, Profile, Archive
xcodebuild the archive
export the archive again

xcodebuild archive fails ITMS validation

Our app has a watchkit app + extension. Archives from XCode IDE always pass iTunes store validation. However archives generated via xcodebuild command tools (Xcode 6.4; Build version 6E35b) fail this validation with the following errors:
ERROR ITMS-90163: "Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. The bundle contains a key that is not included in the provisioning profile: 'aps-environment' in 'Payload/TheDodo.app/PlugIns/DodoExtension.appex/DodoExtension'."
ERROR ITMS-90164: "Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. According to the provisioning profile, the bundle contains a key value that is not allowed: '##########.###.##########.######' for the key 'application-identifier' in 'Payload/TheDodo.app/PlugIns/TheDodoWatchKitExtension.appex/TheDodoWatchKitExtension'"
ERROR ITMS-90163: "Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. The bundle contains a key that is not included in the provisioning profile: 'aps-environment' in 'Payload/TheDodo.app/PlugIns/TheDodoWatchKitExtension.appex/TheDodoWatchKitExtension'."
ERROR ITMS-90046: "Invalid Code Signing Entitlements. Your application bundle's signature contains code signing entitlements that are not supported on iOS. Specifically, value '##########.###.##########.######' for key 'application-identifier' in 'Payload/TheDodo.app/PlugIns/TheDodoWatchKitExtension.appex/TheDodoWatchKitExtension' is not supported. This value should be a string starting with your TEAMID, followed by a dot '.', followed by the bundle identifier."
ERROR ITMS-90163: "Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. The bundle contains a key that is not included in the provisioning profile: 'aps-environment' in 'Payload/TheDodo.app/PlugIns/TheDodoWatchKitExtension.appex/TheDodoWatchKitApp.app/TheDodoWatchKitApp'."
ERROR ITMS-90163: "Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. The bundle contains a key that is not included in the provisioning profile: 'com.apple.security.application-groups' in 'Payload/TheDodo.app/PlugIns/TheDodoWatchKitExtension.appex/TheDodoWatchKitApp.app/TheDodoWatchKitApp'."
The Makefile to archive and export looks something like this:
/usr/bin/xcodebuild -verbose -verbose -workspace 'rebelmouse.xcworkspace' -scheme TheDodo -configuration "App Store" -sdk 'iphoneos' -archivePath /tmp/TheDodo.xcarchive -derivedDataPath /tmp/ROJECT.Ji9vwyH0 APPLICATION_BUILD_VERSION=2456 archive
/usr/bin/xcodebuild -exportArchive -exportFormat ipa -archivePath /tmp/TheDodo.xcarchive -exportPath /tmp/TheDodo.ipa -exportWithOriginalSigningIdentity
Any suggestion / help is very appreciated. Thanks in advance.
Answering this in case anyone else is stuck in the same boat.
With Xcode 7.0 the xcodebuild acquired a new command line option to export archive namely the exportOptionsPlist , this takes a full path to a plist that configures the archive.
You no longer need to set the -exportFormat
xcodebuild --help lists the details of the plist.
For enterprise builds I use this plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>enterprise</string>
</dict>
</plist>
For App Store builds replace replace enterprise with app-store.
tell xcodebuild the name of the provisioning profile to use instead of having it 'auto-search' it:
xcodebuild -exportArchive -exportFormat ipa -archivePath "FOLD/FILE.xcarchive" -exportPath "FOLD/FILE.ipa" -exportProvisioningProfile "NAME" > /dev/null || exit 1

Resources