Android | Get OkHTTP Library version at runtime
<p>Recently I analyzed crash reports form my app and found several stack traces which points to <code>okhttp</code></p>

<p>My app doesn't depend on <code>okhttp</code> explicitly.</p>

<p>AFAIK <code>okhttp</code> version depends on Android OS version, and <code>okhttp</code> library by itself placed on device</p>

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

<ol>
<li><a href="https://android.googlesource.com/platform/external/okhttp/+/master/okhttp/src/main/java-templates/com/squareup/okhttp/internal/Version.java" rel="nofollow"><code>com.squareup.okhttp.internal.Version</code></a></li>
<li><a href="https://github.com/square/okhttp/blob/master/okhttp/src/main/java-templates/okhttp3/internal/Version.java" rel="nofollow"><code>okhttp3.internal.Version</code></a></li>
</ol>

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

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

<ol>
<li><code>Class.forName("com.android.okhttp.internal.Version")</code> -> <code>java.lang.ClassNotFoundException</code></li>
<li><code>Class.forName("com.squareup.okhttp.internal.Version")</code> -> <code>java.lang.ClassNotFoundException</code></li>
<li><code>Class.forName("okhttp3.internal.Version")</code> -> <code>java.lang.ClassNotFoundException</code></li>
<li><code>Class.forName("com.android.okhttp.internal.http.HttpURLConnectionImpl")</code> -> success</li>
</ol>

<p>Can anyone explain why? What I missed?</p>

<p><strong>Update</strong></p>

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