File size: 3,501 Bytes
5edc6a5
f3bc981
d475e29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5edc6a5
f3bc981
5edc6a5
d475e29
 
 
 
f3bc981
 
5edc6a5
f3bc981
 
 
 
 
 
5edc6a5
f3bc981
 
5edc6a5
f3bc981
 
5edc6a5
f3bc981
5edc6a5
 
f3bc981
5edc6a5
 
 
 
 
f3bc981
5edc6a5
 
f3bc981
 
5edc6a5
f3bc981
 
5edc6a5
 
f3bc981
 
5edc6a5
f3bc981
 
5edc6a5
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import subprocess
import gradio as gr
import platform
import os

def install_flutter():
    if platform.system() == "Windows":
        # Download the Flutter installation bundle
        subprocess.check_call(["powershell", "curl", "-o", "flutter_windows_stable.zip", "https://storage.googleapis.com/flutter_infra/releases/stable/windows/flutter_windows_stable.zip"])
        
        # Extract the zip file
        subprocess.check_call(["powershell", "Expand-Archive", "-Path", "flutter_windows_stable.zip", "-DestinationPath", "C:\\src\\flutter"])
        
        # Update the system's PATH environment variable
        subprocess.check_call(["powershell", "setx", "PATH", "%PATH%;C:\\src\\flutter\\bin"])
        
    elif platform.system() == "Darwin":  # macOS
        # Install Flutter using Homebrew
        subprocess.check_call(["brew", "install", "--cask", "flutter"])
        
    elif platform.system() == "Linux":
        # Download the Flutter installation bundle
        subprocess.check_call(["wget", "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_stable.tar.xz"])
        
        # Extract the tar file
        subprocess.check_call(["tar", "xvf", "flutter_linux_stable.tar.xz", "-C", "~/development/"])
        
        # Update the system's PATH environment variable
        with open(os.path.expanduser("~/.bashrc"), "a") as f:
            f.write("export PATH=$PATH:~/development/flutter/bin")
        
        subprocess.check_call(["source", "~/.bashrc"])

def build_android_app(app_name, package_name, website_url, app_logo):
    try:
        # Install Flutter if it's not already installed
        if not subprocess.check_output(["which", "flutter"]).decode("utf-8"):
            install_flutter()
        
        # Create a new Android app
        subprocess.check_call(["flutter", "create", app_name])
        
        # Configure the app
        with open(f"{app_name}/pubspec.yaml", "r+") as f:
            content = f.read()
            f.seek(0)
            f.write(content.replace("name: flutter_app", f"name: {app_name}").replace("description: A new Flutter project.", f"description: {website_url}").replace("# The following line ensures that the Material Icons font is\n  # included with your application, so that you can use the icons in\n  # the material Icons class.", f"  flutter:\n    assets:\n      - {app_logo}"))
            f.truncate()
        
        # Install dependencies
        subprocess.check_call(["flutter", "pub", "get"], cwd=app_name)
        
        # Run the app
        subprocess.check_call(["flutter", "run"], cwd=app_name)
        
        return "App built successfully."
    
    except Exception as e:
        return f"Error: {str(e)}"

# Gradio interface setup
demo = gr.Blocks()

with demo:
    gr.Markdown("## Android App Builder\nEnter your app details to build an Android app")
    
    with gr.Row():
        app_name = gr.Textbox(label="App Name")
        package_name = gr.Textbox(label="Package Name")
    
    website_url = gr.Textbox(label="Website URL")
    app_logo = gr.Textbox(label="App Logo")
    output = gr.Textbox(label="Output", placeholder="Output will appear here", lines=10)

    # Button to trigger app building
    build_button = gr.Button("Build App")
    
    # Bind the button to the function that builds the app
    build_button.click(fn=build_android_app, inputs=[app_name, package_name, website_url, app_logo], outputs=output)

# Launch the Gradio app
demo.launch()