Bugly官方的自動配置文檔地址:點擊跳轉(zhuǎn)
根據(jù)官網(wǎng)文檔的配置贪薪,在Xcode12上面進行配置完運行,發(fā)現(xiàn)并不能如愿上傳dSYM文件荆永。經(jīng)過排查搔确,
1弄企、在掃描出dSYM文件進行壓縮的時候失尖,文件并不完整善榛,導致執(zhí)行以下命令的時候出錯
zip -r -j ${DSYM_SYMBOL_ZIP_FILE} ${dsymFile} -x *.plist
排查過程:
一開始以為是Xcode不支持 -r -j 多參數(shù)操作戴而,因為刪掉了 -j 之后壓縮就成功了砾肺。
但是挽霉,在上傳的時候接口又報錯了,進到壓縮文件目錄發(fā)現(xiàn)壓縮出來的 zip 只有2K变汪,很顯然這個壓縮文件是有問題的侠坎,繼續(xù)排查,最終發(fā)現(xiàn)在壓縮的過程中dSYM文件的內(nèi)容并不完整裙盾,導致壓縮出來的zip文件也不完整实胸。
猜測:在執(zhí)行掃描的過程中,dSYM文件夾雖然生成了番官,但是里面的內(nèi)容還沒填充完整庐完,還在繼續(xù)生成。于是在執(zhí)行zip的時候加多了10秒鐘的休眠徘熔,再次Archive门躯,dSYM上傳成功!
總結(jié):需要在執(zhí)行 zip 命令或者掃描dSYM前加上休眠時間酷师,等待dSYM文件夾內(nèi)容生成完整讶凉。休眠時間的長短由打包的機器性能而定。
sleep 8 # 這里是由于自己機器性能寫的8秒
2窒升、腳本從 info.plist 文件中解析 CFBundleVersion
和 CFBundleShortVersionString
在新的Xcode上面并不正確缀遍,會得到(MARKETING_VERSION)
BUNDLE_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "${INFOPLIST_FILE}")
BUNDLE_SHORT_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "${INFOPLIST_FILE}")
原因:我們在查看info.plist源碼的時候,發(fā)現(xiàn)在新版Xcode里面 它指向?qū)?yīng)的值就是 CURRENT_PROJECT_VERSION 和 MARKETING_VERSION 這兩個宏
解決:直接使用{MARKETING_VERSION} 即可饱须,無需解析info.plist文件
# 組裝Bugly默認識別的版本信息(格式為CFBundleShortVersionString(CFBundleVersion), 例如: 1.0(1))
if [ ! "${CUSTOMIZED_APP_VERSION}" ]; then
BUGLY_APP_VERSION="${MARKETING_VERSION}(${CURRENT_PROJECT_VERSION})"
else
BUGLY_APP_VERSION="${CUSTOMIZED_APP_VERSION}"
fi
其他說明
如果使用了默認的 UPLOAD_DSYM_ONLY=1 ,就沒必要再在機器上面放入 jar 包了台谊,小燈塔這邊就沒有使用蓉媳,所以也精簡了一下腳本:
#!/bin/sh
BUGLY_APP_ID="xxxxxx"
# #
BUGLY_APP_KEY="xxxxxxxxx"
# #
BUNDLE_IDENTIFIER="com.ad61v1.xiaodengta"
#
# # 腳本默認配置的版本格式為CFBundleShortVersionString(CFBundleVersion), 如果你修改默認的版本格式, 請設(shè)置此變量, 如果不想修改, 請忽略此設(shè)置
# CUSTOMIZED_APP_VERSION="1.0"
#
# # Debug模式編譯是否上傳譬挚,1=上傳 0=不上傳,默認不上傳
UPLOAD_DEBUG_SYMBOLS=0
#
# # 模擬器編譯是否上傳酪呻,1=上傳 0=不上傳减宣,默認不上傳
UPLOAD_SIMULATOR_SYMBOLS=0
#
# #只有Archive操作時上傳, 1=支持Archive上傳 0=所有Release模式編譯都上傳
UPLOAD_ARCHIVE_ONLY=1
# Bugly服務(wù)域名
BUGLY_DSYM_UPLOAD_DOMAIN="api.bugly.qq.com"
# 打印錯誤信息
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 "channel=AppStore" --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
}
# 執(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"
# 檢查必須參數(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"
# 睡眠8秒
sleep 8
#
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}
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
# 上傳
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 ..."
# 組裝Bugly默認識別的版本信息(格式為CFBundleShortVersionString(CFBundleVersion), 例如: 1.0(1))
if [ ! "${CUSTOMIZED_APP_VERSION}" ]; then
BUGLY_APP_VERSION="${MARKETING_VERSION}(${CURRENT_PROJECT_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 ..."
##檢查模擬器編譯是否允許上傳符號
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
}
# 根據(jù)Xcode的環(huán)境變量判斷是否處于Xcode環(huán)境
INFO_PLIST_FILE="${INFOPLIST_FILE}"
BuildInXcode="F"
if [ -f "${INFO_PLIST_FILE}" ]; then
BuildInXcode="T"
fi
echo "BUNDLE_SHORT_VERSION:"${BUNDLE_SHORT_VERSION}
echo "BUNDLE_VERSION:"${BUNDLE_VERSION}
if [ $BuildInXcode = "T" ] && [ ! -f "JenkinsFlag" ]; 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