Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OkHttp: NoSuchMethodError copyInto in TlsUtil

Running instrumentation tests with RESTMock we are getting this error

java.lang.NoSuchMethodError: No static method copyInto$default([Ljava/lang/Object;[Ljava/lang/Object;IIIILjava/lang/Object;)[Ljava/lang/Object; in class Lkotlin/collections/ArraysKt; or its super classes (declaration of 'kotlin.collections.ArraysKt' appears in /data/app/com.example.debug-1/base.apk)
FATAL EXCEPTION: pool-6-thread-1
Process: com.example.debug, PID: 6606
java.lang.NoSuchMethodError: No static method copyInto$default([Ljava/lang/Object;[Ljava/lang/Object;IIIILjava/lang/Object;)[Ljava/lang/Object; in class Lkotlin/collections/ArraysKt; or its super classes (declaration of 'kotlin.collections.ArraysKt' appears in /data/app/com.example.debug-1/base.apk)
    at okhttp3.tls.internal.TlsUtil.newKeyManager(TlsUtil.kt:84)
    at okhttp3.tls.HandshakeCertificates$Builder.build(HandshakeCertificates.kt:144)
    at io.appflate.restmock.SslUtils.localhost(SslUtils.java:49)
    at io.appflate.restmock.RESTMockServer.setUpHttps(RESTMockServer.java:91)
    at io.appflate.restmock.RESTMockServer.init(RESTMockServer.java:74)
    at io.appflate.restmock.RESTMockServerStarter$1.run(RESTMockServerStarter.java:56)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)

This is the line in question in OkHttp

IIUC, Kotlin can treat a varargs as a Kotlin Array and then call extensions functions like copyInto

We're on OkHttp 4.0.1, Kotlin 1.3.40, R8 1.5.41

Our test apk correctly contains copyInto method so I don't think it's a proguard/R8 issue:

enter image description here

I'm at a loss as to what to test next. I asked on OkHttp's github issuse page and they suggested I post here link

Update: still happening on OkHttp 4.1.0. Also I realized that it can't be an R8 issue since R8 doesn't remove code from test apk.

like image 874
tir38 Avatar asked Aug 02 '19 17:08

tir38


2 Answers

I had a same issue , then added the mentioning lib to my project. It solved my problem:

maven :

<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib -->
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>1.3.70</version>
        </dependency>

or

'org.jetbrains.kotlin:kotlin-stdlib:1.3.70'
like image 151
Reza Avatar answered Oct 19 '22 00:10

Reza


I got the same issue when I was using okhttp3.mockwebserver.MockWebServer with https enabled with a server certificate from okhttp-tls.
In my case, the problem was that by just importing the com.squareup.okhttp3:okhttp-tls:4.2.0 dependency, org.jetbrains.kotlin:kotlin-stdlib was being resolved to version 1.2.71.
Given the copyInto method was introduced starting kotlin 1.3 it was failing with the same error you have.

I fixed it by adding explicitly the kotlin version in my gradle.build file:
testRuntime 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'

like image 6
Alex Avatar answered Oct 19 '22 01:10

Alex