简体   繁体   English

React-Native ios应用程序在没有报告的情况下崩溃

[英]React-Native ios App crashes without report

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. 但是,如果我尝试将其存档并使用iTunes Connect的TestFlight或Fabric with Crashlytics将其发送到手机,则应用程序会在打开时立即崩溃。 It briefly shows the launch screen, but no more. 它简要地显示了启动屏幕,但没有更多。

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. 此外,没有崩溃报告 - 在TestFlight,Crashlytics或XCode中,一旦我重新插入手机。所以我在黑暗中操作,没有任何有关什么破坏的信息。 Haven't been able to find a similar issue online, so I figured I'd just ask. 一直无法在网上找到类似的问题,所以我想我只是问。 Any ideas what could be going wrong? 什么想法可能会出错?

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. 其中一些是保密的,但我会尝试发布一个近似版本。

As Chris Geirman suggested, the problem was a JavaScript error. 正如Chris Geirman所说,问题是JavaScript错误。 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. 我不确定有类似问题的人会找到这个帖子,但如果他们这样做,这就是发生的奇怪错误。

I had created a simple ORM system, with a BaseModel and a bunch of models that inherited from it. 我创建了一个简单的ORM系统,包含一个BaseModel和一系列继承它的模型。 The BaseModel constructor looked like this: 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 如同,如果Message模型继承自BaseModel,则调用var msg = new Message(data, relations); msg.className var msg = new Message(data, relations); msg.className returns Message . var msg = new Message(data, relations); msg.className返回Message

But something about bundling/archiving/sending the app through TestFlight or Fabric.io minifies and uglifies the JavaScript, such that the class names are changed. 但是有关通过TestFlight或Fabric.io捆绑/存档/发送应用程序的内容会缩小和丑化 JavaScript,以便更改类名。 So instead, if I do this -- var msg = new Message(data, relations); msg.className 所以相反,如果我这样做 - var msg = new Message(data, relations); msg.className var msg = new Message(data, relations); msg.className -- I'll get back a random variable name, something like 't'. 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. 但是, 'Message'并不像预期的那样,是this.props.className的值 - 't' 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 . 所以,如果我试图隧道进入color值,我会遇到错误,因为我试图访问nullcolor属性。

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 only when 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. 希望这可以避免任何遇到类似错误的人撕掉他们的头发。

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 Reactotron logger. 我遇到了由Reactotron记录器引起的类似问题。 Since I'm not bundling it in production stage, a single line of console.tron.log crashed my app with full stealth. 由于我没有将它捆绑在生产阶段,因此一行console.tron.log使我的应用程序完全隐身崩溃。 (Its kinda my fault, since I didn't give a damn about my linter with 'no-console' setting) (这有点我的错,因为我没有用“无控制台”的设置对我的linter说些什么)

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. 希望有人在浪费时间找出错误之前找到这个。

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. 反应原生崩溃报告中要解决的难题之一(正如Sasha所提到的)是在使用缩小和/或混淆时恢复原始堆栈跟踪 - 这在Bugsnag中通过提供对JS源映射的完全支持以及iOS符号来处理和原始图层的Android Proguard支持。

Let me know if this helps - I'm a founder @ Bugsnag 如果这有帮助,请告诉我 - 我是@ Bugsnag的创始人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM