https://github.com/abaelhe/zulip

https://github.com/abaelhe/zulip-mobile

Debugging

Seeing what the app is doing is an essential part of development. A variety of tools are available to help us do that.

Index:

Official advice from React Native upstream

Debugging our main app code in RN, especially React and Redux

... with the Chrome Developer Tools / Remote JS Debugging

... with React DevTools

... with redux-logger

... with immutable-devtools

Debugging the message list in its WebView

... on iOS, with Safari developer tools

... on Android, with the Chrome Developer Tools (different from using it for RN!)

Debugging platform-native code (i.e. not JS)

... on Android, with adb logcat

Debugging with Sentry

... with a testing-only Sentry project

Troubleshooting

Remote JS Debugging opens a webpage that never loads.

Upstream advice from React Native

React Native's documentation has a "Debugging" page with a wide variety of tips.

Definitely read about:

the In-App Developer Menu

Reloading JavaScript

In-App Errors and Warnings

The Chrome Developer Tools are also essential; see the next section here for details.

Other advice on the page may be useful, but feel free to skim or skip.

Tools: React + Redux

These tools connect to the JavaScript environment that React Native sets up and most of our app code runs in. They provide JS-level debugging there, plus useful hooks specific to React and Redux.

Chrome Developer Tools / Remote JS Debugging

React Native supports debugging the app using Chrome's developer tools, in much the same way you would a web app. This provides you with prettily formatted debug messages and helpful additional information.

To use it, start the app. (Either in the emulator, or see here for additional instructions to do this on a physical device.) Then, open the Developer Menu. Here, select "Debug" (formerly "Debug JS Remotely"). This will open a new tab in your browser, at http://localhost:8081/debugger-ui . Go to this tab and open the developer console.

This console will show all console debug output from your app, which means that you can debug the app with statements like

console.debug(foobar)

Additionally, all Redux events are automatically logged to the console. See discussion of redux-logger below.

See also in the "Troubleshooting" section below.

React DevTools

The standalone version of the React Developer Tools, an Electron app, can be used to debug the React component hierarchy in our app. See RN's docs on how to use it with RN.

As of 2020-01, the latest version (v4) of React DevTools does not support any released version of React Native; see its release notes. Instead, install v3 with the command yarn global add react-devtools@3.

redux-logger: deeper info on Redux events

One extremely useful kind of information for debugging many kinds of issues -- as well as for getting to understand how the app works! -- is to see the Redux state, and a log of the Redux actions.

We have exactly that information logged to the console (in the Chrome Developer Tools; see above), thanks to the middleware redux-logger.

By default, it logs the previous state and next state of every action that is dispatched. You can control its behavior in more detail by editing the call to createLogger in src/boot/middleware.js.

diff: true will compute the diff (using deep-diff) between the old and new states. For example, the log output for the action SWITCH_NARROW can look like this:

image

This can be especially helpful for seeing what each action really does.

predicate can be used to filter which actions cause a log message. By default, all actions are logged; when looking at a long log, this option can help you cut noise and focus on actions relevant to what you're studying.

Many other options exist! See the doc.

immutable-devtools: inspect Immutable.js objects in Chrome

Some of the data in the Redux state is stored in Immutable.js data structures. It's normally awkward to inspect these data structures; an Immutable.Map object, for example, is full of properties like size, __altered, __hash, and __ownerID, which you have to dig around to get at a clear representation of the items contained.

immutable-devtools fixes this problem in Google Chrome v47+ by installing a "custom formatter".

(Alternatively, we might have recommended a Chrome extension, which immutable-devtools mentions in its setup doc. But using the NPM package provides the formatter for zulip-mobile just as effectively without making widespread changes in behavior when you browse the Web.)

To enable it, open Chrome Dev Tools and press F1 to open the settings. In the "Console" section, tick "Enable custom formatters". If it isn't working, please consult the project's issue tracker before opening an issue in zulip-mobile.

Tools: Debugging the message list (in WebView)

We render the message list using a native WebView component. Anything related to the rendering of messages, the behavior of the message list, or bugs inside it, you can debug with familiar tools.

Debugging is available both for Android and iOS, and on an emulator or a physical device via a browser's developer tools.

We've defined a function sendMessage that can send a message from within the WebView to React Native-land outside it. This can be used (with type: 'debug') if you want to see WebView logs alongisde React Native logs.

To debug code that runs during the initial load of the WebView, add alert("pause"); debugger; where you want a breakpoint. Then open the WebView and connect the debugger before clearing the alert.

Debug WebView on iOS

Enable debugging on the device

For iOS Simulator you can skip this step, as it is already enabled.

To debug on your physical iOS device, go to Settings > Safari > Advanced and make sure Web Inspector is on.

Connect to the device

Run Safari (even if your browser of choice is something else).

If you have not done so already, enable the developer tools by going to Safari’s menu, Preferences > Advanced, and checking the Show Develop menu in the menu bar checkbox.

