我是react-native-bugsnag的作者。
我不隶属于该公司,但我喜欢他们的仪表板和定价模型,因此我为我们的 react-native 程序员创建了这个库,以便使用他们的服务。
[TL/DR]:
1)复制下面的脚本,将其添加到您的项目根目录,
2) 更改脚本开头的版本以匹配您的 react-native 项目的本机部分的版本。
3)运行它:
sh crash_report.sh -i <BUGSNAG_KEY>
捆绑并上传您的 ios 源地图,
或者
sh crash_report.sh -a <BUGSNAG_KEY>
捆绑和上传你的安卓源地图。
[更长的版本]:
官方的react-native bugsnag sdk现已发布。
它支持iOS/Android 和 Javascript处理和非处理崩溃报告。
让我解释一下我是如何做到的:
我创建了一个名为的文件,该文件crash_report.sh
创建了我的项目源映射,并将它们上传到 bugsnag,以及我的所有项目文件,这样我就可以看到如下丰富的错误报告:

要使用它,您只需将它添加到您的项目根文件夹,将版本变量appVersion
((这非常重要)否则您将无法在 bugnsag 中看到去混淆的代码然后运行它。
crash_report.sh:
#!/bin/bash
appVersion='1.0.0' # IMPORTANT, this has to be the same as the version of your native project in xcode or android studio.
# Get shell args
aflag=''
iflag=''
platform=''
bugsnagKey=''
while getopts 'i:a:' flag; do
case "${flag}" in
a)
aflag='true'
bugsnagKey=$OPTARG
;;
i) iflag='true'
bugsnagKey=$OPTARG
;;
*) printf "Usage: %s: [-a] [-i] args\n" $0
esac
done
if [ -n "$aflag" ] && [ -z "$iflag" ]; then
printf "Now bundling for android.\n"
platform='android'
fi
if [ -n "$iflag" ] && [ -z "$aflag" ]; then
printf "Now bundling for ios.\n"
platform='ios'
fi
if [ -z "$platform" ]; then
printf "\nUsage: <script> -i <BUGSNAG_KEY> OR -a <BUGSNAG_KEY>. \nTerminating...\n\n"
else
printf "Now fetching project properties from package.json\n"
echo 'Now creating sourcemaps\n App version: '${appVersion}' for platform: '${platform}
# #Create iOS sourcemaps
react-native bundle --dev false --platform ${platform} --entry-file index.${platform}.js --bundle-output main.${platform}.jsbundle --sourcemap-output main.${platform}.jsbundle.map
echo 'Now uploading with key: '${bugsnagKey}' for version '${appVersion}
CUR_DIRR=`pwd` # Get current directory
CUR_DIRR=${CUR_DIRR}'/' # Append a forward slash to it
# Here we get ALL the project files, and form them as curl params, so that we can later on pass them to curl
PROJECT_FILES=$(find src -name '*.js' | while read -r i; do echo '-F '$CUR_DIRR$i'=@'$i; done) # Form the right file ending for curl
# echo ${PROJECT_FILES}
# #Upload iOS sourcemaps
curl -w "\n\n%{http_code}\n" --progress-bar -F apiKey=${bugsnagKey} -F appVersion=${appVersion} -F minifiedUrl="main.jsbundle" -F sourceMap=@main.${platform}.jsbundle.map -F minifiedFile=@main.${platform}.jsbundle -F overwrite=true ${PROJECT_FILES} https://upload.bugsnag.com
echo '\nDone.\n'
fi
我希望这对某人有所帮助,这花了我几个小时才弄清楚。玩得开心..!