简体   繁体   中英

Using OkHttp 3.9.0 with Dagger 2.11 - Why must I include dagger-android2.x dependency?

I was using okhttp 3.8 with dagger 2.11, it works great. When I changed to okhttp 3.9 I was getting ERROR javax.annotation.Nullable not found.

So by some luck I tried including the dagger-android2.x dependency and that fixed the error.

I understood that If you want to use classes like DaggerActivity or if you want to inject activities or fragments you must include the dagger.android package, but why do I need to include it for OkHttp to be used with Dagger?

Edit: I did some more investigating. This change in the https://github.com/square/okhttp/commit/d4a9cf4772ae9d8991e58d934dea433798c9b8eb#diff-e88e53bd5c3b6fb1ba650f55b1261052R21

+import javax.annotation.Nullable;

is the problem.I had to include:

implementation 'com.google.code.findbugs:jsr305:3.0.2' to fix the error

Update 2:

I was injecting into my websocket listener, which I really didn't need to do. This caused the ERROR javax.annotation.Nullable not found. I changed my code to not inject into the websocketlistener and the error is gone and no need for additional dependencies, the error was entirely my fault.

You don't actually have to include the dagger-android2.x dependency. What happens is that OkHttp 3.9 now uses the javax.annotation.Nullable , which the dagger-android2.x dependency uses internally and is, therefore, also available for OkHttp through gradle merge.

Adding compile 'com.google.code.findbugs:jsr305:3.0.2' to your project should be enough, as you pointed out.

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