In the app you are debugging, make sure you have navigated to a screen that is showing a message list.

In the Develop menu, find your device and select it.

Debug

You now have access to the rich developer tools you might be familiar with. You can inspect HTML elements, CSS styles and examine console.log output.

Debug WebView on Android

Enable debugging on the device

For the Android emulator you can skip this step, as it is already enabled.

To debug on your physical Android device, go to Settings > About phone. Next, tap the Build number panel seven times. You will get a notice that now you are a developer. Go back to the main Settings screen. Go to the new Developer options menu and enable the USB debugging checkbox.

Connect to the device

Run Chrome.

Navigate to about:inspect.

Check the Discover USB devices and the app will appear.

Debug

You now have access to the rich developer tools you might be familiar with. You can inspect HTML elements, CSS styles and examine console.log output.

Tools: Native

These tools operate outside the JavaScript environments set up by either React Native or our WebView for the message list. They're essential for debugging our platform-native code which runs outside those JS environments.

adb logcat

When running on Android, either in the emulator or on a physical device, you can use ADB (the Android debugger) to fetch or watch the device's logs. This will include any messages that you print with a statement like

console.debug(foobar)

To see the logs, run adb logcat. This accepts many command-line flags to filter and control the output, some of them extremely useful -- see upstream documentation. Start with the section on filtering log output; feel free to skim the whole rest of the document, but definitely read that section.

Example useful command lines with adb logcat:

adb logcat -T 100 ReactNativeJS:V *:S

This filters out logs unrelated to the app (along with many things that are related), but includes anything you print with console.debug. It starts with the last 100 matching log lines from before you run the command (so it can be helpful for seeing something that just happened), and then it keeps running, printing any new log messages that come through. To quit, hit Ctrl-C.

adb logcat -t 100 *:W

This filters out logs at levels V, D, and I (verbose, debug, info), leaving only W, E, and F (warning, error, fatal). It includes errors at these levels from anything on the system -- often good because it isn't always predictable what tag an important message will come with. It prints the last 100 matching messages, and exits.

adb logcat -T $(date +%s.%N -d "2 minutes ago") *:W

This prints messages since a certain time, then keeps running to print new log messages that come through. The date command is there in order to turn a nice human-formatted time into the format adb logcat expects.

