How to get UserAgent of OkHttp 4.x?

Viewed 1484

In OkHttp 3.x, we can get the user agent using

import okhttp3.internal.Version

println(Version.userAgent())

However, this is not working anymore in OkHttp 4.x.

There was an issue raised in https://github.com/square/okhttp/issues/5969, and fixed in https://github.com/square/okhttp/pull/5981, but I can't get it to work.

In the change log, it is stated starting version 4.7.0.

New: Constant string okhttp3.VERSION. This is a string like “4.5.0-RC1”, “4.5.0”, or “4.6.0-SNAPSHOT” indicating the version of OkHttp in the current runtime. Use this to include the OkHttp version in custom User-Agent headers.

But I just can't get to import okhttp3.VERSION

1 Answers

After clearing the cache and resync, I can now have the version

import okhttp3.OkHttp.VERSION

println(VERSION)
Related