Xcode “Build and Archive” from command line

前端 未结 20 1049
死守一世寂寞
死守一世寂寞 2020-11-22 13:52

Xcode 3.2 provides an awesome new feature under the Build menu, \"Build and Archive\" which generates an .ipa file suitable for Ad Hoc distribution. You can also open the O

相关标签:
20条回答
  • 2020-11-22 14:06

    For Xcode 7, you have a much simpler solution. The only extra work is that you have to create a configuration plist file for exporting archive.

    (Compared to Xcode 6, in the results of xcrun xcodebuild -help, -exportFormat and -exportProvisioningProfile options are not mentioned any more; the former is deleted, and the latter is superseded by -exportOptionsPlist.)

    Step 1, change directory to the folder including .xcodeproject or .xcworkspace file.

    cd MyProjectFolder
    

    Step 2, use Xcode or /usr/libexec/PlistBuddy exportOptions.plist to create export options plist file. By the way, xcrun xcodebuild -help will tell you what keys you have to insert to the plist file.

    Step 3, create .xcarchive file (folder, in fact) as follows(build/ directory will be automatically created by Xcode right now),

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

    Step 4, export as .ipa file like this, which differs from Xcode6

    xcrun xcodebuild -exportArchive -exportPath build/ -archivePath build/MyApp.xcarchive/ -exportOptionsPlist exportOptions.plist
    

    Now, you get an ipa file in build/ directory. Just send it to apple App Store.

    By the way, the ipa file created by Xcode 7 is much larger than by Xcode 6.

    0 讨论(0)
  • 2020-11-22 14:07

    You CAN actually resign a build, just as XCode does, so that you can test and ship the same binary. For example in my script (similar to those above) I build my release version signed as an AdHoc build, then I archive that as an IPA for testing, then resign with my distribution cert and create a zip file, which is what I send to Apple. The relevant line is:

    codesign -f -vv -s "$DistributionIdentity" "$APPDIR"
    
    0 讨论(0)
  • 2020-11-22 14:10

    We developed an iPad app with XCode 4.2.1 and wanted to integrate the build into our continuous integration (Jenkins) for OTA distribution. Here's the solution I came up with:

    # Unlock keychain
    security unlock-keychain -p jenkins /Users/jenkins/Library/Keychains/login.keychain
    
    # Build and sign app
    xcodebuild -configuration Distribution clean build
    
    # Set variables
    APP_PATH="$PWD/build/Distribution-iphoneos/iPadApp.app"
    VERSION=`defaults read $APP_PATH/Info CFBundleShortVersionString`
    REVISION=`defaults read $APP_PATH/Info CFBundleVersion`
    DATE=`date +"%Y%m%d-%H%M%S"`
    ITUNES_LINK="<a href=\"itms-services:\/\/?action=download-manifest\&url=https:\/\/xxx.xxx.xxx\/iPadApp-$VERSION.$REVISION-$DATE.plist\">Download iPad2-App v$VERSION.$REVISION-$DATE<\/a>"
    
    # Package and verify app
    xcrun -sdk iphoneos PackageApplication -v build/Distribution-iphoneos/iPadApp.app -o $PWD/iPadApp-$VERSION.$REVISION-$DATE.ipa
    
    # Create plist
    cat iPadApp.plist.template | sed -e "s/\${VERSION}/$VERSION/" -e "s/\${DATE}/$DATE/" -e "s/\${REVISION}/$REVISION/" > iPadApp-$VERSION.$REVISION-$DATE.plist
    
    # Update index.html
    curl https://xxx.xxx.xxx/index.html -o index.html.$DATE
    cat index.html.$DATE | sed -n '1h;1!H;${;g;s/\(<h3>Aktuelle Version<\/h3>\)\(.*\)\(<h3>&Auml;ltere Versionen<\/h3>.<ul>.<li>\)/\1\
    ${ITUNES_LINK}\
    \3\2<\/li>\
    <li>/g;p;}' | sed -e "s/\${ITUNES_LINK}/$ITUNES_LINK/" > index.html
    

    Then Jenkins uploads the ipa, plist and html files to our webserver.

    This is the plist template:

    <?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>items</key>
        <array>
            <dict>
                <key>assets</key>
                <array>
                    <dict>
                        <key>kind</key>
                        <string>software-package</string>
                        <key>url</key>
                        <string>https://xxx.xxx.xxx/iPadApp-${VERSION}.${REVISION}-${DATE}.ipa</string>
                    </dict>
                    <dict>
                        <key>kind</key>
                        <string>full-size-image</string>
                        <key>needs-shine</key>
                        <true/>
                        <key>url</key>
                        <string>https://xxx.xxx.xxx/iPadApp.png</string>
                    </dict>
                    <dict>
                        <key>kind</key>
                        <string>display-image</string>
                        <key>needs-shine</key>
                        <true/>
                        <key>url</key>
                        <string>https://xxx.xxx.xxx/iPadApp_sm.png</string>
                    </dict>
                </array>
                <key>metadata</key>
                <dict>
                    <key>bundle-identifier</key>
                    <string>xxx.xxx.xxx.iPadApp</string>
                    <key>bundle-version</key>
                    <string>${VERSION}</string>
                    <key>kind</key>
                    <string>software</string>
                    <key>subtitle</key>
                    <string>iPad2-App</string>
                    <key>title</key>
                    <string>iPadApp</string>
                </dict>
            </dict>
        </array>
    </dict>
    </plist>
    

    To set this up, you have to import the distribution certificate and provisioning profile into the designated user's keychain.

    0 讨论(0)
  • 2020-11-22 14:10

    How to build iOS project with command?

    Clean : codebuild clean -workspace work-space-name.xcworkspace -scheme scheme-name 
    

    &&

    Archive : xcodebuild archive -workspace work-space-name.xcworkspace -scheme "scheme-name" -configuration Release -archivePath IPA-name.xcarchive 
    

    &&

    Export : xcodebuild -exportArchive -archivePath IPA-name.xcarchive -exportPath IPA-name.ipa -exportOptionsPlist exportOptions.plist
    


    What is ExportOptions.plist?

    ExportOptions.plist is required in Xcode . It lets you to specify some options when you create an ipa file. You can select the options in a friendly UI when you use Xcode to archive your app.

    Important: Method for release and development is different in ExportOptions.plist

    AppStore :

    exportOptions_release ~ method = app-store

    Development

    exportOptions_dev ~ method = development

    0 讨论(0)
  • 2020-11-22 14:11

    Improving on Vincent's answer, I wrote a script to do that: xcodearchive
    It allows you to archive (generate an ipa) your project via the command line. Think of it like the sister of the xcodebuild command, but for archiving.

    Code is available on github: http://github.com/gcerquant/xcodearchive


    One option of the script is to enable the archiving of the dSYM symbols in a timestamped archive. No excuse to not keep the symbols anymore, and not be able to symbolicate the crash log you might later receive.

    0 讨论(0)
  • 2020-11-22 14:12

    Xcode 8:


    IPA Format:

    xcodebuild -exportArchive -exportFormat IPA -archivePath MyMobileApp.xcarchive -exportPath MyMobileApp.ipa -exportProvisioningProfile 'MyMobileApp Distribution Profile'
    

    Exports the archive MyMobileApp.xcarchive as an IPA file to the path MyMobileApp.ipa using the provisioning profile MyMobileApp Distribution Profile.

    APP Format:

    xcodebuild -exportArchive -exportFormat APP -archivePath MyMacApp.xcarchive -exportPath MyMacApp.pkg -exportSigningIdentity 'Developer ID Application: My Team'
    

    Exports the archive MyMacApp.xcarchive as a PKG file to the path MyMacApp.pkg using the appli-cation application cation signing identity Developer ID Application: My Team. The installer signing identity Developer ID Installer: My Team is implicitly used to sign the exported package.

    Xcodebuild man page

    0 讨论(0)
提交回复
热议问题