简体   繁体   中英

How to debug NativeScript java code in Android Studio?

I'm quite new to NativeScript. Currently, one of my projects is using NativeScript to develop cross-platform app. It has a 3rd-party lib which is written in 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. 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. At least print out java native error or cat log.
  • How can I debug native code in 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. 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.

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. Node required for NativeScript to run. 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:

  • After you've done that you need to change the <app_name>/platforms/android/build.gradle file as described here
  • The above change will enable you to open <app_name>/platforms/android in Android Studio
  • Run <app_name>:clean task from gradle 在此处输入图片说明
  • Run the task default for Android Studio, that will prompt you for emulator or device on which to run: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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