10

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.

tir38
  • 9,810
  • 10
  • 64
  • 107

3 Answers3

7

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'
Reza
  • 1,906
  • 1
  • 17
  • 21
6

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'

Alex
  • 409
  • 5
  • 12
  • 3
    okhttp and okhttp-tls depend on 1.3.50, so something else must have been pinning it back to an old version. https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp/4.2.0 – Yuri Schimke Sep 17 '19 at 09:51
  • Hmm maybe I had a similar problem. When I came back to this problem a few weeks later it had been resolved. Likely I updated another lib that pulled us to the latest Kotlin. – tir38 Dec 20 '19 at 19:21
0

I got the same issue, but I'm developing a multi-module java project. It was useful that add a dependency for kotlin-stdlib in pom.xml that belongs to this module while unit testing...

When I boot this whole project, this issue came out agnain. Finally, I find this dependency need to be in the whole project's pom.xml, I mean the pom.xml in the project's root dir.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30235168) – Ilario Nov 02 '21 at 13:25