findAndroidManifest static method

File? findAndroidManifest(
  1. String projectPath,
  2. ProjectType projectType
)

Find AndroidManifest.xml for Android/Flutter projects

Implementation

static File? findAndroidManifest(
  String projectPath,
  ProjectType projectType,
) {
  if (projectType == ProjectType.flutter ||
      projectType == ProjectType.reactNative) {
    // Flutter and React Native share the same Android manifest location.
    final manifestPath = path.join(
      projectPath,
      'android',
      'app',
      'src',
      'main',
      'AndroidManifest.xml',
    );
    final file = File(manifestPath);
    if (file.existsSync()) return file;
  } else if (projectType == ProjectType.android) {
    // For pure Android projects, check standard source locations first
    // Standard locations: app/src/main/AndroidManifest.xml or src/main/AndroidManifest.xml
    final standardPaths = [
      path.join(projectPath, 'app', 'src', 'main', 'AndroidManifest.xml'),
      path.join(projectPath, 'src', 'main', 'AndroidManifest.xml'),
    ];

    for (final manifestPath in standardPaths) {
      final file = File(manifestPath);
      if (file.existsSync()) {
        return file;
      }
    }

    // Fallback: Search recursively for AndroidManifest.xml (excluding build outputs)
    final dir = Directory(projectPath);
    final files = dir.listSync(recursive: true).whereType<File>();
    for (final file in files) {
      if (file.path.endsWith('AndroidManifest.xml') &&
          !file.path.contains('.gradle') &&
          !file.path.contains('build') &&
          file.path.contains('src') &&
          file.path.contains('main')) {
        return file;
      }
    }
  }
  return null;
}