Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,6 @@ st.set_page_config(page_title="Android Build Server", layout="centered")
|
|
| 10 |
|
| 11 |
st.title("π± Android APK/AAB Generator")
|
| 12 |
st.markdown("Apna Android Studio Project (ZIP) upload karein aur server APK bana dega.")
|
| 13 |
-
st.warning("β οΈ Note: Project 'Build' folder free hona chahiye aur root mein 'gradlew' hona zaroori hai.")
|
| 14 |
|
| 15 |
# File Uploader
|
| 16 |
uploaded_file = st.file_uploader("Project ZIP File Upload Karein", type=["zip"])
|
|
@@ -40,7 +39,7 @@ if uploaded_file is not None:
|
|
| 40 |
|
| 41 |
progress_bar.progress(20)
|
| 42 |
|
| 43 |
-
# 3. Find root directory (
|
| 44 |
project_root = None
|
| 45 |
for root, dirs, files in os.walk("project_extract"):
|
| 46 |
if "gradlew" in files:
|
|
@@ -48,18 +47,18 @@ if uploaded_file is not None:
|
|
| 48 |
break
|
| 49 |
|
| 50 |
if not project_root:
|
| 51 |
-
st.error("β ZIP file mein 'gradlew' nahi mila.
|
| 52 |
else:
|
| 53 |
-
# 4. Permissions fix
|
| 54 |
status_text.info("Setting up Gradle environment...")
|
| 55 |
gradlew_path = os.path.join(project_root, "gradlew")
|
| 56 |
subprocess.run(["chmod", "+x", gradlew_path])
|
| 57 |
|
| 58 |
-
# 5. Build Command
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
# Subprocess chala kar build karna
|
| 63 |
try:
|
| 64 |
result = subprocess.run(
|
| 65 |
[f"./gradlew", build_type],
|
|
@@ -75,26 +74,42 @@ if uploaded_file is not None:
|
|
| 75 |
status_text.success("β
Build Successful!")
|
| 76 |
progress_bar.progress(100)
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
output_path =
|
| 80 |
file_ext = ".apk" if build_apk else ".aab"
|
| 81 |
|
| 82 |
-
|
|
|
|
| 83 |
for file in files:
|
| 84 |
-
if file.endswith(file_ext)
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
if output_path and os.path.exists(output_path):
|
|
|
|
|
|
|
|
|
|
| 89 |
with open(output_path, "rb") as f:
|
| 90 |
-
|
| 91 |
label=f"β¬οΈ Download {file_ext.upper()}",
|
| 92 |
data=f,
|
| 93 |
-
file_name=f"
|
| 94 |
mime="application/vnd.android.package-archive"
|
| 95 |
)
|
| 96 |
else:
|
| 97 |
-
st.error("Build pass hogaya
|
|
|
|
|
|
|
|
|
|
| 98 |
else:
|
| 99 |
st.error("β Build Failed!")
|
| 100 |
st.text_area("Error Log", result.stderr, height=300)
|
|
|
|
| 10 |
|
| 11 |
st.title("π± Android APK/AAB Generator")
|
| 12 |
st.markdown("Apna Android Studio Project (ZIP) upload karein aur server APK bana dega.")
|
|
|
|
| 13 |
|
| 14 |
# File Uploader
|
| 15 |
uploaded_file = st.file_uploader("Project ZIP File Upload Karein", type=["zip"])
|
|
|
|
| 39 |
|
| 40 |
progress_bar.progress(20)
|
| 41 |
|
| 42 |
+
# 3. Find root directory (Smart Find)
|
| 43 |
project_root = None
|
| 44 |
for root, dirs, files in os.walk("project_extract"):
|
| 45 |
if "gradlew" in files:
|
|
|
|
| 47 |
break
|
| 48 |
|
| 49 |
if not project_root:
|
| 50 |
+
st.error("β ZIP file mein 'gradlew' nahi mila.")
|
| 51 |
else:
|
| 52 |
+
# 4. Permissions fix
|
| 53 |
status_text.info("Setting up Gradle environment...")
|
| 54 |
gradlew_path = os.path.join(project_root, "gradlew")
|
| 55 |
subprocess.run(["chmod", "+x", gradlew_path])
|
| 56 |
|
| 57 |
+
# 5. Build Command
|
| 58 |
+
# Note: Hum 'assemble' use kar rahay hain taake agar release sign na ho to debug ban jaye
|
| 59 |
+
build_type = "assemble" if build_apk else "bundle"
|
| 60 |
+
status_text.info(f"Building Project... (Wait karein)")
|
| 61 |
|
|
|
|
| 62 |
try:
|
| 63 |
result = subprocess.run(
|
| 64 |
[f"./gradlew", build_type],
|
|
|
|
| 74 |
status_text.success("β
Build Successful!")
|
| 75 |
progress_bar.progress(100)
|
| 76 |
|
| 77 |
+
# 6. SMART SEARCH for Output File
|
| 78 |
+
output_path = None
|
| 79 |
file_ext = ".apk" if build_apk else ".aab"
|
| 80 |
|
| 81 |
+
# Pure folder mein dhoondo
|
| 82 |
+
for root, dirs, files in os.walk(project_root):
|
| 83 |
for file in files:
|
| 84 |
+
if file.endswith(file_ext):
|
| 85 |
+
# Ignore karna intermediate files ko
|
| 86 |
+
if "unaligned" in file:
|
| 87 |
+
continue
|
| 88 |
+
# Prefer release, but accept debug
|
| 89 |
+
current_file = os.path.join(root, file)
|
| 90 |
+
output_path = current_file
|
| 91 |
+
# Agar release mil jaye to loop break kardo
|
| 92 |
+
if "release" in file:
|
| 93 |
+
break
|
| 94 |
+
if output_path and "release" in output_path:
|
| 95 |
+
break
|
| 96 |
|
| 97 |
if output_path and os.path.exists(output_path):
|
| 98 |
+
file_label = "APP-RELEASE" if "release" in output_path else "APP-DEBUG"
|
| 99 |
+
st.write(f"π File Found: {os.path.basename(output_path)}")
|
| 100 |
+
|
| 101 |
with open(output_path, "rb") as f:
|
| 102 |
+
st.download_button(
|
| 103 |
label=f"β¬οΈ Download {file_ext.upper()}",
|
| 104 |
data=f,
|
| 105 |
+
file_name=f"generated-app{file_ext}",
|
| 106 |
mime="application/vnd.android.package-archive"
|
| 107 |
)
|
| 108 |
else:
|
| 109 |
+
st.error("Build pass hogaya lekin koi APK/AAB file generate nahi hui. Shayad ye Library project hai?")
|
| 110 |
+
st.warning("Check Log below:")
|
| 111 |
+
st.text_area("Build Output", result.stdout[-2000:], height=200)
|
| 112 |
+
|
| 113 |
else:
|
| 114 |
st.error("β Build Failed!")
|
| 115 |
st.text_area("Error Log", result.stderr, height=300)
|