-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Upgrading incompatible issue: NoSuchFieldError: Companion #5378
Comments
Are you using the same versions for all your OkHttp and MockWebServer libraries? They must be in sync. |
I just had the same issue with OkHttp 4.x when upgrading from 3.x. We're not using MockWebServer or any other 'extensions', just OkHttp, so mismatching versions was not the case.
Eventually I found the cause. Our dependency tree (simplified and stripped):
Moshi depends on Okio 1.16.0, while OkHttp depends on Okio 2.2.2. This resulted in both okio 1.x and 2.x being added to the classpath. Forcing Okio to 2.x in the :main solved this issue. |
This sounds like a fairly severe Gradle bug if this truly is the result. The presence of a 2.x should replace the use of 1.x given they have the same Maven coordinates. You should see something like
|
I ran into the issue when running a Main class from IntelliJ, I'm not sure if this issue is related to IntelliJ or Gradle. I'm not a Gradle expert, but I think Gradle does report the right dependencies on the classpath: Output of
Output of
Again, both logs are simplified and stripped. I could provide detailed information privately if interested. We're using Gradle 5.6. |
Ok so those actually indicate that there are not two Okios on the classpath and that Gradle is doing the correct thing by upgrading the 1.x dependency to 2.x for the runtime classpath. |
That's what I thought, it looks like IntelliJ is wrong. Thanks for looking into it. |
Hi,
The following code snippets throw an incompatible issue when I try to upgrade okhttp from 3.10.0 to 4.1.0.
The mockito version is 2.16.0. It works well before. After upgrading, it throws an error:
The text was updated successfully, but these errors were encountered: