Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - how to debug the native android code

I have been trying to debug the native android code that is invoked through platform channel in flutter and the debugging is only in the flutter side. The execution doesn't hit the breakpoint in the native android. The application is working as expected but the debugging doesn't. I am using Android studio. Can some one please tell me how to debug the native android code ?

like image 936
Shruthi Avatar asked Mar 04 '19 15:03

Shruthi


People also ask

How do I debug a Flutter App in Android?

Well if you're using android studio IDE you can open only android module of your app and then you can write and debug your code as a native android app. You can do this with a right click on your project root folder and go to Flutter > Open android module in android studio option.

Can I load Android native code in a flutter plugin or app?

This feature is not yet supported for web plugins. Before your library or program can use the FFI library to bind to native code, you must ensure that the native code is loaded and its symbols are visible to Dart. This page focuses on compiling, packaging, and loading Android native code within a Flutter plugin or app.

How to add native debug symbols in flutter?

If you run the flutter build appbundle command to build your project then native debug symbols are bundled with the resulting app. You don't have to do anything, native debug symbols are in this bundle.

Is it possible to debug a native crash report in flutter?

Flutter creates native libraries (.so) to handle the rendering - and currently, the debug symbols are not included in the bundle/APK that the flutter build system generates. I am just now trying to debug a native crash report for a Android app but am unable as the symbols are missing.


3 Answers

Breakpoints are working fine for me when using Android Studio at project/android/, on both emulator and physical device. And remember to Debug instead of Run (^D instead of ^R). Note, it did not work when opening the project from project/.


I don't think making a new android project to write the Native code for a flutter app is a good option (vivek's suggestion). There are many Flutter specific considerations you need to make on the native side, it is not just an Android app.

like image 83
Ben Butterworth Avatar answered Oct 25 '22 01:10

Ben Butterworth


If you navigate to MainActivity.kt or MainActivity.java in the android studio then you can see "Open for Editing in Android Studio" on the top right. click on that and it will open you a new window where you can easily write native code.

Well, better if you can write whole code in a new android project and test there then use that code to make flutter plugin. I think this will be faster than to edit in flutter project.

let me know what others think.

like image 31
vivek yadav Avatar answered Oct 25 '22 01:10

vivek yadav


I had a similar problem. Debugging native code on an emulator worked, while debugging on a physical device (Zebra TC25, Android 7.1) crashed with a Fatal signal 11 (SIGSEGV). Switching from the Flutter beta channel to the Flutter stable channel fixed it for me.

like image 40
Sander Roest Avatar answered Oct 25 '22 03:10

Sander Roest