使用工具进行APP打包和分发

常见的xcodebuild命令

编译打包

编译打包,产出archive包

# configuration参数一般为Debug和Release
xcodebuild [-project projectname] [-target targetname ...] [-configuration configurationname]
           [-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
           [-userdefault=value ...]
xcodebuild -workspace workspacename -scheme schemename [-destination destinationspecifier]
          [-destination-timeout value] [-configuration configurationname]
          [-sdk [sdkfullpath | sdkname]] [buildaction ...] [setting=value ...]
          [-userdefault=value ...]

可以使用-project替换掉-workspace来对应project工程.

构建project工程时,可以指定对应的target.不指定时默认为第一个.
构建workspace工程时,必须指定workspace和scheme参数.

导出ipa包

从编译过的archive包中导出ipa包

xcodebuild -exportArchive -archivePath <xcarchivepath> -exportPath <destinationpath> -exportOptionsPlist <plistpath>

需要在plistpath中手动进行ipa包的配置,其中app-store可以替换为ad-hoc,enterprise,package,development等.

<!-- exportOptionsPlist -->
<?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>uploadBitcode</key> <false/>
        <!-- 是否上传符号文件 -->
        <key>uploadSymbols</key> <false/>
    </dict>
</plist>

其他常见命令

# 列出当前工程的所有 Targets , Configurations 和 Schemes
xcodebuild -list
# clean当前编译目录
xcodebuild clean -workspace ${TARGET_NAME}.xcworkspace -scheme ${TARGET_NAME} -configuration ${BUILD_TYPE}

# 获取bundle_version
/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' ${plistPath}
# 设置bundle_version
/usr/libexec/PlistBuddy -c 'Set :CFBundleShortVersionString "${newValue}"' ${plistPath}

参考:

IPA包的处理

可以使用altool命令对IPA进行验证和上传App Store.

altool命令路径:/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool

# IPA包的验证
${altoolpath} --validate-app -f ${file} -t ${platform} -u ${username} [-p ${password}]
# IPA包的上传
${altoolpath} --upload-app -f ${file} -u ${username} [-p ${password}]

为了方便使用altool命令,可以命名别名:

vim ~/.bash_profile
# 指定altool别名
alias altool="/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
source ~/.bash_profile

也可以建立 altool 命令的软链接:

ln -s /Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool altool

还可以使用命令行上传至蒲公英和fir.im平台.

fir p '${ipaPath}' -T '${firToken}'

参考:

使用xcrun命令重签名生成新的IPA包

支持在修改了app包的签名信息,相关资源后重签名生成ipa包.

/usr/bin/xcrun -sdk iphoneos PackageApplication -v ${appPath} -o ${ipaPath} --sign ${signInfo} --embed ${mobileprovisionPath}

参考:

对app包重签名打包为ipa包

其他相关资料