As the title said, this is the problem. I have an android flavored app with modules. The app compiled using gradle in android-studio and in TeamCity server. We have custom task for creating the code coverage that look like that:
task codeCoverageReport(type: JacocoReport) {
// Gather execution data from all subprojects
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
//Build class & source dirs
def classExcludes =['**/R.class',
'**/R$*.class',
'**/BuildConfig.class',
'**/*$InjectAdapter*.class',
'**/*$ModuleAdapter*.class',
'**/*$ViewInjector*.class']
sourceDirectories = files();
classDirectories = files();
subprojects.each{
sourceDirectories += files(it.projectDir.absolutePath + '/src/main/java')
def path1 = it.buildDir.absolutePath + '/intermediates/classes/debug'
def path2 = it.buildDir.absolutePath + '/classes/main'
classDirectories += fileTree(dir: path1, excludes: classExcludes, includes: ['**/*.class'])
classDirectories += fileTree(dir: path2, excludes: classExcludes, includes: ['**/*.class'])
}
reports {
xml.enabled true
html.enabled true
html.destination "${buildDir}/reports/jacoco"
csv.enabled false
}
doFirst {
fileTree(dir: project.rootDir.absolutePath,includes: ['**/classes/**/*.class']).each {File file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
}
Now, the problem is that the code coverage created only for the modules and not for the app (main module). After some time I understood that this is because of the flavoring - the modules are not flavored, so they have only one Jacoco exec file, but the app (main module) is flavored and so Jacoco create many exec files and don't know which one to take. After searching for a solution in google I found a way to work this through - but this created report for each module separately, which didn't help much. I also tried to include specific the exec of one of the flavors in the execution data, which worked, but I don't know how to create something that will work for all the flavors. I found things like this solution, but for some reason that didn't work with Jacoco. What is the correct way to create code coverage for app with modules and flavors? Thanks, Omer