setNewBundleName function

String setNewBundleName(
  1. Context context,
  2. String manifestFileData,
  3. String currentBundleName,
  4. String desiredBundleName,
)

Implementation

String setNewBundleName(Context context, String manifestFileData,
    String currentBundleName, String desiredBundleName) {
  final parsed = XmlDocument.parse(manifestFileData);
  final application = parsed.findAllElements("application").toList()[0];
  final List<String> label = application.attributes
      .where((attrib) => attrib.toString().contains("android:label"))
      .map((i) => i.toString())
      .toList();
  if (label.isEmpty) {
    throw Exception(
        "Could not find android:label in ${context.androidManifestPath}");
  }

  final String updatedManifestData = manifestFileData.replaceAll(
      currentBundleName, 'android:label="${desiredBundleName}"');

  return updatedManifestData;
}