当应用程序在应用模拟器中运行时,如何用React Native调试他们的React代码?
当前回答
使用可视化代码工作室调试react原生android和ios应用程序的最佳方法
步骤1。
安装React Native -完整的扩展包
步骤2。
使用USB调试模式连接移动设备或从android工作室打开模拟器。
步骤3。
在可视代码工作室的左侧菜单中单击调试选项 点击添加配置,选择React Native,然后创建launch.json
步骤4。
打开dev选项在手机上的长后按或摇手机和启用调试js远程
第5步。
最后一步点击播放按钮,选择调试android或调试ios
更多信息请参考这个链接
https://medium.com/@tunvirrahmantusher/android-debug-with-vscode-for-react-native-96f54d73462a
其他回答
React本机调试器。它帮我解决了90%的问题
要调试你的react原生应用程序,只需到以下地址:
localhost: 8081 / debugger-ui 在你的默认浏览器(chrome)和打开开发者工具来调试你的react原生应用程序
如果你想了解检查网络流量和理解原生UI视图层次结构。通过其可扩展的插件API, React Native Update版本为调试移动应用程序提供了开发人员工具。
Flipper是一个调试移动应用程序的很棒的开发工具。该工具随react-native 62一起发布
我没有足够的声誉来评论之前的答案,这些答案都很好。:) 以下是我在开发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问题肯定会有帮助。
希望这能帮助到一些人。
如果你想在默认情况下打开调试:
import { NativeModules } from 'react-native';
if (__DEV__) {
NativeModules.DevSettings.setIsDebuggingRemotely(true)
}
要让它在Android上工作:
npm install --save react-native-devsettings-android
react-native link react-native-devsettings-android
参考:启动一个React Native应用程序,默认启用“调试JS远程”
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- iPhone上UIView和UILabels的渐变
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- keychain上的分发证书中缺少私钥
- 在实现API时,我如何避免在块中捕获自我?
- 如何设置整个应用程序在纵向模式?
- 我如何调试git/git-shell相关的问题?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?