Vimeo Networking Library Crash for Android 10 platform (api29)

爱⌒轻易说出口 提交于 2021-02-10 06:16:10

问题


I implemented vimeo networking using vimeo networking library(https://github.com/vimeo/vimeo-networking-java), exoplayer and explained in this post https://stackoverflow.com/a/65737556/8814924

Now the problem is when I was checking with API 30 it was getting error

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

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

which indicates the error on

VimeoClient.initialize(configuration);

which issue is dicscussed here : https://github.com/square/okhttp/issues/5878 , issue discussion :

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)
}

is there any solution possible with using the current version "1.1.3" of networking library for this or I have to wait till the library update ?


回答1:


I primarily Solved the problem for Vimeo video streaming on the Android 10 platform using the Vimeo-Networking library (v1.1.3). as the main problem is in the OkHttpClient build method

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

where with 1 parameter version is depricated and I needed to pass X509TTrustManager as 2nd parameter like this :

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];
            }
        });

So it solved my problem till this update comes in the stable version of this library. How I implemented this is described below :

  1. Error was showing on VimeoClient.initialize(accessToken); line and I searched about the error and find out that it is caused because of this OkHttpClient method deprecation (with 1 parameter).

  2. So I went into VimeoClient.java and saw in its constructor private Retrofit createRetrofit() was called and inside it private OkHttpClient createOkHttpClient() was called. and there public class RetrofitClientBuilder object was created and it's problemetic method was public OkHttpClient build() in which : if (sSLSocketFactory != null) { builder.sslSocketFactory(sSLSocketFactory); } this deprecated method was called.

  3. So I just had to create 2 new java file with name VimeoClientUpdated.java and RetrofitClientBuilderUpdated.java which is just a renamed copy of VimeoClient.java and RetrofitClientBuilder.java and now my RetrofitClientBuilderUpdated.java has no deprecated method rather the correct and VimeoClientUpdated.java is calling RetrofitClientBuilderUpdated.java (I couldn't extend because of the final class and couldn't even wrap the class as to the gateway to that solution, I had to face the private method which wasn't possible to alter in wrapper class)

  4. and finally just instead of calling VimeoClient.initialize(accessToken) I am calling my newly created VimeoClientUpdated(accessToken) which won't crash while playing Vimeo video on Android 10.

Suggest me if there is a better way of serving my purpose (solving deprecated library method calling from the android activity). Cheers..!!



来源:https://stackoverflow.com/questions/65737921/vimeo-networking-library-crash-for-android-10-platform-api29

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!