如何调试本机代码? [英] How debug nativescript code?

查看:183
本文介绍了如何调试本机代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是从nativescript开始,所以请介意这是否只是一个简单的问题.

I am just starting out with nativescript so please mind if this is just a simple question.

我使用tns run android在我的手机上运行代码,但是当它启动时,它也会在控制台中启动的loggin,所以我该如何调试编写的代码让我说我有console.log我的代码中的语句,但在该日志中找不到我的语句.

I run my code on my phone with tns run android but when it starts it starts tons of loggin also in console so how can I debug the code I have written lets say I have console.log statement in my code but I can't find my statement in that heaps of logs easily.

推荐答案

您可以使用JavaScript虚拟机可用的调试器工具.您可以在NativeScript文档中找到有关它的更多信息-调试. 基本上,要使用调试器,您将需要Chrome浏览器.有几种选项可以运行它:

You can use the debugger tool, available for the JavaScript virtual machine. You can find more information about it in the NativeScript documentation - debugging. Basically to use the debugger you will need Chrome browser. There are several options to run it:

  1. 当您没有正在运行的应用程序时-您将不得不使用tns debug android --debug-brk,它将运行该应用程序并打开调试器
  2. 如果您已经使用tns run androidtns livesync android --watch运行了该应用程序(以下是有关此命令的更多信息),则您将无法在当前控制台窗口中编写任何其他命令.在这种情况下,您可以再打开一个控制台窗口,然后键入tns debug android --start
  3. 如果您希望能够在当前控制台中键入其他命令,则可以使用tns run android --justlaunch,然后您可以在同一控制台窗口中键入tns debug android --start.
  1. When you don't have a running application - you will have to use tns debug android --debug-brk and it will run the application and open the debugger
  2. If you already have run the application with tns run android or tns livesync android --watch (bellow there is more information about this command), you will not be able to write any other command in the current console window. In that case you can open one more console window and you type tns debug android --start
  3. If you would like to be able to type other commands in the current console, you can use tns run android --justlaunchand after that you will be able to type in the same console window tns debug android --start.

如果您希望将所有console.log()语句打印在一个地方,则可以使用 Android设备监视器.要运行它,请在控制台中写入monitor,它将出现.在那里,您可以为console.log()-s创建一个新的过滤器.在按下绿色加号图标后将出现的对话框中,在按日志标签字段中,您必须编写 JS .然后,在运行您的应用程序后,您可以按名称,将名称赋予该过滤器,然后您将看到应用程序中的所有console.log()语句. 为了使用监视器,更方便的是使用命令tns livesync android --watch.通过使用它,可以在保存所做的更改后使您的应用程序自动运行.还请记住,有时监视器只是断开连接,您将不得不再次运行它.

If you would like to have all of your console.log() statements printed on one place, you can use Android Device Monitor. To run it write monitor in you console and it will appear. There you can create a new filter for your console.log()-s. In the dialog box, which will appear after pressing the green plus icon, in the field by Log Tag you have to write JS. Then after running your application you can press on the name, you gave to that filter, and you will see all of the console.log() statements from you app. What would be more convenient in order to use the monitor, is to use the command tns livesync android --watch. By using it you will have your application automatically run after you save the changes you have made. Keep also in mind that sometimes the monitor simply disconnects and you will have to run it again.

这篇关于如何调试本机代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