Certificate pinning not working

config.setPinnedServerCertificate(pinnedServerCert) is giving me following error

java.lang.NoSuchMethodError: No static method verifyAsIpAddress(Ljava/lang/String;)Z in class Lokhttp3/internal/Util; or its super classes (declaration of ‘okhttp3.internal.Util’ appears in /data/app/com.metispro.quanticpos-Pzcp2nCL2_svKEMsmIadzw==/base.apk!classes3.dex)
at okhttp3.internal.tls.CustomHostnameVerifier.verify(CustomHostnameVerifier.java:68)
at okhttp3.internal.tls.CustomHostnameVerifier.verify(CustomHostnameVerifier.java:60)
at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.kt:357)
at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.kt:310)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:178)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:236)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:109)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:77)
at okhttp3.internal.connection.Transmitter.newExchange$okhttp(Transmitter.kt:162)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:35)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:71)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.kt:184)
at okhttp3.RealCall$AsyncCall.run(RealCall.kt:136)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

I little more information would be really useful. Which of our products are you using? What version are you using? Can we see the code that is failing?

It looks to me as if you have a wrong version of okhttp bound into your app.

implementation 'com.squareup.okhttp3:okhttp:3.9.1'

this i tried but didnt work.
right now m using
implementation ‘com.squareup.okhttp3:okhttp:4.2.0’
with
implementation ‘com.couchbase.lite:couchbase-lite-android:2.6.2’

and it fails only when i pin certificate for wss. ws works perfectly.

code:
private byte getPinnedCertFile(Context context) {
AssetManager assetManager = context.getAssets();
InputStream is;
try {
is = assetManager.open(“cert.cer”);
return (IOUtils.toByteArray(is));
} catch (IOException e) {
e.printStackTrace();
}
return null;

}

    ReplicatorConfiguration config = new ReplicatorConfiguration(getDatabase(), new URLEndpoint(url));
    config.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PUSH_AND_PULL);
    config.setContinuous(true);
    config.setAuthenticator(new BasicAuthenticator(username, password));
    byte[] pinnedServerCert = this.getPinnedCertFile(context);
    // Set pinned certificate.
    if (pinnedServerCert != null)
        config.setPinnedServerCertificate(pinnedServerCert);
    replicator = new Replicator(config);
    replicator.addChangeListener(CBSyncStatus::setmObservableStatus);
    replicator.start();

and when i went to CustomHostnameVerifier inside the OKHttp3 library,
verifyAsIpAddress of import static okhttp3.internal.Util.verifyAsIpAddress was RED(didnt exist) and same case with verifyAsIpAddress in following method:
public boolean verify(String host, X509Certificate certificate) {
return verifyAsIpAddress(host)
? verifyIpAddress(host, certificate)
: verifyHostname(host, certificate);
}

and one more thing,

configurations.all {
resolutionStrategy.force ‘com.squareup.okhttp3:logging-interceptor:3.9.1’
resolutionStrategy.force ‘com.squareup.okhttp3:okhttp:3.9.1’
}
if i force the version it worked but is there any better solution from your side?