美文网首页
ios脚本打包

ios脚本打包

作者: biggerworld | 来源:发表于2017-05-18 15:16 被阅读0次

    #!/bin/bash

    #$1表示第一个参数

    PROJECTPATH="$1"

    build_configuration="Release"

    # 是否编译工作空间 (例:若是用Cocopods管理的.xcworkspace项目,赋值true;用Xcode默认创建的.xcodeproj,赋值false)

    is_workspace=$"false"

    # 指定要打包编译的方式 : Release,Debug...

    build_configuration="Release"

    projectDirectory=`echo ${PROJECTPATH%/*}`

    projectFile=`echo ${PROJECTPATH##*/}`

    scheme_name=`echo ${projectFile%.*}`

    echo $projectDirectory

    cd "$projectDirectory"

    info_plist_path="${projectDirectory}/${scheme_name}/Info.plist"

    EXPORT_PLIST="${projectDirectory}/${scheme_name}/EXPORT_PLIST.plist"

    bundle_version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $info_plist_path`

    bundle_build_version=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $info_plist_path`

    bundle_identifier=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $info_plist_path`

    # 删除旧.xcarchive文件

    rm -rf ~/Desktop/$scheme_name-IPA/$scheme_name.xcarchive

    # 指定输出ipa路径

    export_path=~/Desktop/$scheme_name-IPA

    # 指定输出归档文件地址

    export_archive_path="$export_path/$scheme_name.xcarchive"

    # 指定输出ipa地址# 指定输出ipa名称 : scheme_name + bundle_version

    export_ipa_path="$export_path"

    ipa_name="$scheme_name-v$bundle_version"

    # 指定输出文件目录不存在则创建

    if [ -d "$export_path" ] ; then

    echo $export_path

    else

    mkdir -pv $export_path

    fi

    # 判断编译的项目类型是workspace还是project

    if $is_workspace ; then

    # 编译前清理工程

    xcodebuild clean -workspace ${PROJECTPATH}.xcworkspace \

    -scheme ${scheme_name} \

    -configuration ${build_configuration}

    xcodebuild archive -workspace ${PROJECTPATH}.xcworkspace \

    -scheme ${scheme_name} \

    -configuration ${build_configuration} \

    -archivePath ${export_archive_path}

    else

    # 编译前清理工程

    echo ${PROJECTPATH}

    xcodebuild clean -project ${PROJECTPATH} \

    -scheme ${scheme_name} \

    -configuration ${build_configuration}

    xcodebuild \

    -scheme "${scheme_name}" \

    -archivePath  ${export_archive_path} \

    -configuration  ${build_configuration} \

    archive

    #如果加上 预制描述文件

    #xcodebuild \

    #-scheme "${SCHEME_NAME}" \

    #-sdk "${TARGET_SDK}" \

    #-archivePath "${PROJECT_BUILDDIR}/${SCHEME_NAME}.xcarchive" \

    #-configuration Release \

    #PROVISIONING_PROFILE="${PROVISIONING_PROFILE}" \

    #archive

    fi

    #  检查是否构建成功

    #  xcarchive 实际是一个文件夹不是一个文件所以使用 -d 判断

    if [ -d "$export_archive_path" ] ; then

    echo "项目构建成功 🚀 🚀 🚀 "

    else

    echo "项目构建失败 😢 😢 😢"

    exit 1

    fi

    echo "*************************  开始导出ipa文件  *************************  "

    xcodebuild \

    -exportArchive \

    -archivePath ${export_archive_path} \

    -exportOptionsPlist "${EXPORT_PLIST}" \

    -exportPath ${export_ipa_path}

    ## 修改ipa文件名称

    mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name.ipa

    ## 输出打包总用时

    echo "打包总用时: ${SECONDS}s "

    open -R "$export_ipa_path"

    相关文章

      网友评论

          本文标题:ios脚本打包

          本文链接:https://www.haomeiwen.com/subject/ufmsxxtx.html