添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)' #1271 NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)' #1271 mmaryo opened this issue Sep 30, 2020 · 19 comments

Hello

When I run Web3j.build(HttpService(" https://ropsten.infura.io/$id")).web3ClientVersion().send( )

Therer is an error

java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)'

Inside HttpService and performIO I see

RequestBody.create(request, JSON_MEDIA_TYPE);

Is wrong

It should be

RequestBody.create(JSON_MEDIA_TYPE, request);

Environment

Kotlin 1.4.0
Quarkus 1.8.1.Final
Web3j 5.0.0

I encountered the same problem java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody; ;
when I use web3j-4.6.3 and run Web3ClientVersion clientVersion = web3.web3ClientVersion().send();

Is there any solution?

I encountered the same problem java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody; ;
when I use web3j-4.6.3 and run Web3ClientVersion clientVersion = web3.web3ClientVersion().send();

Is there any solution?

Did you manage to fix it?

	<dependencyManagement>
		<dependencies>
			<!--  Needed to avoid conflict with OkHttp being used in auth0-java and okhttp3 being used by spring -->
			<dependency>
				<groupId>com.squareup.okhttp3</groupId>
				<artifactId>okhttp</artifactId>
				<version>4.9.0</version>
			</dependency>
		</dependencies>
	</dependencyManagement>

found here: https://github.com/auth0/auth0-java/pull/342/files and here auth0/auth0-java#324

Fixed: Manually adding the okhttp3 dependency will fix it!

I have the same problem, how do I need to add dependencies manually?

Hey. I had the same issue on version 5.0.0, solved it by copypasting @BarBozz code, so my pom.xml structure looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project ...>
  <modelVersion></modelVersion>
  <dependencies></dependencies>
  some other tags
  <code copied from @BarBozz comment>
</project>

@BarBozz solutions gives me this

Exception in thread "main" java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B at okio.Segment.writeTo(Segment.kt:169) at okio.Segment.compact(Segment.kt:152) at okio.Buffer.write(Buffer.kt:1842) at okio.Buffer.read(Buffer.kt:1854) at okio.Buffer.writeAll(Buffer.kt:1642) at okio.Options$Companion.buildTrieRecursive(Options.kt:187) at okio.Options$Companion.buildTrieRecursive(Options.kt:174) at okio.Options$Companion.buildTrieRecursive$default(Options.kt:113) at okio.Options$Companion.of(Options.kt:72) at okhttp3.internal.Util.<clinit>(Util.kt:71) at okhttp3.internal.concurrent.TaskRunner.<clinit>(TaskRunner.kt:309) at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:41) at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:47) at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.kt:471) at org.web3j.protocol.http.HttpService.createOkHttpClient(HttpService.java:138) at org.web3j.protocol.http.HttpService.<init>(HttpService.java:118)

I'm using Spring Boot

Solved only by removing the BarBozz solutions from <dependencyManagement> and adding these to main <dependencies>:

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.9.1</version>
</dependency>
<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib</artifactId>
    <version>1.3.70</version>
</dependency>

Let Spring complains about version override.

For anyone using gradle:

implementation 'org.web3j:core:5.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'

will fix the problem.

I'm still seeing this bug. Setting the versions as suggested in the last two comments didn't help. Tested with:

  • java 17
  • quarkus 2.13.3.Final
  • kotlin 1.7.20
  • web3j 4.8.9 and 4.9.4
  • Going back to older versions (Java 11, Quarkus 2.1.2, Kotlin 1.4.32) solves the issue for me - without having to include a dependency to okhttp.

    Is there anyone out there to fix this bug?
    If you are using maven, add this dependency in your pom file.

    <dependency>
    	<groupId>com.squareup.okhttp3</groupId>
    	<artifactId>okhttp</artifactId>
    	<version>4.10.0</version>
    </dependency>
              

    For me the solution is now to not using the quarkus-bom.
    So remove the line (when using Gradle)

    implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
    

    and instead append ":${quarkusPlatformVersion}" to all quarkus dependencies. This way the okhttp version is not getting fixed to 3.x.x by the quarkus bom.

    Works with

  • Quarkus 3.0.3
  • web3j:core:4.9.8
  • It's still na issue for me even if I have already added suggested dependency.

    Java 17

            <dependency>
                <groupId>org.web3j</groupId>
                <artifactId>core</artifactId>
                <version>4.9.7</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp</artifactId>
                <version>4.9.3</version>
            </dependency>
    
    java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)'
    	at org.web3j.protocol.http.HttpService.performIO(HttpService.java:159) ~[core-4.9.7.jar:na]
    	at org.web3j.protocol.Service.send(Service.java:48) ~[core-4.9.7.jar:na]
    	at org.web3j.protocol.core.Request.send(Request.java:87) ~[core-4.9.7.jar:na]
    

    Can anyone help me please?

    NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)' #1990