1

In our javafx mobile application, we are using Okhttp3 4.9.1 for http requests. One of our developers told me that even if we specify Okhttp as an external dependency, in android device it will only use the Okhttp bundled with android. So I just wanted to verify it and tried to print the okhttp versions at the runtime like this one. It didn't work (ClassNotFoundExceptions). So, my question is,

  1. Do javafx mobile apps use 'okhttp bundled with android' or the one that we specified as a dependency?
  2. How to get the version of 'okhttp' bundled with android in javafx mobile application?

1 Answers1

1

If you bundle OkHttp in your app it will use that version instead of the built in Android version. They differ in package also, so you can't easily mistake them. I don't think you can directly use https://android.googlesource.com/platform/external/okhttp/+/master/repackaged/okhttp/src/main/java/com/android/okhttp/OkHttpClient.java in your app, but I'm not certain.

You should be able to use okhttp3.OkHttp.VERSION directly, but it has a bug that it's const value and so inlined at compile time. So you can read this using reflection, assuming proguard isn't applied and moving the classes.

You can also look at the default user agent in an interceptor which uses this version field.

Class.forName("okhttp3.internal.Version") won't work because it's an internal detail and has since moved. It got moved in 4.7.0 https://github.com/square/okhttp/commit/72cb889c867481c578bce663d3ea0d92e648fcac#diff-6e62984ccabc6dc7bb9bbda58768b4af28bf789f6415d09c2d89de4387ecf816

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69