简体   繁体   English

如何调试从 Flutter 平台通道调用的本机 Android

[英]How to debug native Android invoked from Flutter Pllatform Channel

I can't seem to figure out how to make debugging work for a native Android module invoked from a Flutter app via a Platform Channel.我似乎无法弄清楚如何对通过平台通道从 Flutter 应用程序调用的本机 Android 模块进行调试。 I'm using the sample from the Flutter documentation ( https://flutter.dev/docs/development/platform-integration/platform-channels ).我正在使用 Flutter 文档( https://flutter.dev/docs/development/platform-integration/platform-channels )中的示例。 I've tried the following:我尝试了以下方法:

  1. Open the Flutter project in IntelliJ在 IntelliJ 中打开 Flutter 项目
  2. Right click the android folder and select Flutter |右键单击 android 文件夹和 select Flutter | Open Android Module in Android Studio在 Android Studio 中打开 Android 模块
  3. Android Studio opens the native Android code. Android Studio 打开原生 Android 代码。
  4. Set breakpoints in Android code在 Android 代码中设置断点
  5. Click Debug from Android Studio从 Android Studio 单击调试
  6. Emulator shows "Waiting for Debugger Application is waiting for deubgger to attach" while in Android Studio the debug console shows 'Connected to the target VM, address: 'localhost:8601''模拟器显示“等待调试器应用程序正在等待调试器附加”,而在 Android Studio 中,调试控制台显示“已连接到目标 VM,地址:'localhost:8601''
  7. Run Flutter App from IntelliJ (I've also tried Debug from IntelliJ - flutter code will stop on breakpoints)从 IntelliJ 运行 Flutter 应用程序(我也尝试过从 IntelliJ 调试 - flutter 代码将在断点处停止)
  8. The breakpoints fro the native Android code never breaks本机 Android 代码的断点永不中断

What am I doing wrong?我究竟做错了什么?

I started another project and was able to get it working.我开始了另一个项目并且能够让它工作。

To debug the Flutter code, start the debugger from IntelliJ要调试 Flutter 代码,请从 IntelliJ 启动调试器

To debug the native android code, right click on the android folder and select Flutter |要调试原生 android 代码,请右键单击 android 文件夹和 select ZC047B10EEE7631CC26164E07ZCF Open Android Module in Android Studio.在 Android Studio 中打开 Android 模块。 Start the debugger there.在那里启动调试器。 The Flutter app will open in the emulator and you can set/hit breakpoints in the native code Flutter 应用程序将在模拟器中打开,您可以在本机代码中设置/命中断点

Flutter has a problem with debugging if you use relative paths. Flutter如果使用相对路径调试有问题。 For example, if your import statements look like the following, debugging won't work例如,如果您的导入语句如下所示,则调试将不起作用

import '../app.dart';

Change these statements to将这些语句更改为

import 'package:your_package/app.dart';

The debugger will begin to work after that.之后调试器将开始工作。 It's a good habit in flutter to import the statements in this manner.在 flutter 中以这种方式导入语句是一个好习惯。

What worked for me was running the app in debug mode in Android Studio and then pressing the "Attach Debugger to Android Process" button.对我有用的是在 Android Studio 中以调试模式运行应用程序,然后按下“将调试器附加到 Android 进程”按钮。

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

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