profile
viewpoint

Ask questionsjava.lang.NoSuchMethodError on Google PubSub Publisher.newBuilder().build()

I'm getting this error stack trace:

Exception in thread "main" java.lang.NoSuchMethodError: io.grpc.okhttp.OkHttpChannelProvider.isAndroid()Z
	at io.grpc.okhttp.OkHttpChannelProvider.priority(OkHttpChannelProvider.java:51)
	at io.grpc.ManagedChannelProvider$1.getPriority(ManagedChannelProvider.java:49)
	at io.grpc.ManagedChannelProvider$1.getPriority(ManagedChannelProvider.java:41)
	at io.grpc.ServiceProviders$1.compare(ServiceProviders.java:79)
	at java.util.Collections$ReverseComparator2.compare(Collections.java:5178)
	at java.util.TimSort.countRunAndMakeAscending(TimSort.java:360)
	at java.util.TimSort.sort(TimSort.java:220)
	at java.util.Arrays.sort(Arrays.java:1512)
	at java.util.ArrayList.sort(ArrayList.java:1462)
	at java.util.Collections.sort(Collections.java:175)
	at io.grpc.ServiceProviders.loadAll(ServiceProviders.java:76)
	at io.grpc.ServiceProviders.load(ServiceProviders.java:42)
	at io.grpc.ManagedChannelProvider.<clinit>(ManagedChannelProvider.java:37)
	at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:37)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:194)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:169)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:156)
	at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:157)
	at com.google.cloud.pubsub.v1.stub.GrpcPublisherStub.create(GrpcPublisherStub.java:164)
	at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:152)
	at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:82)
	at com.google.cloud.pubsub.v1.Publisher$Builder.build(Publisher.java:597)
	at TrackingAPI.sendEvent(TrackingAPI.java:20)
	at EventGenerator.sendRandomEvents(EventGenerator.java:46)
	at EventGenerator.main(EventGenerator.java:22)

When executing this line:

Publisher publisher = Publisher.newBuilder(TOPIC_ID).build();. I suspect some dependency issue. This is my pom-file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.findwise.app</groupId>
    <artifactId>data-pipeline</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-core</artifactId>
            <version>1.19.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-storage</artifactId>
            <version>1.73.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-pubsub</artifactId>
            <version>1.73.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud.dataflow</groupId>
            <artifactId>google-cloud-dataflow-java-sdk-all</artifactId>
            <version>2.5.0</version>
            <exclusions>
                <exclusion>
                    <groupId>io.grpc</groupId>
                    <artifactId>grpc-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>

What is the reason for this issue?

googleapis/google-cloud-java

Answer questions chingor13

This looks like a mismatch of grpc versions. Is there a reason you're locking the grpc version to 1.19?

useful!

Related questions

Dialogflow V2, Springboot Dialogflow Library calls are failing ::: java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_linux_x86_64, netty_tcnative_linux_x86_64_fedora, netty_tcnative_x86_64, netty_tcnative] hot 2
PubSub: grpc Uncaught exception in the SynchronizationContext. Panic! - Could not find LoadBalancer pick_first hot 2
Pubsub Subscriber initialization crashes JVM on Alpine Linux with libc6-compat hot 1
Google-cloud-language: No such Method Error on gax grpc hot 1
Duplicate classes error when adding dialogflow dependency 0.98.0-alpha along with firebase hot 1
The newest version of google-cloud-speech jar bug report hot 1
Firestore: Quickstart throws IllegalStateException: Could not find policy 'pick_first' hot 1
Firestore: should library handle/retry UNAVAILABLE errors? hot 1
PubSub: grpc Uncaught exception in the SynchronizationContext. Panic! - Could not find LoadBalancer pick_first hot 1
Error reporting from GCE fails due to auth issues hot 1
Dependency conflict with KMS when running Spark code in Dataproc hot 1
Memory leak from netty/Deadline exceeded after 9999961477ns hot 1
BigQuery: Create new Table using schema from json file hot 1
Unable to make GRPC call in 32bit Windows Machine hot 1
PubSub: grpc Uncaught exception in the SynchronizationContext. Panic! - Could not find LoadBalancer pick_first hot 1
Github User Rank List