首页 文章

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

提问于
浏览
1

我'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记录有关本机代码的有 Value 信息 .
console log capture

相反,我将项目导入Android Studio,它位于platform / android文件夹下 . 但是当我点击“运行”按钮时它会记录错误 .

see capture

我想知道:

  • 是否可以直接使用VS Code调试本机代码 . 至少打印出java本机错误或cat日志 .

  • 如何在Android Studio中调试本机代码?如何解决我遇到的问题?

如果有人能回答我的问题,我将非常感激 . 谢谢!

1 回答

  • 1

    首先我要说的是没有与Android Studio正式集成 . 我所能提供的只是一种可行的解决方法 .

    注意:下面提供的步骤使用NativeScript CLI 3.1.1进行测试,并且可能也适用于3.2.0 .

    第一个问题是您没有在全局路径中设置"node",所以首先,您需要将其添加到PATH . NativeScript运行所需的节点 . 你可以看看如何设置here

    如果您希望能够使用Android Studio运行项目,可以按照以下步骤操作:

    • 完成后,您需要更改 <app_name>/platforms/android/build.gradle 文件here

    • 以上更改将使您能够在Android Studio中打开 <app_name>/platforms/android

    • 从gradle运行 <app_name>:clean 任务
      enter image description here

    • 运行Android Studio的任务默认值,它将提示您运行模拟器或设备:
      enter image description here

相关问题