简体   繁体   English

如何在 Android 设备/仿真器上 LiveReload 和调试离子/电容器应用程序

[英]How to LiveReload and debug Ionic/Capacitor application on Android device/emulator

I'm new to Ionic and want to debug the Ionic app that's running on Android device (and emulator).我是 Ionic 的新手,想调试在 Android 设备(和模拟器)上运行的 Ionic 应用程序。
I've followed the official documentation for debugging and livereload , but still the breakpoint is never hit on VS Code from Android devices.我已经按照官方文档进行了调试livereload ,但是在 Android 设备的 VS Code 上仍然没有遇到断点。
Also I've played a lot with sourceMapPathOverrides but no result.我也玩了很多sourceMapPathOverrides但没有结果。

Can we somehow debug the Ionic/Capacitor app that's running on Android device using VS Code (no Chrome pls) and with LiveReload support?我们可以使用 VS Code(无 Chrome pls)并支持 LiveReload 以某种方式调试在 Android 设备上运行的 Ionic/Capacitor 应用程序吗?

PS I know the question is a bit general, but this is a question that many beginners (like me) face and a few-hours-googling doesn't provide an all in one solution guide of how to do that, especially if you're on Capacitor. PS我知道这个问题有点笼统,但这是许多初学者(像我一样)面临的问题,并且几个小时的谷歌搜索并没有提供如何做到这一点的一体化解决方案指南,特别是如果你重新上电容器。

Had to figure it out by my own...只好自己想办法了。。。

Here's the guide of how to debug the Ionic/Capacitor app that's running on Android via VS Code:以下是如何通过 VS Code 调试在 Android 上运行的 Ionic/Capacitor 应用程序的指南:

  1. Install the following plugin on VS Code: Android WebView Debug在 VS Code 上安装以下插件: Android WebView 调试
  2. Add the following entry to launch.json file in VS Code:将以下条目添加到 VS Code 中的launch.json文件中:
    {
      "type": "android-webview",
      "request": "attach",
      "name": "Attach to Android WebView",
      "webRoot": "${workspaceFolder}/*",
      "sourceMapPathOverrides": {
        "webpack:/*": "${workspaceFolder}/*"
      }
    }
  1. Now we should do reverse TCP so we could attach a debugger to the Android device.现在我们应该反向 TCP 以便我们可以将调试器附加到 Android 设备。
    Run the command prompt and get the emulator device with the following command:运行命令提示符并使用以下命令获取模拟器设备:
    adb devices list
  2. Open a reverse TCP connection using adb:使用 adb 打开反向 TCP 连接:
    adb -s [DEVICE-ID] reverse tcp:8100 tcp:8100
  3. From VS Code console run the Ionic on localhost:从 VS Code 控制台在 localhost 上运行 Ionic:
    ionic cap run android -l
    and WAIT for it to load completely并等待它完全加载
  4. Run the app from Android Studio on the desired device在所需设备上从 Android Studio 运行应用程序
  5. Run the debugger on VS code, select "Attach to Android WebView", select the device and web container在 VS 代码上运行调试器,select “附加到 Android WebView”,Z99938282F04071859941E18F16EFZCF42Z 设备和 Z21899D84 容器

Some resources that might be useful for troubleshooting:一些可能对故障排除有用的资源:
https://ionicframework.com/docs/cli/livereload https://ionicframework.com/docs/cli/livereload
https://ionicframework.com/docs/troubleshooting/debugging https://ionicframework.com/docs/troubleshooting/debugging
Ionic emulate android ERR_CONNECTION_REFUSED localhost:8100 离子模拟 android ERR_CONNECTION_REFUSED localhost:8100

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

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