10

I'm wonder how to debug flutter iOS code in a plugin? I can open the example app that's generated whenever you create a plugin but I see the plugin code as binary framework, therefore I can't debug it.

For android it's fairly easy, I just open the android folder in A.S. and the plugin + the example are there, I just add run configs and I start debugging right away.

But I really hope to find a similar way for iOS.

Shehabic
  • 6,787
  • 9
  • 52
  • 93

3 Answers3

14

Plugins are added to the ios app as pod projects so it is similar to debugging any code in pod project.

  1. Open Runner project workspace
  2. Browse the file in the Pods project
  3. Put Breakpoint

NB: Need to run app from flutter first to work this properly

enter image description here

Eldhose
  • 726
  • 8
  • 19
  • I am not able to see my plugin in Pods/Development Pods. I tried running the app on iOS first and then opened xcode but I am not able to see my plugin there. – Shrijan Regmi Jun 02 '23 at 13:23
  • Is the plugin in Development pod folder? else make sure the name is correct. In some case they may have used different library manager – Eldhose Jun 04 '23 at 15:36
5

To set a breakpoint and debug Flutter plugin code from Xcode, try the following:

  1. Open ios/Runner.xcworkspace for the Flutter application you want to debug.
  2. From the Debug menu, select Breakpoints > Create symbolic breakpoint...
  3. In the Symbol field, enter the method you want to break on. For example, to break on the default entrypoint for the plugin defined in the HelloPlugin class, set the symbol to -[HelloPlugin handleMethodCall:result:].
  4. Run your app from Xcode via Product > Run.

From that point, trigger the plugin code through whichever UI actions will hit the code in question.

cbracken
  • 3,610
  • 2
  • 21
  • 20
  • flutter plugin should have 'example' subdir and use that application's `ios/Runner.xcworkspace` to run - also that application could have all basic functions of the plugin on a screen. – Magillus Nov 27 '18 at 18:51
1

Make sure to build the example app first using cd hello/example; flutter build ios --no-codesign, then open it in Xcode.

You can find files for the iOS part deep in the project hierarchy: Pods > Development Pods > name_of_your_plugin > ... > Classes

You can put breakpoints in the Xcode as you would normally do, and then you can run the example app straight from the Xcode.

Reference from the Flutter team.

DamjanDabo
  • 97
  • 3
  • I am not able to see my plugin in Pods/Development Pods. I tried running the app on iOS first and then opened xcode but I am not able to see my plugin there. – Shrijan Regmi Jun 02 '23 at 13:23