如何获取OkHttp 4.x的UserAgent?

Ely*_*lye 3 android okhttp

在 OkHttp 3.x 中,我们可以使用以下方式获取用户代理

\n
import okhttp3.internal.Version\n\nprintln(Version.userAgent())\n
Run Code Online (Sandbox Code Playgroud)\n

然而,这在 OkHttp 4.x 中不再起作用。

\n

https://github.com/square/okhttp/issues/5969中提出了一个问题,并在https://github.com/square/okhttp/pull/5981中修复中修复,但我无法解决工作。

\n

变更日志中指出从 4.7.0 版本开始。

\n
New: Constant string okhttp3.VERSION. This is a string like \xe2\x80\x9c4.5.0-RC1\xe2\x80\x9d, \xe2\x80\x9c4.5.0\xe2\x80\x9d, or \xe2\x80\x9c4.6.0-SNAPSHOT\xe2\x80\x9d indicating the version of OkHttp in the current runtime. Use this to include the OkHttp version in custom User-Agent headers.\n
Run Code Online (Sandbox Code Playgroud)\n

但我就是无法导入okhttp3.VERSION

\n

Ely*_*lye 5

清除缓存并重新同步后,我现在可以获得该版本

import okhttp3.OkHttp.VERSION

println(VERSION)
Run Code Online (Sandbox Code Playgroud)