简体   繁体   English

如何在Android Studio中调试NativeScript Java代码?

[英]How to debug NativeScript java code in Android Studio?

I'm quite new to NativeScript. 我对NativeScript很陌生。 Currently, one of my projects is using NativeScript to develop cross-platform app. 目前,我的一个项目是使用NativeScript开发跨平台应用程序。 It has a 3rd-party lib which is written in java. 它有一个用Java编写的第三方库。 But the result is not as good as I expected. 但是结果并不像我预期的那样好。 I was struggling to find the problem since the console didn't log valuable info regarding to native code. 由于控制台未记录有关本机代码的宝贵信息,因此我一直在努力寻找问题。 控制台日志捕获

Instead, I import the project to Android Studio which is under the folder of platform/android. 相反,我将项目导入到位于platform / android文件夹下的Android Studio中。 But it logs error when I hit the "run" button. 但是当我按下“运行”按钮时,它会记录错误。

见捕获

I want to know: 我想知道:

  • Is it possible to debug native code directly with VS Code. 是否可以直接使用VS Code调试本机代码。 At least print out java native error or cat log. 至少打印出Java本机错误或cat日志。
  • How can I debug native code in Android Studio? 如何在Android Studio中调试本机代码? How to solve the problem I ran into? 如何解决我遇到的问题?

I'd be very appreciated, if anyone can answer my questions. 如果有人可以回答我的问题,我将不胜感激。 Thanks! 谢谢!

Let me start off by saying there's no official integration with Android Studio. 首先,我说没有与Android Studio的官方集成。 All I can provide is a workaround that will make it possible. 我所能提供的是一个变通办法,它将使其成为可能。

Note: The steps provided below are tested with NativeScript CLI 3.1.1 and will probably work also with 3.2.0. 注意:以下提供的步骤已通过NativeScript CLI 3.1.1进行了测试,并且可能也可以在3.2.0下使用。

The first problem is you don't have "node" set in your global path so first of all, you need to add it to PATH. 第一个问题是在全局路径中没有设置“节点”,因此首先需要将其添加到PATH。 Node required for NativeScript to run. 运行NativeScript所需的节点。 You can look at how to set it up here 您可以在这里查看如何设置

If you want to be able to run the project with Android Studio you can follow these steps: 如果您希望能够使用Android Studio运行该项目,则可以按照以下步骤操作:

  • After you've done that you need to change the <app_name>/platforms/android/build.gradle file as described here 当你这样做,你需要更改<app_name>/platforms/android/build.gradle文件描述这里
  • The above change will enable you to open <app_name>/platforms/android in Android Studio 通过以上更改,您可以在Android Studio中打开<app_name>/platforms/android
  • Run <app_name>:clean task from gradle 从gradle运行<app_name>:clean任务 在此处输入图片说明
  • Run the task default for Android Studio, that will prompt you for emulator or device on which to run: 运行默认的Android Studio任务,该任务将提示您输入要在其上运行的模拟器或设备: 在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM