Xcode “Build and Archive” from command line

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

    I found some of the other answers here hard to get going. This article did if for me. Some paths may need to be absolute, as mentioned in the other answers.

    The Command:

    xcrun -sdk iphoneos PackageApplication \
        "/path/to/build/MyApp.app" \
        -o "output/path/to/MyApp.ipa" \
        --sign "iPhone Distribution: My Company" \
        --embed "/path/to/something.mobileprovision"
    
    0 讨论(0)
  • 2020-11-22 14:13

    I have given a brief description of steps to follow, and parameters to pass while generating an ipa using terrminal below:

    1. Go to the folder which contains the MyApp.xcodeproject file in terminal

    2. By using the command given below you will get all the Targets of the application

      /usr/bin/xcodebuild -list 
      
    3. After the above command is executed, you will get a list of targets of which you should select a specific target you need to generate .ipa

      /usr/bin/xcodebuild -target $TARGET -sdk iphoneos -configuration Release
      
    4. The above command builds the project and creates a .app file.The path to locate the .app file is ./build/Release-iphoneos/MyApp.app

    5. After Build gets succeeded then execute the following command to generate .ipa of the application using Developer Name and Provisioning Profile using the syntax below:

      /usr/bin/xcrun -sdk iphoneos PackageApplication -v “${TARGET}.app” -o “${OUTDIR}/${TARGET}.ipa” –sign “${IDENTITY}” –embed “${PROVISONING_PROFILE}”
      

    Explanation of each Parameter in the above syntax:

    ${TARGET}.app                == Target path (ex :/Users/XXXXXX/desktop/Application/build/Release-iphoneos/MyApp.app)
    ${OUTDIR}                    == Select the output directory(Where you want to save .ipa file)
    ${IDENTITY}                   == iPhone Developer: XXXXXXX (XXXXXXXXXX)(which can be obtained from Keychain access)
    ${PROVISONING_PROFILE}   == Path to the provisioning profile(/Users/XXXXXX/Library/MobileDevice/Provisioning Profiles/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.mobileprovision”)
    
    1. ipa will be generated at selected output directory "${OUTDIR}"
    0 讨论(0)
  • 2020-11-22 14:14

    if you use next tool: https://github.com/nomad/shenzhen

    then this task is very easy:

    which ipa 1>/dev/null 2>&1 || echo 'no shenzhen. to install use: sudo gem install shenzhen --no-ri --no-rdoc'
    ipa build --verbose --scheme "${schemeName}"
    

    source

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

    Updating my answer with Xcode 9 and Swift

    Archive

    xcodebuild -workspace <ProjectName>/<ProjectName>.xcworkspace \
      -scheme <schemeName> clean archive -configuration release \
      -sdk iphoneos -archivePath <ProjectName>.xcarchive
    

    IPA Export (please note the export option plist)

    xcodebuild -exportArchive -archivePath  <ProjectName>.xcarchive \
      -exportOptionsPlist  <ProjectName>/exportOptions.plist \
      -exportPath  <ProjectName>.ipa
    

    For those who don't know about exportOptions.plist, https://blog.bitrise.io/new-export-options-plist-in-xcode-9


    Those who were using this for building project in CI/CD tools like teamcity/jenkins, please make sure you are using the right xcode installed in the build agent for for both archive and export.

    You can use either of below 2 options for this.

    1. Use the full path to xcodebuild,
    /Applications/Xcode 9.3.1.app/Contents/Developer/usr/bin/xcodebuild
    
    1. Use xcode-select,
    xcode-select -switch /Applications/Xcode 9.3.1.app
    

    Below is my old answer

    Here is command line script for creating archive and IPA example. I have an iPhone xcode project , which is located in Desktop/MyiOSApp folder.

    Execute following commands one by one:

    cd /Users/username/Desktop/MyiOSApp/
    
    xcodebuild -scheme MyiOSApp archive \
      -archivePath /Users/username/Desktop/MyiOSApp.xcarchive
    
    xcodebuild -exportArchive -exportFormat ipa \
      -archivePath "/Users/username/Desktop/MyiOSApp.xcarchive" \
      -exportPath "/Users/username/Desktop/MyiOSApp.ipa" \
      -exportProvisioningProfile "MyCompany Distribution Profile"
    

    This is tested with Xcode 5 and working fine for me.

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

    try xctool, it is a replacement for Apple's xcodebuild that makes it easier to build and test iOS and Mac products. It's especially helpful for continuous integration. It has a few extra features:

    1. Runs the same tests as Xcode.app.
    2. Structured output of build and test results.
    3. Human-friendly, ANSI-colored output.

    No.3 is extremely useful. I don't if anyone can read the console output of xcodebuild, I can't, usually it gave me one line with 5000+ characters. Even harder to read than a thesis paper.

    xctool: https://github.com/facebook/xctool

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

    I found how to automate the build and archive process from the comand line, I just wrote a blog article explaining how you can achieve that.

    The command you have to use is xcrun:

    /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}"
    

    You will find all the details in the article. If you have any questions dont hesitate to ask.

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