当应用程序在应用模拟器中运行时,如何用React Native调试他们的React代码?


当前回答

如果你想了解检查网络流量和理解原生UI视图层次结构。通过其可扩展的插件API, React Native Update版本为调试移动应用程序提供了开发人员工具。

Flipper是一个调试移动应用程序的很棒的开发工具。该工具随react-native 62一起发布

其他回答

对我来说,在React-Native上调试的最好方法是使用“Reactotron”。

安装Reactotron,然后将这些添加到你的package.json:

"reactotron-apisauce": "^1.1.2",
"reactotron-react-native-under-37": "^1.1.2",
"reactotron-redux": "^1.1.2", 

现在,只需要登录您的代码。 例如:console.tron.log(调试)

在Windows中,使用android模拟器,你可以执行以下步骤:

模拟器运行后,应用程序在它上面,按下菜单按钮,然后选择“调试JS远程”或“调试在Chrome中”(这取决于模拟器使用)。你可以看到下一个图像作为参考:模拟器的步骤图像 一个新的Chrome标签将出现。你必须按Ctrl + J来显示开发人员工具,并开始跟踪调试步骤。请看这张图片作为参考

此外,您应该使用console.log()特性来使调试过程更具描述性。

我没有足够的声誉来评论之前的答案,这些答案都很好。:) 以下是我在开发react-native应用程序时调试的一些方法。

Live reloading react-native makes it super easy to see your changes with the ⌘ + R keys or even just enable live reload and watchman will "refresh" the simulator with the latest changes. If you get an error, you can get a clue from the line number from that red screen. A couple of undo will get you back to working state and start again. console.log('yeah, seriously.') I find myself prefer letting the program run and logging some informations than adding a debugger break point. (tough debugger is useful when trying to work with external packages/libraries and it comes with autocompletion, so you know what other methods you can utilise.) Enable Chrome Debugging with debugger; break point in your program.

这取决于您遇到的错误类型以及您对如何调试的偏好。对于大多数未定义的不是一个对象(评估'something.something'),方法1和2对我来说已经足够好了。

然而,处理由其他开发人员编写的外部库或包将需要更多的努力来调试,因此有一个像Chrome Debugging这样的好工具

有时它来自react-native平台本身,所以谷歌一下react-native问题肯定会有帮助。

希望这能帮助到一些人。

你可以使用Safari来调试iOS版本的应用程序,而不必启用“远程调试JS”,只需遵循以下步骤:

1. Enable Develop menu in Safari: Preferences → Advanced → Select "Show Develop menu in menu bar"
2. Select your app's JSContext: Develop → {Your Simulator} → Automatically Show Web Inspector for JS JSContext
3. Safari's Web Inspector should open which has a Console and a Debugger

我使用这个库来调试react-native项目

https://github.com/jhen0409/react-native-debugger 它包括

包括React -devtools-core中的React Inspector。 包括回家的 DevTools,用redux-devtools-extension做了相同的API。

或者你可以用

For IOS $ react-native log-ios
For Android $ react-native log-android