How Can We Help?
< All Topics

Integrate RKTracer with Android Studio IDE and generate code coverage for Java/Kotlin Apps

How to Integrate RKTracer plugin in Android Studio in Windows 10/Linux?

Step 1: Open Android Studio IDE.

Step 2: Go to the File menu→ Settings → Plugin on the left side of the screen and then on the right side, click the “setting” icon on the right side and select the “install plug-in from disk” option.


Step 3: Navigate to the RKTracer tool installation folder, 

Windows: “C:\rktracer\share\rktracer-plugins”

Linux: “/home/username/rktracer/share/rktracer-plugins”

Select “RKTracer-Android-Plugin.jar” and select ok, to install the RKTracer plugin for Android Studio IDE.


Step 4: Now, we need to close the android studio IDE and open it. You should see RKTracer options under the Tools menu → The RKtracer option to turn ON or OFF or generate reports. There is also a quick turn ON/OFF option with a click mark in green color, as shown in the below screenshot.

Generate Code coverage for Java-based application in android studio IDE?

Following Instructions will work for all the Apps with C/C++ or Java, or Kotlin or in combination in Android Studio IDE. Ensure that you can build and test the app in android studio or on the target device.

Step 1: Enable RKTracer Tool.

Goto → Tools→ RKTracer and select Switch Instrumentation ON.

Step 2: Rebuild the application

The RKTracer tool will instrumentation takes place at a source code level.

Step 3: Install the APK in the device and test.

By default, the RKTracer tool will autosave coverage data from the emulator or device to the app working folder in the build machine, provided the device or emulator is connected to the build machine. If the device/phone is not connected to the build machine at the time of testing, RKTracer coverage data will be saved in the logcat buffer and in the testing device. You can later save coverage data from logcat log or pull coverage data from device to app folder in the build machine.

To pull the coverage data, you can execute the command. 

adb pull  /data/data/com.example.widecolor/rk-coverage.txt 

Step 4: Generate Code Coverage Reports

We can either use the Tools menu → rktracer → report option to generate a report or open a terminal or command prompt in the project directory. We have the rktracer folder and execute the following command to generate reports.

 Linux: “rkresults app/build.gradle” to generate reports. 

Windows: “rkresults app\build.gradle” to generate reports. 

If the RKTracer Html reports are not opening in the browser, we can navigate the project folder/rktracer/reports/ and open index.html to check the reports.

NOTE: Once the reports are generated, you need to Turn OFF the RKTracer tool.

Generate code coverage for selected functions/files/folder

Generate coverage reports  for the selected folders







Suppose you need code coverage for source files from three different folders, i.e., core, keys, power, and ignore coverage for folders firmware_loader and lockdown. Edit rktracer.config in the RKTracer installation folder and go to the end of the file add the following information. 

ignore *.java

instrument */power/* */core/* */keys/*

never */firmware_loader/* */lockdown/*


ignore *.java = Ignores all Java source files from instrumentation

Instrument = Instrument source files from given folders

never = ignore selected folder  


Generate coverage reports only for selected functions from three different files.

fun_X() in source-file-X 

fun_Y() in source-file-Y

fun_Z() in source-file-Z

Suppose you need code coverage for selected functions from three different files. Edit rktracer.config in the RKTracer installation folder and go to the end of the file and set the following variables as shown below.  

ignore *.java

instrument * * *

function-ignore *

function-instrument fun_X() fun_Y() fun_Z()


ignore *.java = Ignore all Java programming source files

instrument *  *  *  = Instrument only these three source files.

function-ignore * = Then ignore all functions in the above three files.

function-instrument fun_X() fun_Y() fun_Z() = But instrument or don’t ignore these three functions from these three files.

Previous Code Coverage for Java Projects in NetBeans IDE
Next Code Coverage for Maven Java Projects
Table of Contents