xcodebuild 脚本打包(针对Xcode7以后archive无WatchKitSupport问题)

Xcode archive 打包

在Xcode 7 以后,打包之后的ipa中目录应该是这样子的

  • Payload
  • SwiftSupport (支持swift)
  • Symbols
  • WatchKitSupport (支持Watch)

原来用xcodebuild 脚本打包时是这样的:

xcodebuild -target ${TARGET_NAME} -configuration ${BUILD_CONFIGURATION} -sdk phones build
xcrun -sdk iphoneos PackageApplication -v ${APP_NAME} -o ${IPA_PATH}


此时我们在IPA_PATH 中看到的ipa我们会发现目录中只有Payload,如果这是正式包,那我们在上传时就会收到报错,会告诉我们没有WatchKitSupport。遇到这个问题真的很郁闷,因为原来一直都是脚本打包,都没问题,所以找了问题在哪儿,自个做个笔记,也给大家分享一下。

Xcode7以后脚本打包

先上脚本构建方法代码

TARGET_NAME="MyApp"

appver=V1.0

currentDate=date +%Y_%m%d_%H%M

buildVersion="TEST1"

ROOT_BUILD_DIR="${SRCROOT}/build"

LOCAL_DIR="/Users/$(whoami)/Desktop/LOCALPACKAGE"

PROJECT_NAME="${SRCROOT}/${TARGET_NAME}.xcodeproj"

#  取调用该方法的构建包configuration : Release Debug Adhoc等  

BUILD_CONFIGURATION=$1
#临时构建目录
BUILD_DIR="${ROOT_BUILD_DIR}/${BUILD_CONFIGURATION}-iphoneos"
#LOCAL_PACKAGE_DIR为打包的最终存储文件夹,命名根据各自需求,我是以“版本日期build版本configuration“命名的
LOCAL_PACKAGE_DIR="${LOCAL_DIR}/${appver}
${currentDate}
${buildVersion}
${BUILD_CONFIGURATION}"

# Archive_Path为.xcarchive文件的存储目录
Archive_Path="$ROOT_BUILD_DIR/${TARGET_NAME}.xcarchive"
# Export_Plist_Path 为ExportOptions.plist路径
Export_Plist_Path="${SRCROOT}/ExportOptions.plist"

#dSyms位置
DSYM_PATH=dSYMs
DSYM_ZIP_NAME="${TARGET_NAME}.dSYMs.zip"

# xcodebuild must run on dir $SRCROOT
cd ${SRCROOT}
xcodebuild -target ${TARGET_NAME} -configuration ${BUILD_CONFIGURATION} -sdk iphoneos clean
xcodebuild archive -project ${PROJECT_NAME}  -scheme ${TARGET_NAME}  -archivePath ${Archive_Path}

# mkdir

if [ ! -d ${LOCAL_PACKAGE_DIR}]; then

mkdir ${LOCAL_PACKAGE_DIR}

fi

cd ${Archive_Path}
# zip dSYM
zip -r ${DSYM_ZIP_NAME} ${DSYM_PATH}
# move dSYM到本地包目录
mv ${DSYM_ZIP_NAME} ${LOCAL_PACKAGE_DIR}

# 导出ipa到本地包目录
xcodebuild -exportArchive -archivePath $Archive_Path -exportPath $LOCAL_PACKAGE_DIR -exportOptionsPlist $Export_Plist_Path

Xcode7之后取消了原来的-exportFormat,而是使用exportOptionsPlist 来取代,具体的使用方法可以在Terminal打xcodebuild --help查看。
我们需要自己创建一个plist作为Export Options,只要有这个配置文件,那我们在使用这个命令的时候就能打出跟手动用Xcode Archive之后export出的ipa一样了,也不会存在无法上传iTunesConnect的问题。

Export Options Plist

下面是目前我知道的options的设置:
method: (String) The method of distribution, which can be set as any of the following:

  • app-store
  • enterprise
  • ad-hoc
  • development

teamID: (String) The development program team identifier.
uploadSymbols: (Boolean) Option to include symbols in the generated ipa file.
uploadBitcode: (Boolean) Option to include Bitcode.

Plist 样例:





teamID
MYTEAMID123
teamID
app-store
uploadSymbols




你可能感兴趣的:(xcodebuild 脚本打包(针对Xcode7以后archive无WatchKitSupport问题))