My android application uses the following config:
Contents of build.gradle file
buildscript {
repositories {
Jacoco coverage support has been added to the gradle plugin since 0.10.0. See http://tools.android.com/tech-docs/new-build-system.
Not quite sure I understand why you have such a complex gradle file.
You need to compile against Java 1.5 version.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
targetCompatibility JavaVersion.VERSION_1_5
}
https://code.google.com/p/android/issues/detail?id=69174
This issue has been fixed in build tools version 21+
android {
buildToolsVersion "21.1.2"
compileSdkVersion 19
...
}
Upgrade build tools to 21+ to retain Java 1.7 compatibility.
The following link was very useful in explaining the problem I encountered: http://www.androidpuzzles.com/168_17620080/
I subsequently switched the source and target compatibility settings to Java 1.5 and I was able to run the unit and UI tests (which used both mockito and espresso) and generate code coverage report using Jacoco.
If I had to retain Java 1.7 settings, the workaround would have been to change the scope of private methods in the class being tested to either protected or public scope. This would have then allowed me to generate the code coverage report (overcoming the issue as identified in the link included).