readAndroidApplicationId function

String? readAndroidApplicationId(
  1. String projectRoot
)

The applicationId in the project's android/app/build.gradle(.kts), or null when there isn't one.

Implementation

String? readAndroidApplicationId(String projectRoot) {
  for (final String name in ['build.gradle.kts', 'build.gradle']) {
    final File file = File('$projectRoot/android/app/$name');
    if (!file.existsSync()) continue;
    final RegExpMatch? match = RegExp(
      r'''applicationId\s*=?\s*["']([^"']+)["']''',
    ).firstMatch(file.readAsStringSync());
    if (match != null) return match.group(1);
  }
  return null;
}