overwriteAndroidManifestWithNewLauncherIcon function

Future<void> overwriteAndroidManifestWithNewLauncherIcon(
  1. String iconName,
  2. File androidManifestFile
)

Updates the line which specifies the launcher icon within the AndroidManifest.xml with the new icon name (only if it has changed)

Note: default iconName = "ic_launcher"

Implementation

Future<void> overwriteAndroidManifestWithNewLauncherIcon(
  String iconName,
  File androidManifestFile,
) async {
  // we do not use `file.readAsLinesSync()` here because that always gets rid of the last empty newline
  final List<String> oldManifestLines =
      (await androidManifestFile.readAsString()).split('\n');
  final List<String> transformedLines =
      _transformAndroidManifestWithNewLauncherIcon(oldManifestLines, iconName);
  await androidManifestFile.writeAsString(transformedLines.join('\n'));
}