0

I'm trying to integrate Dagger 2 to be used in unit tests. Unfortunately whenever I run my test I get java.lang.NoClassDefFoundError: javax/inject/Provider.

I have the javax dependency added in Gradle like this:

depdencencies {
    ...
    provided 'javax.annotation:jsr250-api:1.0'
}

What I tried: Changing provided to compile. Adding both compile and testCompile with this dependency. I also tried testProvided but there is no such thing so it didn't work either.

Apparently the problem is that by using provided this dependency is available only compile time. Unfortunately nothing else worked so I am open to any suggestions. If more information is needed, please ask. Thanks!

dephinera
  • 3,703
  • 11
  • 41
  • 75

1 Answers1

0

I use in AndroidStudio 2.2.3 dagger2 for unit testing with app/build.gradle

....

apt 'com.google.dagger:dagger-compiler:2.11'
compile 'com.google.dagger:dagger:2.11'
provided 'javax.annotation:jsr250-api:1.0'
provided 'org.glassfish:javax.annotation:10.0-b28'


....
eurosecom
  • 2,932
  • 4
  • 24
  • 38
  • thanks. Although can you provide information why it doesn't work in my case? Also why do I need to use both two `provided` dependencies for javax annotations? – dephinera Oct 04 '17 at 07:47
  • I think it's just enough provided 'org.glassfish:javax.annotation:10.0-b28' Sorry I can not explain it. I studied the Dagger tutorials and used the recommended buil.gradle – eurosecom Oct 04 '17 at 12:57