Android | Get OkHTTP Library version at runtime

Viewed 4553

Recently I analyzed crash reports form my app and found several stack traces which points to okhttp

My app doesn't depend on okhttp explicitly.

AFAIK okhttp version depends on Android OS version, and okhttp library by itself placed on device

To help with troubleshooting I decided to log okhttp library version, and looks like I found several useful classes for this

  1. com.squareup.okhttp.internal.Version
  2. okhttp3.internal.Version

Just to make sure that I didn't mistake I took com.android.okhttp.internal.http.HttpURLConnectionImpl class form stack-trace and tried to Class.forName it - success

Also I noticed that com.squareup.okhttp transformed to com.android.okhttp looks like at build-time, so totally I tried such variants

  1. Class.forName("com.android.okhttp.internal.Version") -> java.lang.ClassNotFoundException
  2. Class.forName("com.squareup.okhttp.internal.Version") -> java.lang.ClassNotFoundException
  3. Class.forName("okhttp3.internal.Version") -> java.lang.ClassNotFoundException
  4. Class.forName("com.android.okhttp.internal.http.HttpURLConnectionImpl") -> success

Can anyone explain why? What I missed?

Update

I have pulled okhttp.jar from my device adb pull /system/framework/okhttp.jar but it contains MANIFEST.MF only

1 Answers
Related