iOS bugly符号表自动上传脚本

Build Phase脚本

  • 确保Mac拥有JDK环境
  • 需要去bugly下载上传的jar包
#!/bin/sh
# Copyright 2014-2015 Bugly @Tencent. All rights reserved.
#
################################################################################
# 注意: 请配置下面的信息
################################################################################
BUGLY_APP_ID="xxxxxx"
BUGLY_APP_KEY="xxxxxxxxx
BUNDLE_IDENTIFIER="com.xx.xxxx"
BUGLY_SYMBOL_JAR_PATH="xxxxx.jar"      #去bugly下载jar包,确保电脑有该java环境
ENABEL_BUGLY_SYMBOL_UPLOAD=0    #Archive是否开启符号上传(个别机器没有java环境可以设置0)

################################################################################
# 自定义配置
################################################################################
# Debug模式编译是否上传,1=上传 0=不上传,默认不上传
UPLOAD_DEBUG_SYMBOLS=1
#
# 模拟器编译是否上传,1=上传 0=不上传,默认不上传
UPLOAD_SIMULATOR_SYMBOLS=0
#
# # 脚本默认配置的版本格式为CFBundleShortVersionString(CFBundleVersion),  如果你修改默认的版本格式, 请设置此变量, 如果不想修改, 请忽略此设置
# CUSTOMIZED_APP_VERSION=""
#
#
#
# This script will extract symbols from the .dSYM and generate .symbol file(Bugly supported) and upload to server.
# You could visit http://bugly.qq.com to get more details about Bugly.
#
# Usage:
#     * The instructions assume you have copyed this script into your project int Xcode.
#     * Copy the "buglySymbolIOS.jar" file into the "~/bin" folder.
#    * Open the project editor, select your build target.
#    * Click "Build Phases" at the top of the project editor.
#    * Click "+" button in the top left corner and select "New Run Script Phase".
#    * Click "Run Script".
#    * Paste the following script into the dark text box. You will have to uncomment the lines (remove the #) of course.
#
# --- SCRIPT BEGINS ON NEXT LINE, COPY AND EDIT FROM THERE ---
#
#
#
# --- END OF SCRIPT ---


################################################################################
# 注意: 如果你不知道此脚本的执行流程和用法,请不要随便修改!
################################################################################

# 退出执行并打印提示信息
exitWithMessage() {
    echo "--------------------------------"
    echo -e "${1}"
    echo "--------------------------------"
    echo "No upload and exit."
    echo "----------------------------------------------------------------"
    exit ${2}
}

echo "----------------------------------------------------------------"
echo "Copyright 2014-2015 Bugly @Tencent. All rights reserved."

echo "This script will extract symbols from the .dSYM file and generate .symbol file(Bugly supported) and upload to server."
echo "You could visit http://bugly.qq.com to get more details about Bugly."
echo "----------------------------------------------------------------"

echo "Uploading dSYM to Bugly."
echo ""

# Bugly服务域名
DSYM_UPLOAD_DOMAIN="bugly.qq.com"

# 读取Info.plist文件中的版本信息
echo "Info.Plist : ${INFOPLIST_FILE}"

# BUNDLE_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "${INFOPLIST_FILE}")
# BUNDLE_SHORT_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "${INFOPLIST_FILE}")

# ios 11以后获取版本号与build
# Build号
BUNDLE_VERSION=`xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION ='`
# 版本号
BUNDLE_SHORT_VERSION=`xcodebuild -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION ='`

# 组装Bugly默认识别的版本信息(格式为CFBundleShortVersionString(CFBundleVersion), 例如: 1.0(1))
if [ ! "${CUSTOMIZED_APP_VERSION}" ]; then
BUGLY_APP_VERSION="${BUNDLE_SHORT_VERSION}(${BUNDLE_VERSION})"
else
BUGLY_APP_VERSION="${CUSTOMIZED_APP_VERSION}"
fi

