0

I cannot build a simple metric from a java application using the Stackdriver Monitoring client when I have a dependency to the Google Dataflow client.

I get the exception:

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:78)
    at java.util.Collections$ReverseComparator2.compare(Collections.java:5178)
    at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
    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:75)
    at io.grpc.ServiceProviders.load(ServiceProviders.java:42)
    at io.grpc.ManagedChannelProvider.<clinit>(ManagedChannelProvider.java:37)
    at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:36)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:185)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:157)
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:149)
    at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:151)
    at com.google.cloud.monitoring.v3.stub.GrpcMetricServiceStub.create(GrpcMetricServiceStub.java:173)
    at com.google.cloud.monitoring.v3.stub.MetricServiceStubSettings.createStub(MetricServiceStubSettings.java:184)
    at com.google.cloud.monitoring.v3.MetricServiceClient.<init>(MetricServiceClient.java:158)
    at com.google.cloud.monitoring.v3.MetricServiceClient.create(MetricServiceClient.java:139)
    at com.google.cloud.monitoring.v3.MetricServiceClient.create(MetricServiceClient.java:130)
    at SimpleMetric.main(SimpleMetric.java:7)

on the create method:

import com.google.cloud.monitoring.v3.MetricServiceClient;

import java.io.IOException;

public class SimpleMetric {
    public static void main(String... args) throws IOException {
        MetricServiceClient metricServiceClient = MetricServiceClient.create();
    }
}

only when I add:

compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:2.5.0'

as in my gradle file as a dependency.

plugins {
    id 'java'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

    dependencies {
        compile 'com.google.cloud:google-cloud-monitoring:1.48.0'
        // exception with the dependency below
        compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:2.5.0'

    }

I reported the issue to Google. In the meantime, is there a workaround?

4

1 回答 1

0

isAndroid在 io.grpc.ManagedChannelProvider 中定义,从 1.11 版的 grpc-core 中取出。该错误意味着您以某种方式使用 1.11 之前的 grpc-okhttp 和 1.11 或更高版本的 grpc-core。

google-cloud-monitoring 1.48.0 间接依赖于 grpc-core 1.13:

com.google.cloud:google-cloud-monitoring:jar:1.48.0:compile
+- com.google.cloud:google-cloud-core:jar:1.48.0:compile
+- com.google.cloud:google-cloud-core-grpc:jar:1.48.0:compile
|  +- io.grpc:grpc-protobuf:jar:1.13.1:compile
|  |  \- io.grpc:grpc-protobuf-lite:jar:1.13.1:compile
|  +- io.grpc:grpc-context:jar:1.13.1:compile
+- com.google.api.grpc:proto-google-cloud-monitoring-v3:jar:1.30.0:compile
+- io.grpc:grpc-netty-shaded:jar:1.13.1:compile
|  \- io.grpc:grpc-core:jar:1.13.1:compile (version selected from constraint [1.13.1,1.13.1])
|     +- com.google.errorprone:error_prone_annotations:jar:2.1.2:compile
|     +- io.opencensus:opencensus-api:jar:0.12.3:compile
|     \- io.opencensus:opencensus-contrib-grpc-metrics:jar:0.12.3:compile
+- io.grpc:grpc-stub:jar:1.13.1:compile
\- io.grpc:grpc-auth:jar:1.13.1:compile

google-cloud-dataflow-java-sdk-all 2.5.0 间接依赖于 grpc-core 1.2 和 grpc-okhttp 1.2:

com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:jar:2.5.0:compile
 +- org.apache.beam:beam-sdks-java-io-google-cloud-platform:jar:2.5.0:compile
 |  +- io.grpc:grpc-core:jar:1.2.0:compile
 |  |  +- com.google.errorprone:error_prone_annotations:jar:2.0.11:compile
 |  |  +- io.grpc:grpc-context:jar:1.2.0:compile
 |  |  \- com.google.instrumentation:instrumentation-api:jar:0.3.0:compile
 |  +- com.google.api:gax-grpc:jar:0.20.0:compile
 |  |  +- io.grpc:grpc-protobuf:jar:1.2.0:compile
 |  |  +- com.google.api:api-common:jar:1.1.0:compile
 |  |  +- com.google.auto.value:auto-value:jar:1.2:compile
 |  |  +- com.google.api:gax:jar:1.3.1:compile
 |  |  \- org.threeten:threetenbp:jar:1.3.3:compile
 |  +- io.grpc:grpc-auth:jar:1.2.0:compile
 |  +- io.grpc:grpc-netty:jar:1.2.0:compile
 |  +- io.grpc:grpc-stub:jar:1.2.0:compile
 |  +- io.grpc:grpc-all:jar:1.2.0:compile
 |  |  +- io.grpc:grpc-okhttp:jar:1.2.0:compile
 |  |  |  +- com.squareup.okhttp:okhttp:jar:2.5.0:compile
 |  |  |  \- com.squareup.okio:okio:jar:1.6.0:compile

所以基本上数据流已经过时并导致冲突。不再支持数据流 SDK,因为它现在是 Apache Beam。考虑迁移以解决问题。

于 2018-10-10T20:19:30.733 回答