简体   繁体   English

如何在 Visual Studio 代码中调试 React Native 应用程序?

[英]How to debug react native apps in visual studio code?

I am using visual studio code IDE to develop react native app and am not using expo library.我正在使用 Visual Studio 代码 IDE 来开发本机应用程序,并且没有使用 expo 库。

Before that I was working on the android studio, debugging in that is straightforward and simple.在此之前,我在 android studio 工作,在那里进行调试非常简单明了。

Now for react-native, I wanted to know how to debug my app using visual studio code IDE?现在对于 react-native,我想知道如何使用 Visual Studio 代码 IDE 调试我的应用程序?

If you want to debug the app in VS Code itself, like in other IDEs.如果您想在 VS Code 本身中调试应用程序,就像在其他 IDE 中一样。 Then on approach can be to follow the following steps:然后在方法上可以按照以下步骤进行:

  1. Install React Native Tools Extension (provided by Microsoft ) to VS Code.React Native Tools Extension(由Microsoft提供)安装到 VS Code。

在此处输入图片说明

This is a nice add on to VS Code's capabilities for React Native.这是对 VS Code 的 React Native 功能的一个很好的补充。

  1. Then go to Debug option from left menu and click on Add Configuration.然后从左侧菜单转到调试选项,然后单击添加配置。

在此处输入图片说明

If it initially says No Configuration then you can click on Add Configuration and then choose React Native option.如果它最初显示No Configuration那么您可以单击 Add Configuration,然后选择 React Native 选项。

  1. Now if already have Launch configuration added, then you can click on Add Configuration button then you will see more options related to React Native.现在如果已经添加了Launch configuration ,那么您可以单击 Add Configuration 按钮,然后您将看到更多与 React Native 相关的选项。

在此处输入图片说明

You can add configurations for React Native: Attach to Packager , React Native: Debug to Android , React Native: Debug to iOS in your launch.json file.您可以在launch.json文件中为React Native: Attach to PackagerReact Native: Debug to AndroidReact Native: Debug to iOS添加配置。 It is present in .vscode folder.它存在于.vscode文件夹中。

  1. Then add your breakpoints in code.然后在代码中添加断点。 Now suppose you already have your app running on emulator then you can choose option Attach to Packager .现在假设您的应用程序已经在模拟器上运行,那么您可以选择选项Attach to Packager

在此处输入图片说明

  1. Then on emulator or device open developer options (Ctrl + M for Windows + Android) and click on Debug JS Remotely .然后在模拟器或设备上打开开发人员选项(Windows + Android 为 Ctrl + M)并单击Debug JS Remotely

在此处输入图片说明

Now your breakpoints should be working.现在你的断点应该可以工作了。 Similarly if your app wasn't working already then you can go for Debug Android or Debug iOS accordingly.同样,如果您的应用程序尚未运行,那么您可以相应地进行Debug AndroidDebug iOS

Step1: Open app Setting in your mobile by shaking your mobile or by typing this command in your machine if your running android.步骤1:通过摇动手机或在您的机器中输入此命令(如果您正在运行Android)打开手机中的应用设置。

adb shell input keyevent 82

Step2: Select Debug JS Remotely which is the second option. Step2:选择Debug JS Remotely ,这是第二个选项。 Step3: In your Browser type Url http://localhost:8081/debugger-ui/ Step4: Again Open App Setting by shaking or running the command shown in step 1 and select Reload option which is first option步骤 3:在您的浏览器中输入 Url http://localhost:8081/debugger-ui/步骤 4:再次通过摇动或运行步骤 1 中显示的命令打开应用设置,然后选择重新加载选项,这是第一个选项

Now You can get all console logs in the browser and also you can debug your app remotely by putting breakpoints and analyze the values step by step.现在您可以在浏览器中获取所有控制台日志,还可以通过放置断点并逐步分析值来远程调试您的应用程序。

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

相关问题 使用 Visual Studio Code 进行 React Native 调试不起作用 - React Native debug with Visual Studio Code not working 如何在 Visual Studio 代码中构建 react.js 应用程序? - How to build react.js apps at visual studio code? 如何在 Visual Studio 代码中调试“create-react-app”? - How to debug `create-react-app`s in visual studio code? 如何让 React Native 代码在 Visual Studio 中工作 - how to get React native code working in visual studio 没有在 Visual Studio Code for React Native 中获取 IntelliSense - Not getting IntelliSense in Visual Studio Code for React Native Electron + React + Typescript + Visual Studio Code?调试?我可以在visual studio中调试电子反应应用程序吗? - Electron + React + Typescript + Visual Studio Code? Debug? Can I debug an electron-react app in visual studio? 无法在 Visual Studio 代码中调试 React.js 代码 - Unable to debug React.js code in visual studio code 使用 expo 字体对 expo 小吃进行原生反应,但不适用于 Visual Studio 代码 - React native with expo fonts working on expo snack but not on visual studio code 如何使用 Visual Studio 2017 创建 React 应用程序(无 Visual Studio 代码) - How to create react app with visual studio 2017 (no visual studio code) 带有 React 的 Visual Studio 代码 - Visual Studio Code with React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM