Xcode “Build and Archive” from command line

前端 未结 20 1063
死守一世寂寞
死守一世寂寞 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 13:56

    The xcodebuild tool can build and export archive products with the -exportArchive flag (as of Xcode 5). The export step was previously only possible via the Xcode Organizer UI.

    First archive your app:

    xcodebuild -scheme <scheme name> archive
    

    Given $ARCHIVE_PATH (the path to the .xcarchive file), export the app from the archive with one of the following:

    iOS .ipa file:

    xcodebuild -exportArchive -exportFormat ipa -archivePath "$ARCHIVE_PATH" -exportPath "myApp.ipa" -exportProvisioningProfile "My App Provisioning profile"
    

    Mac .app file:

    xcodebuild -exportArchive -exportFormat app -archivePath "$ARCHIVE_PATH" -exportPath "myApp.app" -exportSigningIdentity "Developer ID Application: My Software Company"
    

    In both commands the -exportProvisioningProfile and -exportSigningIdentity arguments are optional. man xcodebuild for details on the semantics. In these examples, the provisioning profile for the iOS build specified an AdHoc distribution provisioning profile, and the signing identity for the Mac app specified a Developer ID for export as a 3rd party application (i.e. not distributed via the Mac App Store).

    0 讨论(0)
  • 2020-11-22 13:56

    Open Terminal & drag and drop your project folder:

    cd /Users/username/Desktop/demo/

    Execute the following commands one by one:

    Builds app as-"demo.xcodeproj" into an archive

    xcodebuild archive -project demo.xcodeproj -scheme demo -archivePath /Users/username/Desktop/demo.xcarchive

    If your app has Podfile fie as-"demo.xcworkspace"-

    xcodebuild -workspace Project-Name.xcworkspace -scheme Scheme-Name -sdk iphoneos -configuration Release Provisioning_Profile=“Provision-Name” Development_Team=“Team-ID” archive -archivePath /Path/To/Output/AppName.xcarchive archive

    IPA Export Build Command

    Download ExportOptions.plist file from Here

    xcodebuild -exportArchive -archivePath /Users/shilpa/Desktop/demo.xcarchive -exportPath /Users/shilpa/Desktop/demo.ipa -exportOptionsPlist /Users/shilpa/Downloads/ExportOptions.plist

    You will find .xcarchive to .ipa using terminal details in the article.

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

    I've been using my own build script to generate the ipa package for ad hoc distribution.

    die() {
        echo "$*" >&2
        exit 1
    }
    
    appname='AppName'
    config='Ad Hoc Distribution'
    sdk='iphoneos3.1.3'
    project_dir=$(pwd)
    
    echo using configuration $config
    
    echo updating version number
    agvtool bump -all
    fullversion="$(agvtool mvers -terse1)($(agvtool vers -terse))"
    echo building version $fullversion
    
    xcodebuild -activetarget -configuration "$config" -sdk $sdk build || die "build failed"
    
    echo making ipa...
    # packaging
    cd build/"$config"-iphoneos || die "no such directory"
    rm -rf Payload
    rm -f "$appname".*.ipa
    mkdir Payload
    cp -Rp "$appname.app" Payload/
    if [ -f "$project_dir"/iTunesArtwork ] ; then
        cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork
    fi
    
    ipaname="$appname.$fullversion.$(date -u +%Y%m%d%H%M%S).ipa"
    zip -r $ipaname Payload
    
    echo finished making $ipaname
    

    The script also increment the version number. You can remove that part if it's not needed. Hope it helps.

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

    Go to the folder where's your project root and:

    xcodebuild -project projectname -activetarget -activeconfiguration archive
    
    0 讨论(0)
  • 2020-11-22 14:02

    Going one step further, uploading to iTunesConnect via commandline with Xcode 7! (Assuming you are starting with an .ipa that has been signed with the correct release profile and signing identity.)

    Enter altool, the CLI interface for the Application Loader (docs, page 38). Hidden deep within Xcode.app's structure, is a handy function to let us upload directly to ItunesConnect.

    /Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool
    

    Simply run $ altool --upload-app -f file -u username [-p password] to upload your newly minted .ipa straight to Apple. The password is optional, and will prompt you for it if you leave it off the command.

    If there are any issues with the app during the verification step, the console will print them out.

    You will likely have to export the path to altool if you don't want to save its location.

    export PATH=$PATH:/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/
    

    Thats it! Simply login to iTunesConnect.com and select your new build for testing with testflight.

    Final Note: If you get an error saying Exception while launching iTunesTransporter: Transporter not found at path: /usr/local/itms/bin/iTMSTransporter. You should reinstall the application, you can follow the suggestion on this SO answer, to run a symlink to the correct location:

    ln -s /Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/itms /usr/local/itms
    
    0 讨论(0)
  • 2020-11-22 14:03

    After updating to Xcode 8, I found that enterprise ipa generate by

    /usr/bin/xcrun -sdk iphoneos PackageApplication -v "${RELEASE_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPER_NAME}" --embed "${PROVISONING_PROFILE}" 
    

    Command cannot be launched because of some signature issue. The log indicates that "warning: PackageApplication is deprecated, use xcodebuild -exportArchive instead.

    So I switch to xcodebuild -exportArchive and everything went back normal.

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