Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

xcode - iOS builds / ipa creation no longer works from the command line

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...