Skip to content

Conversation

@DevMohammadSalameh
Copy link

Summary

Fixes #2444

When Google Play Services is unavailable (e.g., on Android emulators without Google APIs or devices without Play Services), CronetEngine initialization throws a JniException:

"All available Cronet providers are disabled. A provider should be enabled before it can be used."

This change:

  • Wraps CronetAdapter creation in a try-catch block
  • Falls back to the standard HttpClientAdapter (dart:io) when Cronet is unavailable
  • Adds an optional onCronetUnavailable callback for developers who want to be notified when the fallback occurs

Changes

  • native_adapter.dart: Added graceful fallback with try-catch
  • CHANGELOG.md: Documented the new behavior

Usage

// Basic usage - fallback happens silently
final dio = Dio();
dio.httpClientAdapter = NativeAdapter();

// With callback to log or handle the fallback
dio.httpClientAdapter = NativeAdapter(
  onCronetUnavailable: (error) {
    print('Cronet unavailable, using dart:io fallback: $error');
  },
);

Test Plan

  • melos run format - passes
  • melos run analyze - passes
  • flutter test in native_dio_adapter - all 10 tests pass
  • Manual test on Android emulator without Google Play Services (requires device testing)

  Fixes cfug#2444

  When Google Play Services is unavailable, CronetEngine initialization
  throws a JniException. This change catches the exception and falls
  back to the standard HttpClientAdapter using dart:io.

  Also adds an optional onCronetUnavailable callback for developers
  who want to be notified when the fallback occurs.
@DevMohammadSalameh DevMohammadSalameh requested a review from a team as a code owner January 8, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[native_dio_adapter] All network requests fail when Google Play services are unavailable

1 participant