okhttp 3.8.0: ProGuard "can't find referenced class javax.annotation.Nullable"

Created on 14 May 2017  Â·  13Comments  Â·  Source: square/okhttp

According to the 3.8.0 CHANGELOG: "We've added a compile-time dependency on the JSR 305 annotations. This is a provided dependency and does not need to be included in your build configuration…"

However, ProGuard brings a lot of messages like this:

okhttp3.Address: can't find referenced class javax.annotation.Nullable
…

This can be worked around by adding jsr305 to the gradle configuration:

    compile 'com.google.code.findbugs:jsr305:3.0.2'

However, according to the docs, this should be done by okhttp dependencies.

Most helpful comment

All 13 comments

Thanks

it looks like minifyEnabled is set to true in your build.gradle so it is applying proguard rules. so you should add this rules to your proguard-rules.pro file

-dontwarn okio.*
-dontwarn com.squareup.okhttp3.
*
-keep class com.squareup.okhttp3.* { *; }
-keep interface com.squareup.okhttp3.
* { *; }
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

That is not OkHttp's package and so those rules are effectively useless
(aside from dropping warnings in Okio and for JSR 305 annotations). Even if
it was OkHttp's correct package, you're better off turning off ProGuard
than doing such an overly-keepy rule.

On Thu, Oct 26, 2017 at 4:22 PM attaullahpro notifications@github.com
wrote:

it looks like minifyEnabled is set to true in your build.gradle so it is
applying proguard rules. so you should add this rules to your
proguard-rules.pro file

-dontwarn okio.*
-dontwarn com.squareup.okhttp3.
*
-keep class com.squareup.okhttp3.* {
*; } -keep interface com.squareup.okhttp3.
* { *; }
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/square/okhttp/issues/3355#issuecomment-339720798, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEdEAc1uIR4V-lOVyHFNstfmQCzsKks5swLG2gaJpZM4NaVjH
.

@attaullahpro was almost right...

Correct one:

-dontwarn okio.*
-dontwarn com.squareup.okhttp3.
*
-keep class com.squareup.okhttp3.** { *; }
-keep interface com.squareup.okhttp3.** { *; }
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

That's not our package so most of those rules do nothing.

On Thu, Feb 15, 2018, 2:14 AM Mincho notifications@github.com wrote:

@attaullahpro https://github.com/attaullahpro was almost right...
-dontwarn okio.* -dontwarn com.squareup.okhttp3.* -keep class
com.squareup.okhttp3.* { *; } -keep interface com.squareup.okhttp3. { *;
} -dontwarn javax.annotation.Nullable -dontwarn
javax.annotation.ParametersAreNonnullByDefault

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/square/okhttp/issues/3355#issuecomment-365843447, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEUvDSZwzwXuXwvcx4MWwTKNqtN6gks5tU9lCgaJpZM4NaVjH
.

@JakeWharton I am sure you are aware that the side effect of having a popular library is that many other projects will utilize it. The side effect of offering a complete solution is that has a greater contribution to larger file size. The end result is a small portion of a larger library being used in a project that will then require tools, such as minifyEnabled, to compensate for the size increase.

I am using the parse-community replacement for Parse services and their library has introduced these errors. I am not using okhttp directly and cannot expect to have the changes to resolve this issue posted to a maven or jcenter repository immediately. It also seems absurd to recompile the entire library locally simply to bypass a warning that has no impact on the final output.

What rules would you suggest, even as a temporary solution? I appreciate pointing out that the library may not be an official version of okhttp or that the suggested rules are not relevant, but neither of these statements actually benefits those of us trying to resolve the issue.

@cketti I directed my question @JakeWharton because of the comment that "you're better off turning off ProGuard than doing such an overly-keepy rule" that contradicts the documentation's own "overly-keepy" rules, such as -dontwarn javax.annotation.**

I assume I can take that as just one contributor's personal opinion. Thanks.

That is not a keep rule. It's a don't warn rule.

On Mon, Mar 5, 2018 at 1:11 PM TwistedUmbrella notifications@github.com
wrote:

@cketti https://github.com/cketti I directed my question @JakeWharton
https://github.com/jakewharton because of the comment that "you're
better off turning off ProGuard than doing such an overly-keepy rule" that
contradicts the documentation's own "overly-keepy" rules, such as -dontwarn
javax.annotation.**

I assume I can take that as just one contributor's personal opinion.
Thanks.

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/square/okhttp/issues/3355#issuecomment-370509896, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEESNs-Q5paLQ005BQp1PDq4lE3DDuks5tbX9MgaJpZM4NaVjH
.

@JakeWharton Thanks for the input. I am sure you have good intentions, but your vague input on the matter has led me to favor the solutions others have posted.

I also face this problem. And I can fix by adding below rules in proguard
-dontwarn okio.*
-dontwarn okhttp3.
*

You can delete the last 3 lines. They do nothing!

On Thu, Jul 26, 2018 at 2:27 AM Kyaw Zin Htun notifications@github.com
wrote:

I also face this problem. And I can fix by adding below rules in proguard
-dontwarn okio.*
-dontwarn okhttp3.
*
-dontwarn com.squareup.okhttp3.*
-keep class com.squareup.okhttp3.
* {
; } -keep interface com.squareup.okhttp3.* { *; }

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/square/okhttp/issues/3355#issuecomment-407990688, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEaVw14nbaXyLnNv-iJnvtVr7uckzks5uKWFegaJpZM4NaVjH
.

Was this page helpful?
0 / 5 - 0 ratings