最近發(fā)現(xiàn)了Bugly的符號(hào)表沒有上傳,追蹤了下發(fā)現(xiàn)在Debug和Release模式都可以上傳符號(hào)表,但一打包(Archive)就不會(huì)上傳符號(hào)表
command+9查看下日志發(fā)現(xiàn)接口返回報(bào)錯(cuò)
Bugly server response: {"rtcode":0,"msg":"Success","data":{"reponseCode":"40410"}}
Error: Failed to upload the zip archive file to Bugly.
解決辦法一
根據(jù)這篇文章https://blog.csdn.net/gdutxzy/article/details/82896348發(fā)現(xiàn)只要在壓縮前sleep幾秒即可
解決辦法二
不過正如作者說聲只是解決燃眉之急,經(jīng)過試驗(yàn)后發(fā)現(xiàn)該錯(cuò)誤來自于最早在Xcode 9中出現(xiàn)的New Build System(能夠大幅度提升編譯速度,同時(shí)更嚴(yán)格地檢測(cè)代碼質(zhì)量(循環(huán)引用等)和更友好地給出提示)導(dǎo)致的(Xcode10 設(shè)置為默認(rèn)了),所以解決辦法二出來了,更改為以前的Legacy Build System解決辦法三
不過當(dāng)然蘋果之所以設(shè)置為New Build System為默認(rèn),肯定比原來有所優(yōu)化的,隨后猜想壓縮的文件之所以為0字節(jié),是因?yàn)樾碌木幾g方式在shell腳本執(zhí)行過程中原文件為0字節(jié),還沒有生成dsym數(shù)據(jù),隨后根據(jù)之前的自動(dòng)配置符號(hào)表工具包里面的dSYMUpload.sh進(jìn)行了更改
#!/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="YOUR_APP_ID"
# #
BUGLY_APP_KEY="YOUR_APP_KEY"
# #
BUNDLE_IDENTIFIER="YOUR_BUNDLE_IDENTIFIER"
# #
UPLOAD_DSYM_ONLY=1
#
# # 腳本默認(rèn)配置的版本格式為CFBundleShortVersionString(CFBundleVersion), 如果你修改默認(rèn)的版本格式, 請(qǐng)?jiān)O(shè)置此變量, 如果不想修改, 請(qǐng)忽略此設(shè)置
# CUSTOMIZED_APP_VERSION=""
#
# # Debug模式編譯是否上傳氏堤,1=上傳 0=不上傳,默認(rèn)不上傳
# UPLOAD_DEBUG_SYMBOLS=0
#
# # 模擬器編譯是否上傳歇僧,1=上傳 0=不上傳宏邮,默認(rèn)不上傳
# UPLOAD_SIMULATOR_SYMBOLS=0
#
# #只有Archive操作時(shí)上傳, 1=支持Archive上傳 0=所有Release模式編譯都上傳
# UPLOAD_ARCHIVE_ONLY=0
#
# #
# source dSYMUpload.sh
#
# --- END OF SCRIPT ---
#
#
#
#
#######################################################
# 2. 腳本根據(jù)輸入?yún)?shù)處理
#######################################################
#
# #命令行下輸入應(yīng)用基本信息, .dSYM文件的父目錄路徑, 輸出文件目錄即可
#
# sh dSYMUpload.sh <bugly_app_id> <bugly_app_key> <app_bundle_identifier> <app_version> <dSYM_src_dir> <bSYMBOL_dest_dir>
#
# #
#
# #注意:
# # 1. dSYMUpload.sh會(huì)調(diào)用buglySymboliOS.jar進(jìn)行.dSYM解析,所以依賴Java運(yùn)行時(shí)環(huán)境
# # 2. dSYMUpload.sh和buglySymboliOS.jar的文件路徑需一致
#
#
#
# --- CONTENT OF SCRIPT ---
#
# Bugly服務(wù)域名
BUGLY_DSYM_UPLOAD_DOMAIN="api.bugly.qq.com"
# 注意jar工具的路徑跟dSYMUpload.sh腳本路徑一致, 請(qǐng)務(wù)必保證jar路徑的正確性
BUGLY_SYMBOL_JAR_PATH="dsymtool/buglySymboliOS.jar"
# 查找添加到系統(tǒng)目錄的jar工具
if [ ! -f "${BUGLY_SYMBOL_JAR_PATH}" ]; then
BUGLY_SYMBOL_JAR_PATH="$HOME/bin/buglySymboliOS.jar"
fi
# 打印錯(cuò)誤信息
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_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// /_}"
DSYM_UPLOAD_URL="https://${BUGLY_DSYM_UPLOAD_DOMAIN}/openapi/file/upload/symbol?app_id=${P_APP_ID}&app_key=${P_APP_KEY}"
echo "dSYM upload url: ${DSYM_UPLOAD_URL}"
echo "-----------------------------"
STATUS=$(/usr/bin/curl -k "${DSYM_UPLOAD_URL}" --form "api_version=1" --form "app_id=${P_APP_ID}" --form "app_key=${P_APP_KEY}" --form "symbolType=2" --form "bundleId=${BUNDLE_IDENTIFIER}" --form "productVersion=${BUGLY_APP_VERSION}" --form "fileName=${P_BSYMBOL_ZIP_FILE_NAME}" --form "file=@${P_BSYMBOL_ZIP_FILE}" --verbose)
echo "-----------------------------"
UPLOAD_RESULT="FAILTURE"
echo "Bugly server response: ${STATUS}"
if [ ! "${STATUS}" ]; then
echo "Error: Failed to upload the zip archive file."
elif [[ "${STATUS}" == *"{\"reponseCode\":\"0\"}"* ]]; then
echo "Success to upload the dSYM for the app [${BUNDLE_IDENTIFIER} ${BUGLY_APP_VERSION}]"
UPLOAD_RESULT="SUCCESS"
else
echo "Error: Failed to upload the zip archive file to Bugly."
fi
#Remove temp dSYM archive
#echo "Remove temporary zip archive: ${DSYM_ZIP_FPATH}"
#/bin/rm -f "${DSYM_ZIP_FPATH}"
if [ "$?" -ne 0 ]; then
exitWithMessage "Error: Failed to remove temporary zip archive." 0
fi
echo "--------------------------------"
echo "${UPLOAD_RESULT} - dSYM upload complete."
if [[ "${UPLOAD_RESULT}" == "FAILTURE" ]]; then
echo "--------------------------------"
echo "Failed to upload the dSYM"
echo "Please check the script and try it again."
fi
}
# .dSYM解析為bSYMBOL文件
function dSYMParse() {
DSYM_FILE="$1"
DSYM_SYMBOL_FILE="$2"
echo "--------------------------------"
echo "Extract symbol info from .dSYM file. to ${DSYM_SYMBOL_FILE}"
(/usr/bin/java -Xms512m -Xmx1024m -Dfile.encoding=UTF8 -jar "${BUGLY_SYMBOL_JAR_PATH}" -i "${DSYM_FILE}" -o "${DSYM_SYMBOL_FILE}" ) || exitWithMessage "Error: Failed to extract symbols." 1
echo "--------------------------------"
}
function checkCompressedSourceFile() {
SDYM_SIGLE_FILE_IS_EXIST=1
for i in {1..10}; do
sleep 1s
# 遍歷目錄查找當(dāng)前工程名的文件
for dsymSingleFile in $(find "${dsymFile}" -name ${PRODUCT_NAME}); do
if [ -s "${dsymSingleFile}" ];then
# 壓縮文件存在
SDYM_SIGLE_FILE_IS_EXIST=0
return $SDYM_SIGLE_FILE_IS_EXIST
fi
done
done
return $SDYM_SIGLE_FILE_IS_EXIST
}
# 執(zhí)行
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_UPLOAD_DSYM_ONLY="$7"
# 檢查必須參數(shù)是否設(shè)置
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 [ ! "${CONFIG_DSYM_DEST_DIR}" ]; then
exitWithMessage "Error: Invalid dir ${CONFIG_DSYM_DEST_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"
#
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}.zip"
DSYM_SYMBOL_ZIP_FILE_NAME="${DSYM_SYMBOL_ZIP_FILE_NAME// /_}"
DSYM_SYMBOL_ZIP_FILE=${CONFIG_DSYM_DEST_DIR}/${DSYM_SYMBOL_ZIP_FILE_NAME}
if [ $CONFIG_UPLOAD_DSYM_ONLY -eq 1 ]; then
if [ -e $DSYM_SYMBOL_ZIP_FILE ]; then
rm -f $DSYM_SYMBOL_ZIP_FILE
fi
# 判斷壓縮文件的源文件是否存在
SDYM_SINGLE_FILE_NAME="${dsymFile}/Contents/Resources/DWARF/${PRODUCT_NAME}"
checkCompressedSourceFile $SDYM_SINGLE_FILE_NAME
if [ $? == 1 ];then
exitWithMessage "NO file found in ${SDYM_SINGLE_FILE_NAME}" 0
fi
# 如果只上傳dSYM,直接壓縮dSYM目錄
zip -r -j $DSYM_SYMBOL_ZIP_FILE $dsymFile -x *.plist
else
# 使用符號(hào)表工具來生成Symbol文件
dSYMParse $dsymFile $DSYM_SYMBOL_ZIP_FILE
fi
# 上傳
dSYMUpload $CONFIG_BUGLY_APP_ID $CONFIG_BUGLY_APP_KEY $CONFIG_BUGLY_APP_BUNDLE_IDENTIFIER $CONFIG_BUGLY_APP_VERSION $DSYM_SYMBOL_ZIP_FILE
done
if [ $RET = "F" ]; then
exitWithMessage "No .dSYM found in ${DSYM_FOLDER}" 0
fi
}
# 在Xcode工程中執(zhí)行
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}")
# 組裝Bugly默認(rèn)識(shí)別的版本信息(格式為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 "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 "Check the arguments ..."
##檢查模擬器編譯是否允許上傳符號(hào)
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} ${BUGLY_APP_VERSION} ${DWARF_DSYM_FOLDER_PATH} ${BUILD_DIR}/BuglySymbolTemp ${UPLOAD_DSYM_ONLY}
}
# 根據(jù)Xcode的環(huán)境變量判斷是否處于Xcode環(huán)境
INFO_PLIST_FILE="${INFOPLIST_FILE}"
BuildInXcode="F"
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"
# 你可以在此處直接設(shè)置BuglyAppID和BuglyAppKey乾颁,排除不常變參數(shù)的輸入
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
替換Run Script后上傳成功