简体   繁体   English

Flutter - 如何调试原生android代码

[英]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.我一直在尝试调试在flutter中通过平台通道调用的原生android代码,调试只在flutter端。 The execution doesn't hit the breakpoint in the native android.执行不会在原生 android 中遇到断点。 The application is working as expected but the debugging doesn't.应用程序按预期工作,但调试没有。 I am using Android studio.我正在使用 Android 工作室。 Can some one please tell me how to debug the native android code ?有人可以告诉我如何调试本机 android 代码吗?

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.如果您导航到 android studio 中的 MainActivity.kt 或 MainActivity.java,那么您可以在右上角看到“在 Android Studio 中打开以进行编辑”。 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.好吧,如果您可以在新的 android 项目中编写完整代码并在那里进行测试,然后使用该代码制作 flutter 插件,那就更好了。 I think this will be faster than to edit in flutter project.我认为这比在 flutter 项目中编辑要快。

let me know what others think.让我知道其他人的想法。

The answer given by @Marcos Boaventura to follow this blog helped fix the issue. @Marcos Boaventura 在关注此博客时给出的答案有助于解决此问题。 https://medium.com/flutterpub/flutter-app-couldnt-find-libflutter-so-c95ad81cbccd https://medium.com/flutterpub/flutter-app-couldnt-find-libflutter-so-c95ad81cbccd

After fixing the gradle the debug is successful.修复gradle后,调试成功。 Thank you @Marcos Boaventura谢谢@Marcos Boaventura

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).在模拟器上调试本机代码有效,而在物理设备(Zebra TC25、Android 7.1)上调试时因致命信号 11 (SIGSEGV) 崩溃。 Switching from the Flutter beta channel to the Flutter stable channel fixed it for me.从 Flutter beta 通道切换到 Flutter 稳定通道为我修复了它。

Breakpoints are working fine for me when using Android Studio at project/android/ , on both emulator and physical device.在模拟器和物理设备上在project/android/上使用 Android Studio 时,断点对我来说工作正常。 And remember to Debug instead of Run (^D instead of ^R).并记住要调试而不是运行(^D 而不是 ^R)。 Note, it did not work when opening the project from project/ .请注意,它并没有从打开项目时,工作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).我不认为创建一个新的 android 项目来为 flutter 应用程序编写本机代码是一个不错的选择(vivek 的建议)。 There are many Flutter specific considerations you need to make on the native side, it is not just an Android app.您需要在本机端考虑许多 Flutter 特定的注意事项,它不仅仅是一个 Android 应用程序。

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

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