Request for AndroidManifest Editor in FlutterFlow

Project Settings

I've run into a challenge while working on my FlutterFlow project that I think many others might face too. I needed to add specific tags (like android:usesCleartextTraffic="true") to the AndroidManifest.xml file for my Android project, but FlutterFlow doesn’t currently offer a way to edit this file directly.

To work around this, I developed a script that monitors and updates the manifest file with the necessary tags. While this works, it’s not ideal for long-term use and may be challenging for those less comfortable with scripting.

Suggestion:

Could we get an integrated AndroidManifest editor within FlutterFlow?

What have you tried so far?
import time
import os
import re

# Path to the AndroidManifest.xml file
manifest_path = "AndroidManifest.xml"

# Content to check for
search_pattern = re.compile(r'<application[\s\S]*?android:label[\s\S]*?>')
replace_content = r'<application\n    android:label="APTV"\n    tools:replace="android:label"\n    android:icon="@mipmap/ic_launcher"\n    android:requestLegacyExternalStorage="true"\n    android:usesCleartextTraffic="true">'

def check_and_replace():
    if not os.path.exists(manifest_path):
        print(f"Manifest file not found at {manifest_path}")
        return

    with open(manifest_path, 'r') as file:
        content = file.read()

    if search_pattern.search(content):
        if 'android:usesCleartextTraffic="true"' not in content:
            print("Updating the manifest file to include android:usesCleartextTraffic=\"true\"")
            updated_content = search_pattern.sub(replace_content, content)
            with open(manifest_path, 'w') as file:
                file.write(updated_content)
            print("Manifest file updated.")
        else:
            print("Manifest file already contains android:usesCleartextTraffic=\"true\"")
    else:
        print("The <application> tag with the required label was not found.")

def monitor_file():
    last_modified_time = os.path.getmtime(manifest_path)

    while True:
        try:
            current_modified_time = os.path.getmtime(manifest_path)
            if current_modified_time != last_modified_time:
                print("Manifest file has been modified.")
                check_and_replace()
                last_modified_time = current_modified_time

            time.sleep(0.5)  # Check every 5 seconds
        except KeyboardInterrupt:
            print("File monitoring stopped.")
            break

if __name__ == "__main__":
    check_and_replace()  # Ensure it's correct before starting the monitoring
    monitor_file()
Did you check FlutterFlow's Documentation for this topic?
No
9
1 reply