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.
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.
- Open Android Studio, then open the
Filemenu, chooseSettings, thenPlugins. Click the settings icon and select Install plugin from disk. - Navigate to the
rktracer-pluginsfolder inside your RKTracer installation, selectRKTracer-Android-Plugin.jar, and confirm the installation. - Restart the Android Studio IDE.
The rktracer-plugins folder is inside the RKTracer installation folder:
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:
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:
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:
rkresults
Enable coverage for selected files
You can scope coverage to specific files and functions by editing rktracer.config:
ignore *.c instrument */power/* */core/* */keys/* never */firmware_loader/* */lockdown/* function-ignore * function-instrument fun_X() fun_Y() fun_Z()