{"record":{"id":"6960fe3268a30a11","repo":"grpc/grpc-java","slug":"unable-to-load-okhttpchannelprovider","errorCode":null,"errorMessage":"Unable to load OkHttpChannelProvider","messagePattern":"Unable to load OkHttpChannelProvider","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"android/src/main/java/io/grpc/android/AndroidChannelBuilder.java","lineNumber":138,"sourceCode":"  }\n\n  /**\n   * Creates a new builder, which delegates to the given ManagedChannelBuilder.\n   *\n   * <p>The provided {@code builder} becomes \"owned\" by AndroidChannelBuilder. The caller should\n   * not modify the provided builder and AndroidChannelBuilder may modify it. That implies reusing\n   * the provided builder to build another channel may result with unexpected configurations. That\n   * usage should be discouraged.\n   *\n   * @since 1.24.0\n   */\n  public static AndroidChannelBuilder usingBuilder(ManagedChannelBuilder<?> builder) {\n    return new AndroidChannelBuilder(builder);\n  }\n\n  private AndroidChannelBuilder(String target) {\n    if (OKHTTP_CHANNEL_PROVIDER == null) {\n      throw new UnsupportedOperationException(\"Unable to load OkHttpChannelProvider\");\n    }\n    delegateBuilder =\n        InternalManagedChannelProvider.builderForTarget(OKHTTP_CHANNEL_PROVIDER, target);\n  }\n\n  private AndroidChannelBuilder(ManagedChannelBuilder<?> delegateBuilder) {\n    this.delegateBuilder = Preconditions.checkNotNull(delegateBuilder, \"delegateBuilder\");\n  }\n\n  /**\n   * Enables automatic monitoring of the device's network state.\n   */\n  public AndroidChannelBuilder context(Context context) {\n    this.context = context;\n    return this;\n  }\n\n  @Override","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/AndroidChannelBuilder.java#L120-L156","documentation":"AndroidChannelBuilder's target-string constructor relies on the bundled OkHttp channel provider (OKHTTP_CHANNEL_PROVIDER) to delegate channel creation. If ServiceLoader failed to load OkHttpChannelBuilder's provider — usually because the grpc-okhttp dependency is missing from the APK — the builder throws UnsupportedOperationException(\"Unable to load OkHttpChannelProvider\").","triggerScenarios":"Building a channel via AndroidChannelBuilder.forTarget(String) when grpc-okhttp is not on the classpath, or with ProGuard/R8 stripping OkHttpChannelProvider before ServiceLoader can instantiate it.","commonSituations":"Android apps missing the io.grpc:grpc-okhttp dependency, shrinker configs removing META-INF/services entries for the provider, or transitive dependency conflicts dropping okhttp classes.","solutions":["Add the io.grpc:grpc-okhttp dependency to the Android build","Keep ServiceLoader entries: ensure ProGuard/R8 keeps META-INF/services/io.grpc.ManagedChannelProvider (don't strip service files)","Alternatively use AndroidChannelBuilder.usingBuilder(OkHttpChannelBuilder.forTarget(...)) which bypasses provider lookup","Prefer the explicit usingBuilder(...) path in newer grpc-android versions, as forTarget(String) is deprecated"],"exampleFix":"// before\nChannel channel = AndroidChannelBuilder.forTarget(\"dns:///example.com:443\").build();\n// after (build.gradle: implementation 'io.grpc:grpc-okhttp:1.x')\nChannel channel = AndroidChannelBuilder\n    .usingBuilder(OkHttpChannelBuilder.forTarget(\"dns:///example.com:443\"))\n    .build();","handlingStrategy":"fallback","validationCode":"if (OKHTTP_CHANNEL_PROVIDER == null) {\n  throw new IllegalStateException(\"grpc-okhttp not available: add io.grpc:grpc-okhttp dependency\");\n}","typeGuard":"null","tryCatchPattern":"try {\n  return AndroidChannelBuilder.forTarget(target).build();\n} catch (UnsupportedOperationException e) {\n  // grpc-okhttp missing or stripped: add dependency or fix keep rules\n  throw new IllegalStateException(\"Include io.grpc:grpc-okhttp and keep META-INF/services\", e);\n}","preventionTips":["Declare io.grpc:grpc-okhttp in Android builds that use AndroidChannelBuilder","Ensure ProGuard/R8 keeps ManagedChannelProvider service-loader entries","Prefer AndroidChannelBuilder.usingBuilder(explicitBuilder) over the deprecated forTarget(String)","Run a smoke test that builds a channel at app startup to catch missing-provider issues early"],"tags":["grpc","android","okhttp","classpath","dependency"],"backgroundTag":"missing-dependency","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"}