4

I'm working on a Ionic Application and there are a few bugs on Custom Java Plugin imported to the app.

I'm not a Java developer but I wish to understand what happen in those plugins while I run the Ionic Application.

Looking on Google I found a few things like adb logcat that is something terrible and impossible to read.

I tried creating a few messages in the Java Plugin in this way:

Log.d("MyMessage", "Something is happening");

And using grep in the adb logcat to see only my messages but unfortunately it is not enough even because I can not pass a variable as message... so I don't exactly know what is going on in the Plugin while using the app.

I know about JDB but I don't know how to run it together with the Ionic App.

Basically I just wish to create breakpoints or to print dynamic variables while the Plugin is executed to understand where are bugs but I can not find anything useful.

I'm a Javascript developer and I have several tools to debug my Front-End stuff so I think it is quite weird it doesn't exist a way to debug much more complex, back-end, code...

I hope you can help me to do that.

Ayeye Brazo
  • 3,316
  • 7
  • 34
  • 67

1 Answers1

3

For those still looking for a solution:

You can debug java plugins with Android studio and an Android emulator.

Step 1: Install Android studio and SDK tools.

Step 2: Get a virtual device running. In order to use the emulator you need to have the Intel x86 emulator accelerator installed. I personally had issues here, I had to disable Hyper-V before it would run. This and other solutions can be found here: The intel x86 emulator accelerator (HAXM installer) revision 6.0.5 is showing not compatible with windows.

Step 3: Do a build for Android in your Ionic project (if you haven't already done so)

Step 4: Navigate to File > New > Import Project and then navigate to your Ionic project. Don't import the entire project, just the Android folder ( {ProjectName} > platforms > android) *WARNING: Don't update the gradle if you are presented with the option to do so. This may break the ability to build Android from within the Ionic folder. *

Not updating the gradle may result in a "Gradle project sync failed" error. In my case the solution was to run File -> Invalidate caches / Restart

And that's pretty much it. Once the project is loaded you can use the project tab to navigate to the plugin you want to debug, place breakpoints where you want them, and run debug.