detectAndroidPackageName method
Configures FlutterFire for the current project using the
provided projectId.
Includes exponential backoff retry logic to handle cases where a newly created project's API hasn't propagated across Google's backend yet.
The platforms parameter specifies which platforms to configure
(e.g., 'android', 'ios', 'macos', 'web', 'windows').
Detects the default Android package name from android/app/build.gradle.
Implementation
String? detectAndroidPackageName() {
try {
final file = File('android/app/build.gradle');
if (!file.existsSync()) return null;
final content = file.readAsStringSync();
// Match: applicationId "com.example" or applicationId = "com.example"
final match = RegExp(r'''applicationId\s*=?\s*["']([^"']+)["']''').firstMatch(content);
if (match != null) {
return match.group(1);
}
} catch (e) {
print('⚠️ Failed to detect Android package name: $e');
}
return null;
}