Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFound Exception #5

Closed
josomers opened this issue May 8, 2014 · 8 comments
Closed

FileNotFound Exception #5

josomers opened this issue May 8, 2014 · 8 comments

Comments

@josomers
Copy link

josomers commented May 8, 2014

Hi,

I'm trying to make my Robolectric tests work with Jacoco support, but it seems that the plugin is not compatible with Dagger as it can not find some class files with '$$' in the filename. For this reason I got a FileNotFoundException when executing the 'jacocoTestReport' task. Is this related to the 'known issue' on this page: http://tools.android.com/tech-docs/new-build-system or is this something that needs to be fixed in Dagger, Android build tools or the Jacoco plugin?

Thanks.

@josomers josomers changed the title Dagger support FileNotFound Exception May 8, 2014
@nenick
Copy link
Owner

nenick commented May 8, 2014

Lets find it out who needs work ...

Get you coverage report when you run connectedCheck (espresso tests)? When yes then dagger + jacoco works together and it should be possible with robolectric.

Create a sample project setup with dagger to show us your error, then we can try out. Class not found mean most times it is missing in the classpath. Try out to play with this line classDirectories = fileTree(dir: '../AndroidSample/build/classes/debug', exclude: 'com/example/R*.class')

What is your intention to use dagger? Maybe it would be enough to use AndroidAnnotions as your dependency injection framework.

@josomers
Copy link
Author

I'm planning to create a few sample applications in the upcoming week. I'll keep you informed.

@josomers
Copy link
Author

It's about injection which is not compatible with jacoco I guess, both Butterknife as Dagger are not compatible after testing some things.

@dpreussler
Copy link

As it's not mentioned here, at least those projects can have coverage with excluding the generated classes: exclude: '/$.class'

@nenick
Copy link
Owner

nenick commented Jun 12, 2014

have you tried it or maybe @josomers could you try it please?

current i don't plan to include dagger or butterknife until someone has a good reason for me. But I would be glad if someone found a way to get it work and share it with me. Then i will mention it in the wiki how to include dagger or butterknife and get this code under test.

@josomers
Copy link
Author

Very nice suggestion by @dpreussler! I tried and modified it a little, but this is my working solution: https://gist.github.com/josomers/9f90b017e321c54bb918

Make sure to replace 'my-project' with the name of your project.

@nenick
Copy link
Owner

nenick commented Jun 30, 2014

here is a solution without excluding the generated files http://chrisjenx.com/gradle-robolectric-jacoco-dagger/

the main part is to add following part inside jacocoTestReport { }

    doFirst {
        new File('myapp/build/intermediates/classes/').eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }

@sunhao111999
Copy link

@nenick @josomers

i use the solution with my project , task skipped.
my build.gralde

apply plugin: 'jacoco'

android {
  buildTypes {
    debug {
      testCoverageEnabled true
    }
  }
  jacoco {
    version "0.7.1.201405082137"
  }


def coverageSourceDirs = [
        'src/main/java',
]

task jacocoTestReport(type: JacocoReport) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R*.class',
                       '**/*$InjectAdapter.class',
                       '**/*$ModuleAdapter.class',
                       '**/*$ViewInjector*.class'
            ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files("$buildDir/jacoco/testDebug.exec")

    doFirst {
        new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }
}

result:

./gradlew  jacocoTestReport --stacktrace
setup
create beta
cleanPublish:/home/sunhao/Project/android/build/apks
:app:jacocoTestReport SKIPPED

BUILD SUCCESSFUL

Total time: 21.856 secs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants