错误:找不到功能通道服务提供商。尝试添加对 grpc-okhttp 或 grpc-netty 工件的依赖项

Ofi*_*r77 6 java intellij-idea maven

我正在使用 Java 中的 Cloud Vision API 使用 IntelliJ 来检测相机图片中的标签。API 工作正常,但是当我将 android.graphics 依赖项添加到我的 maven pom.xml 以使用位图 ADT 时,它停止工作并抛出错误:“找不到功能通道服务提供程序。尝试添加对 grpc 的依赖项-okhttp 或 grpc-netty 神器”。我尝试将下面的依赖项添加到我的 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>
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

导入 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());
    }
}
Run Code Online (Sandbox Code Playgroud)

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

dge*_*ert 2

我遇到了同样的错误,结果是 IntelliJ 错误。

首先,您需要检查grpc-netty-shadedIDE 中的外部库下是否有您的库。我的案例中缺少这一点。我必须手动删除所有库,运行File -> Invalidate Caches/Restart...然后mvn compile再次运行。

完成这些步骤后,您应该grpc-netty-shaded在外部库中看到库。