Here's my situation:
Background
- I am investigating code-coverage for our Android app. The app is built with Gradle and Android Studio.
- I need code-coverage reports in two situations: during manual tests, and during automated tests built with our sizeable Appium suite.
- I need to get a proof-of-concept out fast (isn't that always the case?) so I haven't had the chance to do thorough R&D. So please forgive any ignorance I display :)
- I have access to the app source, but have little knowledge of the moving parts.
- I have investigated JaCoCo and Emma. This question pertains to JaCoCo.
- Given that we need coverage for Appium and manual tests, I believe offline-instrumentation with JaCoCo is what I need.
Progress Made
- I used the JaCoCo plugin page and the Android Tools page and could configure build.gradle properly.
- I have verified that the classes (present in
build\intermediates\classes
) are instrumented with JaCoCo, and are packaged in the APK. - I wrote a BroadCastReceiver per this SO discussion, which will receive the "end coverage" broadcast.
Problem
When I run the app manually, I keep seeing errors in the logcat W/System.err: java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)
From this SO question and the JaCoCo docs I understand that Jacoco needs to know where to store the jacoco.exec
file - and that I need to package a jacoco-agent.properties (containing a destfile
property) with the APK.
I have tried putting jacoco-agent.properties in assets
- it was packaged into the APK properly, but did not seem to have any effect (i.e Jacoco failed as usual)
I tried putting it inside res
- it did not get packaged into the APK.
I tried res/raw
and hit the error about a dash in the filename, as in this SO question.
I am at my wit's end, and would really appreciate help. How do I package jacoco-agent.properties using my Gradle build into the APK, so that JaCoCo will read it?
Related Questions
this SO question, has an answer from 2013, and it's for Ant, not Gradle.