0

我使用 vimeo 网络库(https://github.com/vimeo/vimeo-networking-java)、exoplayer实现了 vimeo 网络,并在这篇文章中解释了https://stackoverflow.com/a/65737556/8814924

现在的问题是当我检查 API 30 时出现错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emergingit.emergingstudy/com.emergingit.emergingstudy.activities.course.ExoPlayerActivity}: java.lang.IllegalStateException: Unable to extract the trust manager on Android10Platform, sslSocketFactory is class com .android.org.conscrypt.OpenSSLSocketFactoryImpl

原因:java.lang.IllegalStateException: Unable to extract the trust manager on Android10Platform, sslSocketFactory is class com.android.org.conscrypt.OpenSSLSocketFactoryImpl

这表明错误

VimeoClient.initialize(configuration);

此处讨论了哪个问题:https ://github.com/square/okhttp/issues/5878 ,问题讨论:

I assume you are calling the deprecated form of sslSocketFactory, which is broken on newer Android versions. https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/OkHttpClient.kt#L719

/**
 * Sets the socket factory used to secure HTTPS connections. If unset, the system default will
 * be used.
 *
 * @deprecated [SSLSocketFactory] does not expose its [X509TrustManager], which is a field that
 *     OkHttp needs to build a clean certificate chain. This method instead must use reflection
 *     to extract the trust manager. Applications should prefer to call
 *     `sslSocketFactory(SSLSocketFactory, X509TrustManager)`, which avoids such reflection.
 */
@Deprecated(
    message = "Use the sslSocketFactory overload that accepts a X509TrustManager.",
    level = DeprecationLevel.ERROR
)
fun sslSocketFactory(sslSocketFactory: SSLSocketFactory) = apply {
  if (sslSocketFactory != this.sslSocketFactoryOrNull) {
    this.routeDatabase = null
  }

  this.sslSocketFactoryOrNull = sslSocketFactory
  this.certificateChainCleaner = Platform.get().buildCertificateChainCleaner(sslSocketFactory)
}

使用网络库的当前版本“1.1.3”是否有任何解决方案,或者我必须等到库更新?

4

1 回答 1

0

我主要使用 Vimeo-Networking 库(v1.1.3)解决了 Android 10 平台上的 Vimeo 视频流问题。因为主要问题出在 OkHttpClient 构建方法中

builder.sslSocketFactory(sSLSocketFactory);
//RetrofitClientBuilder.java#186    

其中 1 个参数版本被贬低,我需要将 X509TTrustManager 作为第二个参数传递,如下所示:

builder.sslSocketFactory(sSLSocketFactory, new X509TrustManager() {
            @Override
            public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {

            }

            @Override
            public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {

            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[0];
            }
        });

所以它解决了我的问题,直到这个更新出现在这个库的稳定版本中。我如何实现这一点如下所述:

  1. VimeoClient.initialize(accessToken)上显示错误;行,我搜索了错误,发现它是由于这个 OkHttpClient 方法弃用(带有 1 个参数)引起的。

  2. 因此,我进入 VimeoClient.java 并在其构造函数中看到调用了private Retrofit createRetrofit()并在其中调用了private OkHttpClient createOkHttpClient()。并且创建了公共类 RetrofitClientBuilder对象,它的问题方法是public OkHttpClient build()其中:if (sSLSocketFactory != null) { builder.sslSocketFactory(sSLSocketFactory); } 调用了这个不推荐使用的方法。

  3. 所以我只需要创建两个名为VimeoClientUpdated.javaRetrofitClientBuilderUpdated.java的新 java 文件,这只是 VimeoClient.java 和 RetrofitClientBuilder.java 的重命名副本,现在RetrofitClientBuilderUpdated.java没有不推荐使用的方法,而是正确的VimeoClientUpdated.java正在调用RetrofitClientBuilderUpdated.java (由于最终类,我无法扩展,甚至无法将该类包装到该解决方案的网关,我不得不面对无法在包装类中更改的私有方法)

  4. 最后,我没有打电话,而是打电话VimeoClient.initialize(accessToken)给我新创建VimeoClientUpdated(accessToken)的,在 Android 10 上播放 Vimeo 视频时不会崩溃。

如果有更好的方法来满足我的目的(解决从 android 活动调用已弃用的库方法),请建议我。干杯..!!

于 2021-01-18T09:36:15.313 回答