File size: 949 Bytes
e93c08a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
import tempfile
import os

def build_apk(pwa_url):
    with tempfile.TemporaryDirectory() as tmpdir:
        os.chdir(tmpdir)
        try:
            result = subprocess.run(
                ["npx", "create-bubblewrap", "--manifest", f"{pwa_url}", "--directory", "."],
                capture_output=True, text=True
            )
            if result.returncode != 0:
                return f"Bubblewrap error: {result.stderr}"
            subprocess.run(["./gradlew", "assembleRelease"], capture_output=True)
            apk_path = "app/build/outputs/apk/release/app-release.apk"
            if os.path.exists(apk_path):
                return apk_path
            else:
                return "APK build failed or APK not found."
        except Exception as e:
            return f"Error: {str(e)}"

demo = gr.Interface(fn=build_apk, inputs="text", outputs="text", title="PWA to APK Builder")
demo.launch()