bugly自动上传脚本
目前bugly现在已经没有更新buglySymboliOS.jar,也就是不支持自动上传了,只能通过上传工具上传了.
下面是我用上传工具buglyqq-upload-symbol.jar做的Xcode脚本,可以跟之前一样放在xcode打包使用,测试几百遍调试通过的,亲测有效;拒绝废话一堆,一提到关键问题不管用,直接把下面脚本放在xcode中打包,亲测有效
#!/bin/sh
#
# Copyright 2016 Bugly, Tencent. All rights reserved.
#
# V1.4.0
#
# 2016.08.03
#
#
#
######################################################
# 1. 脚本集成到Xcode工程的Target
######################################################
#
# --- Copy the SCRIPT to the Run Script of Build Phases in the Xcode project ---
#
# #
BUGLY_APP_ID="xxx"
# #
BUGLY_APP_KEY="xxxx"
# #
#BUNDLE_IDENTIFIER="xxxx"
# #
UPLOAD_DSYM_ONLY=0
#
# # 脚本默认配置的版本格式为CFBundleShortVersionString(CFBundleVersion), 如果你修改默认的版本格式, 请设置此变量, 如果不想修改, 请忽略此设置
# CUSTOMIZED_APP_VERSION=""
#
# # Debug模式编译是否上传,1=上传 0=不上传,默认不上传
UPLOAD_DEBUG_SYMBOLS=0
#
# # 模拟器编译是否上传,1=上传 0=不上传,默认不上传
# UPLOAD_SIMULATOR_SYMBOLS=0
#
# #只有Archive操作时上传, 1=支持Archive上传 0=所有Release模式编译都上传
UPLOAD_ARCHIVE_ONLY=0
#
# #
# source dSYMUpload.sh
#
# --- END OF SCRIPT ---
#
#
#
#
#######################################################
# 2. 脚本根据输入参数处理
#######################################################
#
# #命令行下输入应用基本信息, .dSYM文件的父目录路径, 输出文件目录即可
#
# sh dSYMUpload.sh <bugly_app_id> <bugly_app_key> <app_bundle_identifier> <app_version> <dSYM_src_dir> <bSYMBOL_dest_dir>
#
# #
#
# #注意:
# # 1. dSYMUpload.sh会调用buglySymboliOS.jar进行.dSYM解析,所以依赖Java运行时环境
# # 2. dSYMUpload.sh和buglySymboliOS.jar的文件路径需一致
#
#
#
# --- CONTENT OF SCRIPT ---
#
# Bugly服务域名
BUGLY_DSYM_UPLOAD_DOMAIN="api.bugly.qq.com"
# 注意jar工具的路径跟dSYMUpload.sh脚本路径一致, 请务必保证jar路径的正确性
BUGLY_SYMBOL_JAR_PATH="dsymtool/buglyqq-upload-symbol.jar"
# 查找添加到系统目录的jar工具
if [ ! -f "${BUGLY_SYMBOL_JAR_PATH}" ]; then
BUGLY_SYMBOL_JAR_PATH="$HOME/bin/buglyqq-upload-symbol.jar"
fi
# 打印错误信息
function exitWithMessage(){
echo "--------------------------------"
echo "${1}"
echo "--------------------------------"
exit ${2}
}
# 上传bSYMBOL文件
function dSYMUpload() {
P_APP_ID="$1"
P_APP_KEY="$2"
P_APP_BUNDLE_ID="$3"
P_APP_VERSION="$4"
P_BSYMBOL_ZIP_FILE="$5"
P_BuildNo="$6"
#
# P_BSYMBOL_ZIP_FILE_NAME=${P_BSYMBOL_ZIP_FILE##*/}
# P_BSYMBOL_ZIP_FILE_NAME=${P_BSYMBOL_ZIP_FILE_NAME//&/_}
# P_BSYMBOL_ZIP_FILE_NAME="${P_BSYMBOL_ZIP_FILE_NAME// /_}"
echo "jar: ${BUGLY_SYMBOL_JAR_PATH}"
echo "inputSymbol:${P_BSYMBOL_ZIP_FILE}"
echo "-----------------------------"
# java -jar "${BUGLY_SYMBOL_JAR_PATH}" -appid "${BUGLY_APP_ID}" -appkey "${BUGLY_APP_KEY}" -bundleid jcringBlack.com -version 1.9.55 -buildNo 1 -platform IOS -inputSymbol ${P_BSYMBOL_ZIP_FILE}
java -jar "${BUGLY_SYMBOL_JAR_PATH}" -appid "${BUGLY_APP_ID}" -appkey "${BUGLY_APP_KEY}" -bundleid "${P_APP_BUNDLE_ID}" -version "${BUGLY_APP_VERSION}" -buildNo "${P_BuildNo}" -platform IOS -inputSymbol ${P_BSYMBOL_ZIP_FILE}
echo "-----------------------------"
}
# 执行
function run() {
CONFIG_BUGLY_APP_ID="$1"
CONFIG_BUGLY_APP_KEY="$2"
CONFIG_BUGLY_APP_BUNDLE_IDENTIFIER="$3"
CONFIG_BUGLY_APP_VERSION="$4"
CONFIG_DSYM_SOURCE_DIR="$5"
CONFIG_DSYM_DEST_DIR="$6"
CONFIG_BUGLY_APP_NUMBER="$7"
# 检查必须参数是否设置
if [ ! "${CONFIG_BUGLY_APP_ID}" ]; then
exitWithMessage "Error: Bugly App ID not defined. Please set 'BUGLY_APP_ID' " 0
fi
if [[ "${CONFIG_BUGLY_APP_ID}" == *"App ID"* ]]; then
exitWithMessage "Error: Bugly App ID not defined." 0
fi
if [ ! "${CONFIG_BUGLY_APP_KEY}" ]; then
exitWithMessage "Error: Bugly App Key not defined." 0
fi
if [ ! "${CONFIG_BUGLY_APP_BUNDLE_IDENTIFIER}" ]; then
exitWithMessage "Error: Bundle Identifier not defined." 0
fi
if [ ! "${CONFIG_BUGLY_APP_VERSION}" ]; then
exitWithMessage "Error: App Version not defined." 0
fi
if [ ! -e "${CONFIG_DSYM_SOURCE_DIR}" ]; then
exitWithMessage "Error: Invalid dir ${CONFIG_DSYM_SOURCE_DIR}" 0
fi
if [ ! -e "${CONFIG_DSYM_DEST_DIR}" ]; then
mkdir ${CONFIG_DSYM_DEST_DIR}
fi
DSYM_FOLDER="${CONFIG_DSYM_SOURCE_DIR}"
IFS=$'\n'
echo "Scaning dSYM FOLDER: ${DSYM_FOLDER} ..."
RET="F"
# 睡眠8秒
sleep 30
#
for dsymFile in $(find "$DSYM_FOLDER" -name '*.dSYM'); do
RET="T"
echo "Found dSYM file: $dsymFile"
DSYM_FILE_NAME=${dsymFile##*/}
DSYM_SYMBOL_ZIP_FILE_NAME="${DSYM_FILE_NAME}.dSYM"
DSYM_SYMBOL_ZIP_FILE_NAME="${DSYM_SYMBOL_ZIP_FILE_NAME// /_}"
DSYM_SYMBOL_ZIP_FILE=${CONFIG_DSYM_DEST_DIR}/${DSYM_SYMBOL_ZIP_FILE_NAME}
echo "目标路径:${DSYM_SYMBOL_ZIP_FILE}"
echo "符号表路径:$dsymFile"
if [ -e $DSYM_SYMBOL_ZIP_FILE ]; then
rm -f $DSYM_SYMBOL_ZIP_FILE
fi
# 如果只上传dSYM,直接压缩dSYM目录
# zip -rj ${DSYM_SYMBOL_ZIP_FILE} ${dsymFile} -x *.plist
# 复制文件
cp -R ${dsymFile} ${CONFIG_DSYM_DEST_DIR}
done
if [ $RET = "F" ]; then
exitWithMessage "No .dSYM found in ${DSYM_FOLDER}" 0
fi
# # 检测文件内是否有文件
# checkdirempty=`ls ${CONFIG_DSYM_DEST_DIR} | wc -l`
# echo $checkdirempty
#
# while [ ! -e "${CONFIG_DSYM_DEST_DIR}" ]; do
# sleep 1
# echo "没有文件了"
# done
# 上传
dSYMUpload $CONFIG_BUGLY_APP_ID $CONFIG_BUGLY_APP_KEY $CONFIG_BUGLY_APP_BUNDLE_IDENTIFIER $CONFIG_BUGLY_APP_VERSION $CONFIG_DSYM_DEST_DIR $CONFIG_BUGLY_APP_NUMBER
}
# 在Xcode工程中执行
function runInXcode(){
echo "Uploading dSYM to Bugly in Xcode ..."
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}")
BUNDLE_IDENTIFIER=$(/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "${INFOPLIST_FILE}")
#组装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 "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}"
# 输出build identifier
echo "--------------------------------"
echo "Check the arguments ..."
##检查模拟器编译是否允许上传符号
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
##检查是否是Release模式编译
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
##检查是否Archive操作
if [ $UPLOAD_ARCHIVE_ONLY -eq 1 ]; then
if [[ "$TARGET_BUILD_DIR" == *"/Archive"* ]]; then
echo "Archive the package"
else
exitWithMessage "Warning: Build for NOT Archive mode and skipping to upload. \nYou can modify 'UPLOAD_ARCHIVE_ONLY' to 0 in the script." 0
fi
fi
#
run ${BUGLY_APP_ID} ${BUGLY_APP_KEY} ${BUNDLE_IDENTIFIER} ${BUNDLE_SHORT_VERSION} ${DWARF_DSYM_FOLDER_PATH} ${BUILD_DIR}/BuglySymbolTemp ${BUNDLE_VERSION}
}
# 根据Xcode的环境变量判断是否处于Xcode环境
INFO_PLIST_FILE="${INFOPLIST_FILE}"
BuildInXcode="F"
#表示INFO_PLIST_FILE文件存在
if [ -f "${INFO_PLIST_FILE}" ]; then
BuildInXcode="T"
fi
if [ $BuildInXcode = "T" ]; then
runInXcode
else
echo "\nUsage: dSYMUpload.sh <bugly_app_id> <bugly_app_key> <app_bundle_identifier> <app_version> <dSYM_src_dir> <bSYMBOL_dest_dir> [upload_dsym_only]\n"
# 你可以在此处直接设置BuglyAppID和BuglyAppKey,排除不常变参数的输入
BUGLY_APP_ID="$1"
BUGLY_APP_KEY="$2"
BUNDLE_IDENTIFIER="$3"
BUGLY_APP_VERSION="$4"
DWARF_DSYM_FOLDER_PATH="$5"
SYMBOL_OUTPUT_PATH="$6"
UPLOAD_DSYM_ONLY=$7
run ${BUGLY_APP_ID} ${BUGLY_APP_KEY} ${BUNDLE_IDENTIFIER} ${BUGLY_APP_VERSION} ${DWARF_DSYM_FOLDER_PATH} ${SYMBOL_OUTPUT_PATH} ${UPLOAD_DSYM_ONLY}
fi