{"record":{"id":"47a3670fa4c72321","repo":"grpc/grpc-java","slug":"call-foraddress-androidcomponentaddress-context","errorCode":null,"errorMessage":"call forAddress(AndroidComponentAddress, Context) instead","messagePattern":"call forAddress\\(AndroidComponentAddress, Context\\) instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"binder/src/main/java/io/grpc/binder/BinderChannelBuilder.java","lineNumber":147,"sourceCode":"   *\n   * @param target A target uri which should resolve into an {@link AndroidComponentAddress}\n   *     referencing the service to bind to.\n   * @param sourceContext the context to bind from (e.g. The current Activity or Application).\n   * @param channelCredentials the arbitrary binder specific channel credentials to be used to\n   *     establish a binder connection.\n   * @return a new builder\n   */\n  @ExperimentalApi(\"https://github.com/grpc/grpc-java/issues/10173\")\n  public static BinderChannelBuilder forTarget(\n      String target, Context sourceContext, BinderChannelCredentials channelCredentials) {\n    return new BinderChannelBuilder(\n        null, checkNotNull(target, \"target\"), sourceContext, channelCredentials);\n  }\n\n  /** Always fails. Call {@link #forAddress(AndroidComponentAddress, Context)} instead. */\n  @DoNotCall(\"Unsupported. Use forAddress(AndroidComponentAddress, Context) instead\")\n  public static BinderChannelBuilder forAddress(String name, int port) {\n    throw new UnsupportedOperationException(\n        \"call forAddress(AndroidComponentAddress, Context) instead\");\n  }\n\n  /** Always fails. Call {@link #forAddress(AndroidComponentAddress, Context)} instead. */\n  @DoNotCall(\"Unsupported. Use forTarget(String, Context) instead\")\n  public static BinderChannelBuilder forTarget(String target) {\n    throw new UnsupportedOperationException(\n        \"call forAddress(AndroidComponentAddress, Context) instead\");\n  }\n\n  private final ManagedChannelImplBuilder managedChannelImplBuilder;\n  private final BinderClientTransportFactory.Builder transportFactoryBuilder;\n\n  private boolean strictLifecycleManagement;\n\n  private BinderChannelBuilder(\n      @Nullable AndroidComponentAddress directAddress,\n      @Nullable String target,","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/binder/src/main/java/io/grpc/binder/BinderChannelBuilder.java#L129-L165","documentation":"BinderChannelBuilder.forAddress(String name, int port) is intentionally unsupported: gRPC Binder channels address Android components, not host:port endpoints. The method is annotated @DoNotCall and always throws UnsupportedOperationException directing you to forAddress(AndroidComponentAddress, Context).","triggerScenarios":"Calling BinderChannelBuilder.forAddress(host, port) — typically ported code using the generic ManagedChannelBuilder API pattern on the binder transport.","commonSituations":"Refactoring a normal gRPC channel to BinderChannelBuilder and reusing forAddress(\"10.0.0.1\", 50051); copy-pasted builder code from an INET-based client.","solutions":["Use BinderChannelBuilder.forAddress(AndroidComponentAddress, Context) targeting the server component","If you need host:port channels, use the standard ManagedChannelBuilder instead of the binder transport","Route Android component addressing via AndroidComponentAddress.forComponent(ComponentName) or the binder-specific factories"],"exampleFix":"// before\nBinderChannelBuilder b = BinderChannelBuilder.forAddress(\"com.example/.Svc\", 8080);\n// after\nBinderChannelBuilder b = BinderChannelBuilder.forAddress(\n    AndroidComponentAddress.forComponent(new ComponentName(\"com.example\", \"com.example.Svc\")),\n    context);","handlingStrategy":"validation","validationCode":"if (address instanceof AndroidComponentAddress) {\n  builder = BinderChannelBuilder.forAddress((AndroidComponentAddress) address, context);\n} else {\n  builder = ManagedChannelBuilder.forAddress(host, port);\n}","typeGuard":"static boolean supportsBinderTransport(SocketAddress addr) {\n  return addr instanceof AndroidComponentAddress;\n}","tryCatchPattern":"try {\n  return BinderChannelBuilder.forAddress(componentAddr, context).build();\n} catch (UnsupportedOperationException e) {\n  throw new IllegalStateException(\"Binder channels need AndroidComponentAddress\", e);\n}","preventionTips":["Never port ManagedChannelBuilder.forAddress(host, port) calls to BinderChannelBuilder","Always construct channels from AndroidComponentAddress plus a Context","Read @DoNotCall annotations as hard API exclusions"],"tags":["grpc","binder","android","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}