我正在尝试使用 Clarifai 来预测 Android 应用程序中的图像。我正在使用 Clarifai gRPC Java 客户端。但是,我收到 IllegalStateException 消息“找不到 TLS ALPN 提供程序;没有可用的 netty-tcnative、Conscrypt 或 Jetty NPN/ALPN'。我正在使用 Java 11,Clarifai gRPC 8.0.0.
下面是我的代码:
public class ClarifaiTask extends AsyncTask<File, Integer, Boolean> {
protected Boolean doInBackground(File... images) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel()).withCallCredentials(new ClarifaiCallCredentials(API_KEY));
MultiOutputResponse response = stub.postModelOutputs(PostModelOutputsRequest.newBuilder().setModelId(MODEL_ID).addInputs(Input.newBuilder().setData(Data.newBuilder().setImage(Image.newBuilder().setUrl(IMG_URL)))).build());
if (response.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Request failed, status: " + response.getStatus());
}
for (Concept c : response.getOutputs(0).getData().getConceptsList()) {
System.out.println(String.format("%12s: %,.2f", c.getName(), c.getValue()));
}
return true;
}
protected void onPostExecute(Boolean result) {
}
}
错误:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.package.name, PID: 25874
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:415)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)
at java.util.concurrent.FutureTask.setException(FutureTask.java:250)
at java.util.concurrent.FutureTask.run(FutureTask.java:269)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.IllegalStateException: Could not find TLS ALPN provider; no working netty-tcnative, Conscrypt, or Jetty NPN/ALPN available
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.defaultSslProvider(GrpcSslContexts.java:246)
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:146)
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:95)
at com.clarifai.channel.ClarifaiChannel.getGrpcChannel(ClarifaiChannel.java:37)
at com.clarifai.channel.ClarifaiChannel.getGrpcChannel(ClarifaiChannel.java:28)
at com.dinuxsoft.somethingg.ClarifaiTask.doInBackground(ClarifaiTask.java:41)
at com.dinuxsoft.somethingg.ClarifaiTask.doInBackground(ClarifaiTask.java:34)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
任何帮助表示赞赏。
您可以尝试安装 conscrypt 以提供 TLS 支持。
然后,您可以尝试更新您的 ClarifaiTask:
static {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
}
在调用存根之前