echo "--------------------------------"
echo "Step 1: Prepare application information."
echo "--------------------------------"

echo "Product Name: ${PRODUCT_NAME}"
echo "Bundle Identifier: ${BUNDLE_IDENTIFIER}"
echo "Version: ${BUNDLE_SHORT_VERSION}"
echo "Build: ${BUNDLE_VERSION}"

echo "Bugly App ID: ${BUGLY_APP_ID}"
echo "Bugly App key: ${BUGLY_APP_KEY}"
echo "Bugly App Version: ${BUGLY_APP_VERSION}"

echo "--------------------------------"
echo "Step 2: Check the arguments ..."

# 上传
function upload() {
    echo "---------------开始上传-----------------"
    DSYM_FOLDER="${CONFIGURATION_BUILD_DIR}"
    for dsymFile in $(find "$DSYM_FOLDER" -name '*.dSYM'); do
        echo "正在上传: $dsymFile"
       
       (/usr/bin/java -jar "${BUGLY_SYMBOL_JAR_PATH}" -appid "${BUGLY_APP_ID}" -appkey "${BUGLY_APP_KEY}" -bundleid "${BUNDLE_IDENTIFIER}" -version "${BUNDLE_SHORT_VERSION}" -platform "IOS" -inputSymbol ${dsymFile} ) || exitWithMessage "Error: Failed to extract symbols." 1
    done

    echo "---------------上传完成-----------------"
}


# 是否开启上传功能
if [ $ENABEL_BUGLY_SYMBOL_UPLOAD -eq 0 ]; then
exitWithMessage "已关闭bugly符号上传.(如有需要开启请设置ENABEL_BUGLY_SYMBOL_UPLOAD=1)" 0
fi

# 检查模拟器编译是否允许上传符号
if [ "$EFFECTIVE_PLATFORM_NAME" == "-iphonesimulator" ]; then
if [ $UPLOAD_SIMULATOR_SYMBOLS -eq 0 ]; then
exitWithMessage "Warning: Build for simulator and skipping to upload. \nYou can modify 'UPLOAD_SIMULATOR_SYMBOLS' to 1 in the script." 0
fi
fi

if [ "${CONFIGURATION=}" == "Debug" ]; then
if [ $UPLOAD_DEBUG_SYMBOLS -eq 0 ]; then
exitWithMessage "Warning: Build for debug mode and skipping to upload. \nYou can modify 'UPLOAD_DEBUG_SYMBOLS' to 1 in the script." 0
fi
fi

# 检查必须参数是否设置
if [ ! "${BUGLY_APP_ID}" ]; then
exitWithMessage "Error: Bugly App ID not defined." 1
fi

if [ ! "${BUGLY_APP_KEY}" ]; then
exitWithMessage "Error: Bugly APP Key not defined." 1
fi

if [ ! "${BUNDLE_IDENTIFIER}" ]; then
exitWithMessage "Error: Bundle Identifier not defined." 1
fi

##检查是否Archive操作
if [[ "$TARGET_BUILD_DIR" == *"/Archive"* ]]; then
    echo "Archive the package"
else
    exitWithMessage "Warning: Build for NOT Archive mode and skipping to upload." 0
fi

# 提取符号信息
echo "--------------------------------"
echo "Step 3: Extract symbol info from .dSYM file."

# Bugly符号提取工具路径, 请确保已经把对应的buglySymbolIOS.jar拷贝到目录~/bin
#BUGLY_SYMBOL_JAR_PATH="$HOME/bin/buglySymbolIOS.jar"

if [ ! -e "$BUGLY_SYMBOL_JAR_PATH" ]; then
exitWithMessage "Error: Jar file '${BUGLY_SYMBOL_JAR_PATH}' was not found. \nPlease copy the jar file into ~/bin folder." 1
fi

# 上传
upload

echo "Please check the script and try it again."

效果

image.png
image.png

有疑问的小伙伴欢迎留言

你可能感兴趣的:(iOS bugly符号表自动上传脚本)