Xcode_自动打包

xcode 自动化打包


XCode 自动打包命令

这里我使用的是Xcode8.3

参考资料:http://www.jianshu.com/p/3f43370437d2


获取证书

貌似xcode7.0以上都可以免费使用开发者证书

  1. 先使用Xcode打开工程,使用免费证书签名

    这里写图片描述

  2. 然后会自动生成 xxx.mobileprovision,这里面就包含了teamId等信息

    1
    2
    3
    4
    MacBook-Pro:Provisioning Profiles wilker$ pwd
    /Users/wilker/Library/MobileDevice/Provisioning Profiles
    MacBook-Pro:Provisioning Profiles wilker$ ls
    fa4ea842-adb4-4dec-82f3-c178f47769d8.mobileprovision

打包命令

  1. 从xcode工程 xxx.xcodeproj 打出 xxx.xcarchive 文件

    1
    2
    3
    cmd = '''xcodebuild -project %s -scheme "MyXMan-mobile" -configuration %s -sdk iphoneos10.3 -archivePath %s archive DEVELOPMENT_TEAM="%s" '''% \
    (project_path, debug_tag, archive_path, team_id)
    cmd += ' ENABLE_BITCODE=NO'
  2. 从 xxx.xcarchive 文件 打出 xxx.ipa 包

    1
    cmd = '''xcodebuild -exportArchive -archivePath %s -exportOptionsPlist %s -exportPath %s '''%(appAchive_path, export_options_plist_path, gself_path)

踩到的一些坑

-project

  • 项目的 xcode工程路径: /Users/wilker/workplace/cocos2dx/MyXMan/frameworks/runtime-src/proj.ios_mac/MyXMan.xcodeproj

-archivePath

  • 导出的 Archive 文件路径

-configuration

  • Debug or Release

查看sdk

  • sdk 设置错误会报错:xcodebuild: error: SDK “iphoneos10.2” cannot be located

  • 查看已有的sdk,命令: xcodebuild -showsdks,然后选择已有的sdk

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    MacBook-Pro:Provisioning Profiles wilker$ xcodebuild -showsdks
    iOS SDKs:
    iOS 10.3 -sdk iphoneos10.3

    iOS Simulator SDKs:
    Simulator - iOS 10.3 -sdk iphonesimulator10.3

    macOS SDKs:
    macOS 10.12 -sdk macosx10.12

    tvOS SDKs:
    tvOS 10.2 -sdk appletvos10.2

    tvOS Simulator SDKs:
    Simulator - tvOS 10.2 -sdk appletvsimulator10.2

    watchOS SDKs:
    watchOS 3.2 -sdk watchos3.2

    watchOS Simulator SDKs:
    Simulator - watchOS 3.2 -sdk watchsimulator3.2
  • 参考资料:http://www.cnblogs.com/zzugyl/p/5438869.html


scheme

  • scheme 设置错误会报错:xcodebuild: error: The project named “MyXMan” does not contain a scheme named “MyXMan”

  • 命令: xcodebuild -project /Users/wilker/workplace/cocos2dx/MyXMan/frameworks/runtime-src/proj.ios_mac/MyXMan.xcodeproj -list

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    MacBook-Pro:release_tools wilker$ xcodebuild -project /Users/wilker/workplace/cocos2dx/MyXMan/frameworks/runtime-src/proj.ios_mac/MyXMan.xcodeproj -list
    Information about project "MyXMan":
    Targets:
    MyXMan-mobile
    MyXMan-desktop

    Build Configurations:
    Debug
    Release

    If no build configuration is specified and -scheme is not passed then "Release" is used.

    Schemes:
    MyXMan-mobile
    MyXMan-desktop
    libsimulator Mac
    libsimulator iOS
    libluacocos2d Mac
    libluacocos2d iOS
    libluacocos2d tvOS
    libcocos2d Mac
    libcocos2d iOS
    libcocos2d tvOS


exportOptionsPlist

  • exportOptionsPlist配置文件设置 teamID 错误会报错:Error Domain=IDEDistributionErrorDomain Code=1 “No valid iOS Distribution signing identities belonging to team 38W5465CZX were found.” UserInfo={NSLocalizedDescription=No valid iOS Distribution signing identities belonging to team 38W5465CZX were found.}

  • 配置文件内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    <!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>development</string>
    <key>teamID</key>
    <string>JW38L9N6HH</string>
    </dict>
    </plist>
  • 参考资料:

  • 可选参数

    1. compileBitcode: Bool
      • For non-App Store exports, should Xcode re-compile the app from bitcode? Defaults to YES.
    2. embedOnDemandResourcesAssetPacksInBundle : Bool
      • For non-App Store exports, if the app uses On Demand Resources and this is YES, asset packs are embedded in the app bundle so that the app can be tested without a server to host asset packs. Defaults to YES unless onDemandResourcesAssetPacksBaseURL is specified.
    3. iCloudContainerEnvironment
      • For non-App Store exports, if the app is using CloudKit, this configures the “com.apple.developer.icloud-container-environment” entitlement. Available options: Development and Production. Defaults to Development.
    4. manifest : Dictionary
      • For non-App Store exports, users can download your app over the web by opening your distribution manifest file in a web browser. To generate a distribution manifest, the value of this key should be a dictionary with three sub-keys: appURL, displayImageURL, fullSizeImageURL. The additional sub-key assetPackManifestURL is required when using on demand resources.
    5. method : String
      • Describes how Xcode should export the archive. Available options: app-store, ad-hoc, package, enterprise, development, and developer-id. The list of options varies based on the type of archive. Defaults to development.
    6. onDemandResourcesAssetPacksBaseURL : String
      • For non-App Store exports, if the app uses On Demand Resources and embedOnDemandResourcesAssetPacksInBundle isn’t YES, this should be a base URL specifying where asset packs are going to be hosted. This configures the app to download asset packs from the specified URL.
    7. teamID : String
      • The Developer Portal team to use for this export. Defaults to the team used to build the archive.
    8. thinning : String
      • For non-App Store exports, should Xcode thin the package for one or more device variants? Available options: (Xcode produces a non-thinned universal app), (Xcode produces a universal app and all available thinned variants), or a model identifier for a specific device (e.g. “iPhone7,1”). Defaults to .
    9. uploadBitcode : Bool
      • For App Store exports, should the package include bitcode? Defaults to YES.
    10. uploadSymbols : Bool
      • For App Store exports, should the package include symbols? Defaults to YES.