38

Overview

Our command line builds (to build and create the .ipa) are no longer working.

iTunesConnect has started rejecting builds that use the CODE_SIGN_RESOURCE_RULES_PATH build setting.

If we build WITHOUT that setting the PackageApplication tool (which we use to create the signed .ipa) fails.

It seems that PackageApplication calls /usr/bin/codesign with resource-rules arguments even if the CODE_SIGN_RESOURCE_RULES_PATH build setting is excluded

I suspect the PackageApplication needs to be updated so that it does not call /usr/bin/codesign with resource-rules arguments when the CODE_SIGN_RESOURCE_RULES_PATH build setting is excluded.

Has anyone found a solution for this?

Details

We build our app on the command line like this:

xcodebuild -workspace myApp.xcworkspace -scheme myApp -sdk iphoneos -configuration AppStoreDistribution OBJROOT=$PWD/build SYMROOT=$PWD/build ONLY_ACTIVE_ARCH=NO 'CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist'

We create the signed .ipa on the command line like this:

xcrun -log -sdk iphoneos PackageApplication "/Users/mpv/dev/myApp/build/AppStoreDistribution-iphoneos/myApp.app" -o "/Users/mpv/dev/myApp/build/AppStoreDistribution-iphoneos/myApp.ipa" -sign "iPhone Distribution: MyTeam (XXXXXXXXXX)" -embed /Users/mpv/Library/MobileDevice/Provisioning\ Profiles/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.mobileprovision

iTunesConnect is now rejecting our builds with the following error:

"This bundle is invalid. The Info.plist contains an invalid key 'CFBundleResourceSpecification' in bundle myApp [myApp.app]"

If we remove the 'CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist' bit from the build command then the app is built without the CFBundleResourceSpecification plist key (which I presume is what we want). The new build command looks like this:

xcodebuild -workspace myApp.xcworkspace -scheme myApp -sdk iphoneos -configuration AppStoreDistribution OBJROOT=$PWD/build SYMROOT=$PWD/build ONLY_ACTIVE_ARCH=NO 

The problem now is that the command to build the .ipa fails with the following error:

error: /usr/bin/codesign --force --preserve-metadata=identifier,entitlements,resource-rules --sign iPhone Distribution: MyTeam (XXXXXXXXXX) --resource-rules=/var/folders/2b/7hylk7nn13dgrl9yyh2wp0lm0000gn/T/zDRRJMkKtQ/Payload/myApp.app/ResourceRules.plist --entitlements /var/folders/2b/7hylk7nn13dgrl9yyh2wp0lm0000gn/T/zDRRJMkKtQ/entitlements_plistIUdGWLYe /var/folders/2b/7hylk7nn13dgrl9yyh2wp0lm0000gn/T/zDRRJMkKtQ/Payload/myApp.app failed with error 1. Output: Warning: usage of --preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!

Warning: --resource-rules has been deprecated in Mac OS X >= 10.10! /var/folders/2b/7hylk7nn13dgrl9yyh2wp0lm0000gn/T/zDRRJMkKtQ/Payload/myApp.app/ResourceRules.plist: cannot read resources

It seems that PackageApplication calls /usr/bin/codesign with resource-rules arguments even if the CODE_SIGN_RESOURCE_RULES_PATH argument / build setting is excluded.

I think PackageApplication needs to be updated so that it does not call /usr/bin/codesign with resource-rules arguments when the CODE_SIGN_RESOURCE_RULES_PATH argument / build setting is excluded.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mike Vosseller
  • 4,097
  • 5
  • 26
  • 28
  • Hello, I already have an unanswered question about exactly the same issue: http://stackoverflow.com/questions/32720442/build-ios-app-and-distribute-ipa-via-testflight-with-jenkins-and-xcode-7 – dreamzor Sep 24 '15 at 14:01
  • Hey I'm getting this error "Ld /Users/confiz/Library/Developer/Xcode/DerivedData/CloudMessage-afevkkqtjcnmoddycvosdhbgoraa/Build/Intermediates/ArchiveIntermediates/LTDMessaging/IntermediateBuildFilesPath/CloudMessage.build/Release-iphoneos/LTDMessaging.build/Objects-normal/arm64/LTD\ Messaging normal arm64" if i try to archive from command line but it works fine from Xcode. I really don't know how to solve it. – aqsa arshad Dec 14 '16 at 10:37

5 Answers5

114

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:

  1. build an archive with xcodebuild archive
  2. 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>

In Xcode 9, you now have to specify more details in exportOptions.plist like below:

<?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.identifier</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>&lt;none&gt;</string>
</dict>
</plist> 
Duck
  • 34,902
  • 47
  • 248
  • 470
