简体   繁体   中英

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. I'm using the sample from the Flutter documentation ( https://flutter.dev/docs/development/platform-integration/platform-channels ). I've tried the following:

  1. Open the Flutter project in IntelliJ
  2. Right click the android folder and select Flutter | Open Android Module in Android Studio
  3. Android Studio opens the native Android code.
  4. Set breakpoints in Android code
  5. Click Debug from 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''
  7. Run Flutter App from IntelliJ (I've also tried Debug from IntelliJ - flutter code will stop on breakpoints)
  8. The breakpoints fro the native Android code never breaks

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

To debug the native android code, right click on the android folder and select Flutter | Open Android Module in Android Studio. Start the debugger there. The Flutter app will open in the emulator and you can set/hit breakpoints in the native code

Flutter has a problem with debugging if you use relative paths. 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.

What worked for me was running the app in debug mode in Android Studio and then pressing the "Attach Debugger to Android Process" button.

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