简体   繁体   中英

Use provide gradle dependency in Android Unit Test

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!

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'


....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM