setupSha method

Future<void> setupSha(
  1. String projectId
)

Orchestrates the full SHA setup flow for the specified projectId.

This includes:

  1. Fetching SHA-1 and SHA-256 values locally.
  2. Finding the corresponding Firebase Android App ID.
  3. Uploading both fingerprints to the Firebase Console.

Implementation

Future<void> setupSha(String projectId) async {
  print('šŸ”‘ Setting up SHA (SHA-1 + SHA-256)...\n');

  final shas = await getShas();

  final sha1 = shas['sha1'];
  final sha256 = shas['sha256'];

  if ((sha1 == null || sha1.isEmpty) &&
      (sha256 == null || sha256.isEmpty)) {
    print('āŒ No SHA values found');
    return;
  }

  final appId = await getAndroidAppId(projectId);
  if (appId == null) {
    print('āŒ Android app not found in Firebase');
    return;
  }

  /// šŸ”¹ Upload SHA-1
  if (sha1 != null && sha1.isNotEmpty) {
    print('šŸš€ Adding SHA-1...');
    await run('firebase', [
      'apps:android:sha:create',
      appId,
      sha1,
      '--project=$projectId',
    ]);
  }

  /// šŸ”¹ Upload SHA-256
  if (sha256 != null && sha256.isNotEmpty) {
    print('šŸš€ Adding SHA-256...');
    await run('firebase', [
      'apps:android:sha:create',
      appId,
      sha256,
      '--project=$projectId',
    ]);
  }

  print('\nšŸŽ‰ SHA-1 & SHA-256 added successfully');
}