(On macOS, your date command may not have this feature, because it's a version whose UI hasn't changed since the '80s. You want GNU date. brew install coreutils will install it, with the name gdate.)

Debugging with Sentry

We use Sentry to get alerts about things going wrong in the app.

Testing Sentry itself, with testing-only project

Normally, debug builds of the app (and others that aren't meant to become published release builds) don't send any data to Sentry. In development one sees errors in a more direct way anyway, and we don't want to get confusing noise into our production Sentry data. (For full discussion, see src/sentryConfig.js.)

For testing our Sentry reporting itself, though, one wants to send events to Sentry after all. To avoid polluting our production Sentry data, do this by sending them to a Sentry project that's specifically for testing. For core developers, we have a project called "testing" in our Sentry team, but any project will work.

The "DSN" or "client key" is how we tell the Sentry client where to send events. For Zulip's "testing" project, members of the team can find the DSN at https://sentry.io/settings/zulip/projects/testing/keys/ .

To send events from the JavaScript layer, paste the DSN into src/sentryConfig.js as the value of sentryKey.

To send events from the native Android layer, edit android/app/src/main/AndroidManifest.xml similarly, following the comment around io.sentry.dsn.

Troubleshooting

Remote JS Debugging ("Debug") opens a webpage that never loads.

For some reason, React Native may try to open a browser tab for you at http://10.0.2.2:8081/debugger-ui . Instead, it should be http://localhost:8081/debugger-ui .

To fix this, simply open http://localhost:8081/debugger-ui in your browser. This should load the web debugger you expected. Also, if the app was showing a blank screen before, it should now behave normally.

If you're still experiencing this issue, open the Developer menu in your app. Then, go to "Debug server host & port for device". Here, enter localhost:8081 and click OK. Now, try to open http://localhost:8081/debugger-ui again and see if it works.

Zulip: Debugging Zulip-Mobile: Server + Android + IOS的更多相关文章

  1. 来了!GitHub for mobile 发布!iOS beta 版已来,Android 版即将发布

    北京时间 2019 年 11 月 14 日,在 GitHub Universe 2019大会上,GitHub 正式发布了 GitHub for mobile,支持 iOS 与 Android 两大移动 ...

  2. Tomcat双向Https验证搭建,亲自实现与主流浏览器、Android/iOS移动客户端超安全通信

    紧接着<Tomcat单向Https验证搭建,亲自实现与主流浏览器.Android/iOS移动客户端安全通信>,此处演示下更安全的双向Https认证的通信机制,为了清晰明了,以下进行单独描述 ...

  3. Tomcat单向Https验证搭建,亲自实现与主流浏览器、Android/iOS移动客户端安全通信

    众所周知,iOS9已经开始在联网方面默认强制使用Https替换原来的Http请求了,虽然Http和Https各有各的优势,但是总得来说,到了现在这个安全的信息时代,开发者已经离不开Https了. 网上 ...

  4. (跨平台)cocos2d-x C++ or Object-C(前端)调用C# webservices(后台),实现交叉编译到Android/IOS/WinPhone等移动终端设备

    1.2014年4月2号算是正式找到自己的实习工作-杭州美迪软件有限公司(移动物联事业部)合作于:四川管家婆总部移动终端代理,由于在校选编程专业语言C#和在浙大网新培训课程(C#.Asp.net开发)缘 ...

  5. React++ node.js ++SQL Sever ++MySQL++ python ++ php ++ java ++ c++ c#++ java ++ android ++ ios ++Linux+

    "C语言在它诞生的那个年代,是非常不错的语言,可惜没有OOP.当项目臃肿到一定程度,人类就不可控了. 为了弥补这个缺陷,C++诞生了.而为了应对各种情况,C++设计的大而全,太多复杂的特性, ...

  6. Delphi APP 開發入門(二)Android/iOS設定,Hello World

    Delphi APP 開發入門(二)Android/iOS設定,Hello World 分享: Share on facebookShare on twitterShare on google_plu ...

  7. 用HTML5/CSS3/JS开发Android/IOS应用框架大全

    现在人人都想成为安卓/IOS应用开发工程师.其实,安卓/IOS应用可以用很多种语言来实现.由于我们前端开发工程师,对HTML5/CSS/JavaScript的网络编程已经相当熟悉了.所以,今天大家将会 ...

  8. React Native hot reloading & Android & iOS

    React Native hot reloading & Android & iOS https://facebook.github.io/react-native/docs/debu ...

  9. Android IOS WebRTC 音视频开发总结(八十五)-- 使用WebRTC广播网络摄像头视频(下)

    本文主要介绍WebRTC (我们翻译和整理的,译者:weizhenwei,校验:blacker),最早发表在[编风网] 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacker(微信ID:bl ...

  10. Android IOS WebRTC 音视频开发总结(八十三)-- 使用WebRTC广播网络摄像头视频(上)

    本文主要介绍WebRTC (我们翻译和整理的,译者:weizhenwei,校验:blacker),最早发表在[编风网] 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacker(微信ID:bl ...

随机推荐

  1. Typora——锚点

    意思就是只能跳到标题(单击时可能需要按Ctrl),即# 开头的字段,格式很简单,例如对于一个二级标题,单击(按住Ctrl)"我想跳转",可以跳到"跳 到 这 里" ...

  2. 【深度学习】MLE视角下的VAE与DDPM损失函数推导

    正文 最大似然估计的由来 VAE和DDPM都是likelihood-based生成模型,都是通过学习分布->采样实现图像生成的: 这类模型最大的特点就是希望实现 \[\theta = \arg\ ...

  3. CentOS 7.6 安装 Mysql 5.7

    一.查看CentOS版本 Mysql的版本必须要和CentOS的版本对应!查看CentOS版本的指令如下: cat /etc/redhat-release 二.下载yum源包 wget http:// ...

  4. codeup之字符串逆序存放

    Description 写一个函数将一个字符串按反序存放.在主函数中输入一个字符串,通过调用该函数,得到该字符串按反序存放后的字符串,并输出. Input 一行字符串. Output 输入字符串反序存 ...

  5. dev c++基础操作

    文章目录 改变字体大小&改变背景色 最终效果 调节字体大小 调节背景色 常用快捷键 调试时粘贴测试数据 改变字体大小&改变背景色 最终效果 调节字体大小 Tools -> Edi ...

  6. [python] 轻量级定时任务调度库schedule使用指北

    schedule是一款专为简化定时任务调度而设计的Python库,它通过直观的语法降低了周期性任务的实现门槛.作为进程内调度器,它无需额外守护进程,轻量且无外部依赖,适合快速搭建自动化任务.不过,该库 ...

  7. React Native开发鸿蒙Next---react-native-cameraroll在ArkTS下的接入报错

    .markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...

  8. wso2~自定义event-publisher

    自定义event/publishers的步骤 介绍 event/publishers功能位于carbon平台的event菜单,选择publishers菜单项即可打开发布者配置列表,你可以添加自定义的发 ...

  9. python获取地理位置

    废话不多说,直接上代码 1 from urllib.request import urlopen 2 my_ip = urlopen('http://ip.42.pl/raw').read() 3 4 ...

  10. LUNARiA

    本文同步发布于我的网站 也算是头一次在没有任何安利和剧透,仅在看了简介的情况下就直接下单并开始游玩一部gal了.果然,没有给我留下什么遗憾呢. 游玩日志 SKYOUT-FOREVER <LUNA ...