Mike Vosseller
  • 4,097
  • 5
  • 26
  • 28
  • I was able to `xcodebuild -archive` without specifying the options plist `-exportOptionsPlist` – ehrpaulhardt Oct 13 '15 at 13:30
  • 1
    If you look closely at the output I believe it says something to the effect of using `-archive` without `-exportOptionsPlist` is deprecated. – Mike Vosseller Oct 13 '15 at 17:58
  • Yes you are right, there is a deprecation warning in the output log. Thx for clarification. – ehrpaulhardt Oct 14 '15 at 09:01
  • 6
    can i send you a beer? – AndroidGecko Mar 01 '16 at 12:10
  • @AndroidGecko Sure! Next time you are in Boston. ;-) – Mike Vosseller May 27 '16 at 12:13
  • what is the "method" for distribution cert and not app-store? – Sami Aug 08 '16 at 01:36
  • 1
    @HussamEddin `xcodebuild -help` provides some documentation. Regarding the `method` key it says `Available options: app-store, ad-hoc, package, enterprise, development, and developer-id.` I haven't tried those myself but I assume one of those is what you need. – Mike Vosseller Aug 08 '16 at 16:20
  • 1
    @MikeVosseller, Thank you for your reply. Appreciate it. – Sami Aug 08 '16 at 16:52
  • Not the author.... but http://subathrathanabalan.com/2016/01/07/building-ipa-export-archive/ helps a ton on the raw mechanics of translating the old PackageApplication syntax to the new love. – slumtrimpet Oct 03 '16 at 15:01
  • Is that minimal? I thought the `teamID` has a default value, "the team used to build the archive", and so could be omitted? – dumbledad Nov 01 '16 at 13:27
  • AppStoreDistribution is default or ur created configuration? How does it work with profiles? where to put the profile info? I see u are making App Store ipa but not using any profile info. Does teamID replace it or u have info in configuration? – Sazzad Hissain Khan Feb 21 '17 at 05:38
  • Guys, I am also trying to find a way how is `myApp.ipa` defined. Is there a way to change the resulting IPA name at the export step execution? If no, then how it can me changed finally? – RAM237 May 05 '17 at 12:16
  • In Xcode 9.3 while building archive using above code I am getting error: Check dependencies:Code Signing Error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "XXXXXXXX" with a private key was found. – Rajinder Chandel Jun 04 '18 at 16:32
  • What is `My Provisioning Profile Name`? Is it a file path? – kelin Apr 18 '21 at 18:59
  • @kelin I too am working on this and I believe `My Provisioning Profile Name` is the value for the `Name` key inside the provisioning profile. – blinkmacalahan Apr 23 '22 at 05:17
  • @blinkmacalahan, why do you think it's under `my.bundle.identifier` key? For me looks malformed. – kelin Apr 23 '22 at 09:02
  • @kelin the key is literally called `Name`. Find that key and then use its value. You can also use the UUID of the provisioning profile. You can easily find both by previewing your provisioning profile in the Mac finder. Simply find the provisioning profile in the Mac Finder, single click it to highlight the file, and hit spacebar on it to view a preview. The `Name` is the top value shown in the preview. You'll find the UUID a few lines down. – blinkmacalahan Apr 25 '22 at 05:30
17

Steps to make iPA Usig terminal

Clean Project:

Release

xcodebuild clean -project ProjectPath/myApp.xcodeproj -configuration  ReleaseAdhoc  -alltargets

Debug

xcodebuild clean -project ProjectPath/myApp.xcodeproj -configuration Debug -alltargets

Archive Project:

Debug

xcodebuild archive -project  ProjectPath/myApp.xcodeproj  -scheme “myApp” -configuration Debug  -archivePath  pathForArchiveFolder/myApp.xcarchive

Release

xcodebuild archive -project  ProjectPath/myApp.xcodeproj  -scheme “myApp”  -archivePath  pathForArchiveFolder/myApp.xcarchive

Export IPA

Older Version: This may give A signed resource has been added, modified, or deleted. Error

xcodebuild -exportArchive -archivePath  projectPath/myapp.xcarchive  -exportPath  projectPath/myApp.ipa  -exportFormat ipa  -exportProvisioningProfile  “provisioning profile”

New version:

xcodebuild -exportArchive -archivePath  ProjectPath/myapp.xcarchive  -exportPath  projectPath/myApp.ipa  -exportOptionsPlist  ProjectFolder/exportPlist.plist
Devesh.452
  • 893
  • 9
  • 10
2

Go to project folder:

Archive:

for DEBUG:

xcrun xcodebuild -scheme MyApp -configuration Debug archive -archivePath build/MyApp.xcarchive

for Release:

xcrun xcodebuild -scheme MyApp -configuration Release archive -archivePath build/MyApp.xcarchive

Fetch iPA:

xcrun xcodebuild -exportArchive -exportPath build/ -archivePath build/MyApp.xcarchive/
madlymad
  • 6,367
  • 6
  • 37
  • 68
Devesh.452
  • 893
  • 9
  • 10
2

Here's a quick tip in case you need to create the exportOptions.plist file as part of your build process (maybe Jenkins).

You can use the plutil tool to turn JSON into a plist. Example:

echo "{\"method\":\"app-store\"}" | plutil -convert xml1 -o /tmp/exportOptions.plist -- -

Enjoy!

Johannes Fahrenkrug
  • 42,912
  • 19
  • 126
  • 165
0

I have created a project name myFirstApp and the location of the project is Desktop/myFirstApp. Tested on Xcode 8.3

Step 1 -

cd /Users/Ved/Desktop/myFirstApp/

Step 2 -

xcodebuild -scheme myFirstApp archive \

-archivePath /Users/Ved/Desktop/myFirstApp.xcarchive

Step 3 -

xcodebuild -exportArchive -exportFormat ipa \

-archivePath "/Users/Ved/Desktop/myFirstApp.xcarchive" \

-exportPath "/Users/Ved/Desktop/myFirstApp.ipa" \

-exportProvisioningProfile "myFirstAppDevProfile"
Ved Rauniyar
  • 1,539
  • 14
  • 21