Ten Top Tips For Debugging Apps In Delphi XE7 Firemonkey On Android And IOS

Delphi XE7 Firemonkey Debugging Tips And TricksIf you are using Delphi XE7 or Appmethod with Firemonkey for mobile development on Android and IOS it can be tricky to debug directly on the devices. Here are some tips and tricks to help you debug your Firemonkey mobile apps quickly. Also remember that your projects have multiple layers of debug settings. There is the Debug Build Configuration and the Target Platform Debug Configuration. You can Run your projects with and without debugging. Run (with debugging) combined with the Debug Build Configuration is what allows you to set and hit breakpoints within your code. And now for the tips and tricks:

#1. Build And Debug Your App In Win32

The fastest way to develop and debug your mobile apps is by using the Win32 target. Get your app working and solid on Win32 and occasionally deploy and test on Android and IOS when you think it is already solid. Use conditional compilation like {$IFDEF ANDROID}, {$IFDEF IOS}, and {$IFDEF MSWINDOWS} to use platform specific units and code. Only platform specific sensors or things like video playback require testing on the actual platform. Threads can also be tricky on mobile devices.

#2. Output Debug Data To The Mobile Platform Logs

Both Android and IOS have platform logs which you can write to and view while your app is running. The Android function is called AndroidApi.Log.LOGI() and you can view it’s output in Eclipse or in a LogViewer. The IOS function is called NSLog and you can view it’s output in the Iphone Configuration Utility console.

#3. Debug Your REST HTTP Requests Using A Transparent Proxy

There is a tool called Fiddler which acts as a proxy on your machine and gives you full request and response information about HTTP requests that pass through it. You can run your TRESTClient and TidHTTP requests through Fiddler and greatly simplify debugging REST services for Delphi.

#4. Access And Modify Your App Directory On IOS In Real Time

If you are deploying files with your IOS app or saving files for use by your app in it’s GetDocumentsPath directory it can make it much easier when you can browse your app directly just like a Windows folder. There is a utility called iFunBox which allows you to connect to your IOS device and browse into the app directory where you files are stored. You can copy files in and out of the directly and your Firemonkey app can see and use the files without having to redeploy your whole app.

#5. Skip The Android Emulator And The IOS Simulator If Possible

Unless you really have no device Android and IOS devices it is just too slow to use either the Android emulator from Google or the IOS Simulator from Apple. In the case of the Android emulator it is too slow to be effective and while there are emulators out there from other vendors you can push your app to an actual device just as quickly when you need to test platform specific features. In the case of the IOS Simulator it isn’t much different from running in Win32 mode (and Win32 mode is faster) because they both run in X86 (and not ARM). It can emulate some device sensors which is nice but for every day usage Win32 is easier. If you use any static libraries in your IOS apps the libraries will also have to support X86 for the simulator to be able to use them.

#6. Use Profilers To Find Memory Leaks And Tune Code

Delphi XE7 Firemonkey apps get compiled to Xcode so the Xcode Instruments tool works to profile your apps for memory leaks. You deploy your app in debug mode to your IOS device through the Delphi Platform Assistant (PAServer) and then use Xcode Instruments to check for memory leaks etc. For Win32 and Android platforms there are all kinds of profile and memory leak tools with a long history for Delphi like ProDelphi, AQTime, and Nexus Quality Suite.

#7. Wirelessly Debug Your Android Apps From Delphi XE7 Firemonkey

Being stuck holding your device close to your machine so that it can stay connected via a USB cable isn’t very useful in some cases (especially if you are testing the accelerometer). You can set up your development environment to debug on your Android device via Wifi.

#8. Monitor And Test Your App Framerate On Android With Gamebench

Gamebench is an app for Android that does not require your device to be rooted and will report the framerate of your app to you. It uses a companion application on your desktop in addition to an app on your device. Once the data is collected you can view the log of the data and it shows you the FPS, the CPU usage, the memory usage, and the GPU usage. It has a graph over time of the CPU and GPU usage. Additionally it has a graph of the FPS over time.

#9. Debug REST And BaaS Using LiveBindings At Design Time

You can use LiveBindings to read and display JSON data from the BaaS (Back End As A Service) components at design time in your app. This can allow you to rapidly build and debug your app without even compiling as your data is displayed at design time. There is also a custom DataSetProfile which provides the same type of design time debugging with LiveBindings functionality for your REST services.

#10. Increase Your Productivity And Reduce The Need For Debugging With IDE Add Ons

There is a round up of 9 different IDE add ons for Delphi XE7 that can reduce mistakes in your code, make you more productive, and make the IDE easier to use. These include GExperts, Castalia, Delphi Dev. Shell Tools, IDE Fix Pack, ModelMaker, CnPack, Continua CI, Delphi IDE Theme Editor, and Delphi Package Installer. You can use these IDE add ons to help you stop bugs before they happen, provide a more stable development environment, and write better code.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

7 Responses to Ten Top Tips For Debugging Apps In Delphi XE7 Firemonkey On Android And IOS

  1. tom says:

    I am trying to follow your suggestion on #6. Use Profilers To Find Memory Leaks And Tune Code.
    The problem is I cannot find a method for testing memory leaks on Android. I contacted AQtime and Nexus and they both say their products do not do that. Any suggestions or specific examples?

    • Admin says:

      {$IFDEF DEBUG}
      ReportMemoryLeaksOnShutdown := True;

      • tom says:

        Thank you. I’m aware of this command and use it. I cannot find any explicit details on how to use it.
        Where are the results displayed / stored?

        I run an app on an Android device and there are no messages displayed. Same thing when I run it through the ide. If the app is saving it to a log I don’t know where it is. Many google and forum searches has yet to yield me detailed instructions on how to use that feature. Any links are articles would be greatly appreciated.

  2. tom says:

    I just found this from Marco Cantu’s publication http://www.interface.ru/iarticle/files/36514_62108093.pdf

    “Given how memory management works under the Delphi ARM compiler for iOS, it is worth
    considering some of the options you have in making sure everything is under control. Before we
    proceed,it is important to notice that on non-Windows platforms Delphi doesn’t use the FastMM memory manager, so setting the ReportMemoryLeaksOnShutdown global flag to check for memory leaks when the program closes is useless. On the OS X and iOS platforms, in fact, Delphi called directly the malloc and free functions of the native libc library”

    I guess there is no way to check for memory leaks on Android devices.

  3. Pingback: Ten Tips For Building Professional Multi Platform Enterprise Apps With Delphi XE8 Firemonkey | Delphi XE5 XE6 XE7 XE8 Firemonkey, Delphi Android, Delphi IOS

  4. Pingback: Ten Tips For Building Professional Multi Platform Enterprise Apps With Firemonkey | Firemonkey eXplore

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Leverage Feature Rich FireDataGrid Control In Your Delphi XE7 Firemonkey On Windows And Mac OSX

The software house Developer Machines has a nice data aware component called FireDataGrid for Delphi XE6 (and probably XE7) Firemonkey....