Product
Solutions
Resources
Company
Download Trial Book a Demo

Code Coverage for Android Apps in Android Studio IDE

Generate code coverage for an Android app in the Android Studio IDE with RKTracer. Install the RKTracer Android plugin, enable the coverage tool from the Tools menu, rebuild and run your tests on a device or emulator, then produce an HTML report.

Use this guide to generate code coverage for an Android app through the Android Studio IDE. RKTracer integrates with Android Studio using a plugin, so you can enable the coverage tool, rebuild and run your tests, and generate the report from the Tools menu. The same actions are also available from the command line.

In short

Install the RKTracer-Android-Plugin.jar plugin in Android Studio, turn coverage on from Tools then RKTracer ON, rebuild and run your tests, then generate the HTML report with Tools then rktracer then report (or run rkresults).

Install the RKTracer Android plugin

RKTracer integrates with the Android Studio IDE through a plugin. Install the plugin from disk, then restart Android Studio.

  1. Open Android Studio, then open the File menu, choose Settings, then Plugins. Click the settings icon and select Install plugin from disk.
  2. Navigate to the rktracer-plugins folder inside your RKTracer installation, select RKTracer-Android-Plugin.jar, and confirm the installation.
  3. Restart the Android Studio IDE.

The rktracer-plugins folder is inside the RKTracer installation folder:

plugin location
Windows: C:\rktracer\share\rktracer-plugins
Linux:   /home/username/rktracer/share/rktracer-plugins

After the restart, open the Tools menu to find the RKTracer options. From here you can enable or disable the coverage tool and generate reports.

Enable the RKTracer tool

To enable the coverage tool, go to Tools then RKTracer ON.

You can also enable the tool from the command line. Run rktracer gradle on the build.gradle file, then clean and build with Gradle:

enable from the command line
rktracer gradle -on app/build.gradle
gradlew clean
gradlew build

Rebuild the application and run your tests

Rebuild the application, then install the APK on a device or emulator and run your tests. As the instrumented application runs, RKTracer captures the coverage data.

Capture the coverage data from the device using adb logcat and pull the coverage data file from the device:

capture coverage data
adb logcat -c
adb logcat > rk-coverage.txt 2<&1
adb pull /data/data/com.example.widecolor/rk-coverage.txt

Generate the code coverage reports

To generate the HTML reports, go to Tools then rktracer then report. You can also generate the reports from the command line by running rkresults:

generate the report
rkresults

Enable coverage for selected files

You can scope coverage to specific files and functions by editing rktracer.config:

rktracer.config
ignore *.c
instrument */power/* */core/* */keys/*
never */firmware_loader/* */lockdown/*
function-ignore *
function-instrument fun_X() fun_Y() fun_Z()

Stuck on your build?

Open a support ticket and an engineer who knows your toolchain will help. You get a tracked ticket ID by email.