xcode React-Native ios App 在没有报告的情况下崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35785747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
React-Native ios App crashes without report
提问by Sasha
I'm building an iOS app using React Native and trying to get it testable on phones.
我正在使用 React Native 构建一个 iOS 应用程序,并试图让它在手机上进行测试。
If I plug my phone into the computer and "build" directly to the phone, the app is built correctly and opens/operates correctly, no problem.
如果我将手机插入计算机并直接“构建”到手机上,则该应用程序构建正确且打开/运行正常,没问题。
But if I try to archive it and send it to phones using iTunes Connect's TestFlight or Fabric with Crashlytics, the app crashes immediately upon opening. It briefly shows the launch screen, but no more.
但是,如果我尝试使用 iTunes Connect 的 TestFlight 或带有 Crashlytics 的 Fabric 将其存档并发送到手机,则该应用程序在打开时会立即崩溃。它简要地显示启动屏幕,但不再显示。
Moreover, there are no crash reports -- in TestFlight, in Crashlytics, or in XCode, once I plug the phone back in. So I'm operating in the dark here, without any information on what's breaking. Haven't been able to find a similar issue online, so I figured I'd just ask. Any ideas what could be going wrong?
此外,没有崩溃报告——在 TestFlight、Crashlytics 或 XCode 中,一旦我将电话重新插入。所以我在这里暗中操作,没有任何关于发生故障的信息。网上没找到类似的问题,所以想问问。任何想法可能会出错?
Please let me know if there's any code or other data you might need to see. Some of it's confidential, but I'll try to post an approximate version.
如果您需要查看任何代码或其他数据,请告诉我。其中一些是机密的,但我会尝试发布一个大概的版本。
采纳答案by Sasha
As Chris Geirman suggested, the problem was a JavaScript error. I'm not sure people with similar problems will find this thread, but in case they do, here is the weird error that was occurring.
正如 Chris Geirman 所建议的,问题是 JavaScript 错误。我不确定有类似问题的人会找到这个线程,但如果他们这样做了,这是发生的奇怪错误。
I had created a simple ORM system, with a BaseModel and a bunch of models that inherited from it. The BaseModel constructor looked like this:
我创建了一个简单的 ORM 系统,带有一个 BaseModel 和一堆继承自它的模型。BaseModel 构造函数如下所示:
constructor(props = {}, relations = {}) {
Object.keys(props).forEach((k) => {
// Save props to object
this[k] = props[k];
});
this.relations = relations;
this.className = this.constructor.name;
}
That last line was the problem. On my local simulator and if I build the app to my phone by plugging it in, this works fine. As in, if a Message model inherits from BaseModel, calling var msg = new Message(data, relations); msg.className
returns Message
.
最后一行是问题所在。在我的本地模拟器上,如果我通过插入应用程序将应用程序构建到我的手机上,这可以正常工作。如在,如果 Message 模型继承自 BaseModel,则调用var msg = new Message(data, relations); msg.className
返回Message
.
But something about bundling/archiving/sending the app through TestFlight or Fabric.io minifies and uglifiesthe JavaScript, such that the class names are changed. So instead, if I do this -- var msg = new Message(data, relations); msg.className
-- I'll get back a random variable name, something like 't'.
但是关于通过 TestFlight 或 Fabric.io 捆绑/归档/发送应用程序的一些事情会缩小和丑化JavaScript,从而更改类名称。所以相反,如果我这样做 -- var msg = new Message(data, relations); msg.className
-- 我会得到一个随机变量名称,比如“t”。
This was a problem in my app, because my home page contained a switch statement that worked off of the className:
这是我的应用程序中的一个问题,因为我的主页包含一个关闭 className 的 switch 语句:
iconContent() {
return {
Message: {
icon: <Image style={styles.feedItemIconImage} source={ require('../assets/img/icon_message.png') } />,
color: c.grass
}, ...
}[this.props.className] // from the model item
}
But 'Message'
wasn't, as expected, the value of this.props.className
-- 't'
was. And so, if I were to try to tunnel into, say, the color
value, I'd hit an error, because I was trying to access the color
property of null
.
但'Message'
并没有如预期的价值this.props.className
-'t'
是。所以,如果我试图隧道进入,说的color
价值,我会打一个错误,因为我试图访问color
的性能null
。
Why that didn't report, I don't know (I followed Chris's suggestions and installed Sentry, but it still seemed not to report that error).
为什么没有报告,我不知道(我按照 Chris 的建议安装了 Sentry,但它似乎仍然没有报告该错误)。
But that's what was going on. Minification/uglification occurred onlywhen I installed the app on a phone via TestFlight/Fabric, and that's why the app only crashed in those conditions.
但这就是正在发生的事情。仅当我通过 TestFlight/Fabric 在手机上安装应用程序时才会发生缩小/丑化,这就是应用程序仅在这些情况下崩溃的原因。
Hope this saves anyone running into a similar bug from tearing out their hair.
希望这可以避免任何遇到类似错误的人撕掉他们的头发。
回答by eden
I'd like to share my own experience of production stage crash, whereas everything worked fine in development stage.
我想分享我自己的生产阶段崩溃的经验,而在开发阶段一切正常。
I had the similar problem which caused by the Reactotronlogger. Since I'm not bundling it in production stage, a single line of console.tron.log crashed my app with full stealth. (Its kinda my fault, since I didn't give a damn about my linter with 'no-console' setting)
我遇到了由Reactotron记录器引起的类似问题。因为我没有在生产阶段捆绑它,所以一行 console.tron.log 完全隐蔽地崩溃了我的应用程序。(这有点是我的错,因为我并没有在意我的“无控制台”设置的短绒绒)
Here's the code snippet I introduce in my root level file, root.js.
这是我在我的根级文件 root.js 中引入的代码片段。
if (__DEV__) {
...
console.tron = Reactotron;
...
}
Hope somebody finds this before wasting time figuring out what's wrong.
希望有人在浪费时间弄清楚出了什么问题之前发现了这一点。
回答by loopj
Not sure if you still have this problem - but if you do, I'd recommend checking out Bugsnag for react native error reporting- which reports crashes in both the JavaScript layer as well as the native layers (java/cocoa).
不确定你是否仍然有这个问题——但如果你有这个问题,我建议你查看 Bugsnag 以获取本机错误报告——它报告了 JavaScript 层和本机层 (java/cocoa) 中的崩溃。
One of the harder problems to solve in react native crash reporting (as Sasha mentioned) is restoring the original stack traces when using minification and/or obfuscation - this is handled in Bugsnag by providing full support for JS source maps, as well as iOS symbolication and Android Proguard support at the native layers.
在 React Native 崩溃报告(如 Sasha 提到的)中要解决的较难问题之一是在使用缩小和/或混淆时恢复原始堆栈跟踪 - 这在 Bugsnag 中通过提供对 JS 源映射以及 iOS 符号化的完全支持来处理和原生层的 Android Proguard 支持。
Let me know if this helps - I'm a founder @ Bugsnag
如果这有帮助,请告诉我 - 我是创始人 @ Bugsnag