Skip to content
Víctor García edited this page Jul 15, 2024 · 3 revisions

Debugging

The DHIS2 Android SDK is a library developed using Android Studio, so it is possible to use the tools provided by Android Studio for debugging (App inspection). These tools are really powerful and are integrated in the IDE, but they can be a bit heavy and slow in some scenarios.

Also, the App inspection tool requires a debuggeable running process to work properly, which might be a bit tricky due to the nature of a library project: the library doesn't run by itself, it only runs through test classes that have a very short lifetime (usually not enough to attach the App inspection tool and inspect the content). In practice, this limitation force us to execute the tests in debug mode, which is much heavier and slower that regular executions.

There are other lightweight tools for debugging that are worth considering in some cases.

HTTP requests

Android studio

The integrated network inspector works really well and is improved in each version. It might feel a bit slow in some cases.

HTTP Toolkit

A ligthweight tool that attaches to a running device (not a running process) and logs all the network requests. It is quick and straightforward.

Steps to use it:

  1. Download it from https://httptoolkit.com/.
  2. Start an Android device (emulator).
  3. Start HTTP Toolkit.
  4. Go to the "Intercept" tab and click on "Android device via ADB". Accept the connection on the Android device.
  5. The tab "View" will show all the newtork requests.

Limitation: it works well in emulators built with Google API images and root physical devices. For other devices, it requires the installation of some certificates to establish the connection. It is doable but not straightforward.

It is possible to mock certain network requests as well.

Database

Android studio

The integrated database viewer in the App inspection works really well. It shows the whole list of tables and the structure of each table as well.

Command line

Using adb, it is possible to access the Android device and use sqlite3 to run sqlite commands.

Limitation: it only works in emulators built with Google API images and root physical devices.

Steps:

  1. Start and Android device (emulator).
  2. Open a terminal and go to your Android home > platform tools folder (usually Android/Sdk/platform-tools in Linux systems).
  3. Execute adb shell to access a shell in the Android device.
  4. Execute su to promote to a superuser session.
  5. Go to the application folder, the databases are located in cd /data/data/org.hisp.dhis.android.test/databases/.
  6. Check the list of databases in the folder with ls command.

Then, there are two options to execute sql commands.

  1. Connect to the database and access the console.
emu64xa:/data/data/org.hisp.dhis.android.test/databases # sqlite3 play-dhis2-org-41_android_unencrypted.db -header -column                                                                                        
SQLite version 3.39.2 2022-07-21 15:24:47
Enter ".help" for usage hints.
sqlite> select * from constant;
_id  uid          code  name                         displayName                  created                  lastUpdated              value
---  -----------  ----  ---------------------------  ---------------------------  -----------------------  -----------------------  -----
1    Gfd3ppDfq8E        Commodity ordering overhead  Commodity ordering overhead  2014-03-02T04:07:54.855  2014-03-02T04:13:40.906  5.0  
2    bCqvfPR02Im        Pi                           Pi                           2013-03-11T17:39:33.083  2013-03-11T17:39:33.083  3.14 
sqlite> 

  1. Execute the command directly. This method allows the access of command history by pressin the "up" arrow in the keyboard, which is very handy when repeating the same command once and again.
emu64xa:/data/data/org.hisp.dhis.android.test/databases # sqlite3 play-dhis2-org-41_android_unencrypted.db -header -column "select * from constant"                                                             
_id  uid          code  name                         displayName                  created                  lastUpdated              value
---  -----------  ----  ---------------------------  ---------------------------  -----------------------  -----------------------  -----
1    Gfd3ppDfq8E        Commodity ordering overhead  Commodity ordering overhead  2014-03-02T04:07:54.855  2014-03-02T04:13:40.906  5.0  
2    bCqvfPR02Im        Pi                           Pi                           2013-03-11T17:39:33.083  2013-03-11T17:39:33.083  3.14 

File system

Android studio

Go to "View" > "Tool windows" > "Device explorer" and access the route "/data/data/org.hisp.dhis.android.test".

Command line

Using adb, it is possible to access the Android device file system.

Limitation: it only works in emulators built with Google API images and root physical devices.

Steps:

  1. Start and Android device (emulator).
  2. Open a terminal and go to your Android home > platform tools folder (usually Android/Sdk/platform-tools in Linux systems).
  3. Execute adb shell to access a shell in the Android device.
  4. Execute su to promote to a superuser session.
  5. Go to the application folder cd /data/data/org.hisp.dhis.android.test.