java - 错误 : No functional channel service provider found. 尝试添加对 grpc-okhttp 或 grpc-netty Artifact 的依赖

标签 java maven intellij-idea

我正在使用 IntelliJ 在 java 中使用 Cloud Vision API 来检测相机图片中的标签。 API 工作正常,但是当我将 android.graphics 依赖项添加到我的 maven pom.xml 以使用 Bitmap ADT 时,它停止工作并抛出错误:“找不到功能 channel 服务提供者。尝试添加对 grpc 的依赖项-okhttp 或 grpc-netty Artifact ”。我尝试将下面的依赖项添加到我的 pom.xml,但没有任何改变。有人可以告诉我这个错误是什么意思吗?

<dependency>
  <groupId>com.google.android</groupId>
  <artifactId>android</artifactId>
  <version>2.3.1</version>
</dependency>
<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-okhttp</artifactId>
  <version>1.0.1</version>
</dependency>
<dependency>
  <groupId>io.grpc</groupId>
  <artifactId>grpc-netty-shaded</artifactId>
  <version>1.22.1</version>
</dependency>

这是我的代码:

导入 android.graphics.Bitmap;
public static void main(String... args) throws Exception {
    Bitmap bmp;
    String description = "";
    // Instantiates a client
    try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) {

        // The path to the image file to annotate
        String fileName = "c:/stairsPic.png";

        // Reads the image file into memory
        Path path = Paths.get(fileName);
        byte[] data = Files.readAllBytes(path);
        ByteString imgBytes = ByteString.copyFrom(data);

        // Builds the image annotation request
        List<AnnotateImageRequest> requests = new ArrayList<>();
        Image img = Image.newBuilder().setContent(imgBytes).build();
        Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
        AnnotateImageRequest request = AnnotateImageRequest.newBuilder()
                .addFeatures(feat)
                .setImage(img)
                .build();
        requests.add(request);

       // Performs label detection on the image file
        long start = System.currentTimeMillis();
        BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
        long end = System.currentTimeMillis();
        List<AnnotateImageResponse> responses = response.getResponsesList();

        for (AnnotateImageResponse res : responses) {
            if (res.hasError()) {
                System.out.printf("Error: %s\n", res.getError().getMessage());
                return;
            }

            for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
                description = annotation.getDescription();
                break;
            }
        }
        //finding the time difference and converting it into seconds
        float sec = (end - start) / 1000F;
        System.out.println(sec + " seconds");

        System.out.println("The photo description is: " + description);
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

我在执行“import android.graphics.Bitmap”并声明 Bitmap 变量时收到了上面描述的错误。
我的实际结果是在我的函数签名中获取 Bitmap 并将其发送到云视觉 API 而不会出现此错误。

最佳答案

我有同样的错误,结果是 IntelliJ 错误。
首先,您需要检查您是否有 grpc-netty-shaded IDE 中外部库下的库。就我而言,这是缺失的。我必须手动删除所有库,运行 File -> Invalidate Caches/Restart...然后运行 ​​mvn compile再次。
完成这些步骤后,您应该会看到 grpc-netty-shaded库中的外部库。

关于java - 错误 : No functional channel service provider found. 尝试添加对 grpc-okhttp 或 grpc-netty Artifact 的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57182070/

相关文章:

java - Apache Spark 在 IntelliJ 中给出错误

Scalatest 在 Intellij 中构建和运行,但在使用 maven 在命令行上运行时不构建项目

java - Android 中的 View 占据整个屏幕 - 如何告诉 Canvas 尊重 View 的限制?

java - 如何在选项卡更改时更改 Activity 标题(滑动 TabLayout)

java - 使用静态工厂方法的动机

java - Primefaces 组件不呈现

java - 为什么 jacoco :cover report 0 tests, 0 次失败,0 次错误用于 Play 2.2 中的测试?

java - 将 Artifact 从本地 Gradle Artifact 存储库部署到 JCenter/MavenCentral

spring - 严重 : A child container failed during start java. util.concurrent.ExecutionException : org. apache.catalina.LifecycleException 在 Tomcat 中?

Maven 默默地找不到要运行的 JUnit 测试