Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,7 +49,7 @@ def ensure_java_17():
|
|
| 49 |
os.environ["JAVA_HOME"] = candidate
|
| 50 |
return candidate
|
| 51 |
|
| 52 |
-
# 3. Download official Portable Eclipse Temurin OpenJDK 17
|
| 53 |
print("⏬ Downloading Portable OpenJDK 17...")
|
| 54 |
tar_path = os.path.join(BASE_DIR, "openjdk17.tar.gz")
|
| 55 |
url = "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.10%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz"
|
|
@@ -65,11 +65,43 @@ def ensure_java_17():
|
|
| 65 |
|
| 66 |
return JDK17_DIR
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
def init_environment():
|
| 69 |
jh = ensure_java_17()
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
if not os.path.exists(os.path.join(ANDROID_SDK_DIR, "
|
| 73 |
os.makedirs(os.path.join(ANDROID_SDK_DIR, "cmdline-tools"), exist_ok=True)
|
| 74 |
cmdline_zip = os.path.join(BASE_DIR, "cmdline-tools.zip")
|
| 75 |
if not os.path.exists(cmdline_zip):
|
|
@@ -87,21 +119,20 @@ def init_environment():
|
|
| 87 |
if os.path.exists(extracted):
|
| 88 |
os.rename(extracted, latest_dir)
|
| 89 |
|
| 90 |
-
|
| 91 |
-
os.makedirs(licenses_dir, exist_ok=True)
|
| 92 |
-
with open(os.path.join(licenses_dir, "android-sdk-license"), "w") as f:
|
| 93 |
-
f.write("89339e07016797db24746821d3c08014720e16d6\n24333f8a63718c1d52020f9179642b1b78f45a16\nd56f5185613260f44591ec063804d007606a46c5\n")
|
| 94 |
|
| 95 |
sdkmanager = os.path.join(latest_dir, "bin", "sdkmanager")
|
| 96 |
if os.path.exists(sdkmanager):
|
| 97 |
subprocess.run(["chmod", "+x", sdkmanager])
|
| 98 |
-
print("⏬ Installing Android SDK 33 & Build
|
| 99 |
subprocess.run([
|
| 100 |
sdkmanager, f"--sdk_root={ANDROID_SDK_DIR}",
|
| 101 |
-
"platform-tools", "platforms;android-33", "build-tools;33.0.2"
|
| 102 |
], capture_output=True, text=True)
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
if not os.path.exists(os.path.join(FLUTTER_SDK_DIR, "bin", "flutter")):
|
| 106 |
print("⏬ Downloading Flutter SDK...")
|
| 107 |
subprocess.run([
|
|
@@ -119,7 +150,8 @@ def init_environment():
|
|
| 119 |
os.path.join(FLUTTER_SDK_DIR, "bin"),
|
| 120 |
os.path.join(ANDROID_SDK_DIR, "cmdline-tools", "latest", "bin"),
|
| 121 |
os.path.join(ANDROID_SDK_DIR, "platform-tools"),
|
| 122 |
-
os.path.join(ANDROID_SDK_DIR, "build-tools", "33.0.2")
|
|
|
|
| 123 |
]
|
| 124 |
for a in additions:
|
| 125 |
if a and a not in path_env:
|
|
|
|
| 49 |
os.environ["JAVA_HOME"] = candidate
|
| 50 |
return candidate
|
| 51 |
|
| 52 |
+
# 3. Download official Portable Eclipse Temurin OpenJDK 17
|
| 53 |
print("⏬ Downloading Portable OpenJDK 17...")
|
| 54 |
tar_path = os.path.join(BASE_DIR, "openjdk17.tar.gz")
|
| 55 |
url = "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.10%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz"
|
|
|
|
| 65 |
|
| 66 |
return JDK17_DIR
|
| 67 |
|
| 68 |
+
def auto_accept_licenses():
|
| 69 |
+
licenses_dir = os.path.join(ANDROID_SDK_DIR, "licenses")
|
| 70 |
+
os.makedirs(licenses_dir, exist_ok=True)
|
| 71 |
+
|
| 72 |
+
all_sdk_hashes = [
|
| 73 |
+
"89339e07016797db24746821d3c08014720e16d6",
|
| 74 |
+
"24333f8a63718c1d52020f9179642b1b78f45a16",
|
| 75 |
+
"d56f5185613260f44591ec063804d007606a46c5",
|
| 76 |
+
"84831b9409646a918e30573bab4c9c91346d8abd",
|
| 77 |
+
"601007b946f40b2a2617ff2b29d5005b87327787",
|
| 78 |
+
"33b622e746b070b80521630d8245e05131926e59"
|
| 79 |
+
]
|
| 80 |
+
with open(os.path.join(licenses_dir, "android-sdk-license"), "w") as f:
|
| 81 |
+
f.write("\n".join(all_sdk_hashes) + "\n")
|
| 82 |
+
|
| 83 |
+
with open(os.path.join(licenses_dir, "android-googletv-license"), "w") as f:
|
| 84 |
+
f.write("601007b946f40b2a2617ff2b29d5005b87327787\n")
|
| 85 |
+
|
| 86 |
+
sdkmanager = os.path.join(ANDROID_SDK_DIR, "cmdline-tools", "latest", "bin", "sdkmanager")
|
| 87 |
+
if os.path.exists(sdkmanager):
|
| 88 |
+
try:
|
| 89 |
+
p = subprocess.Popen(["yes"], stdout=subprocess.PIPE)
|
| 90 |
+
subprocess.run(
|
| 91 |
+
[sdkmanager, f"--sdk_root={ANDROID_SDK_DIR}", "--licenses"],
|
| 92 |
+
stdin=p.stdout,
|
| 93 |
+
stdout=subprocess.DEVNULL,
|
| 94 |
+
stderr=subprocess.DEVNULL
|
| 95 |
+
)
|
| 96 |
+
p.stdout.close()
|
| 97 |
+
except Exception:
|
| 98 |
+
pass
|
| 99 |
+
|
| 100 |
def init_environment():
|
| 101 |
jh = ensure_java_17()
|
| 102 |
|
| 103 |
+
# Setup Android SDK 33 and all required Build-Tools (including 30.0.3)
|
| 104 |
+
if not os.path.exists(os.path.join(ANDROID_SDK_DIR, "build-tools", "30.0.3")):
|
| 105 |
os.makedirs(os.path.join(ANDROID_SDK_DIR, "cmdline-tools"), exist_ok=True)
|
| 106 |
cmdline_zip = os.path.join(BASE_DIR, "cmdline-tools.zip")
|
| 107 |
if not os.path.exists(cmdline_zip):
|
|
|
|
| 119 |
if os.path.exists(extracted):
|
| 120 |
os.rename(extracted, latest_dir)
|
| 121 |
|
| 122 |
+
auto_accept_licenses()
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
sdkmanager = os.path.join(latest_dir, "bin", "sdkmanager")
|
| 125 |
if os.path.exists(sdkmanager):
|
| 126 |
subprocess.run(["chmod", "+x", sdkmanager])
|
| 127 |
+
print("⏬ Installing Android SDK 33 & Build-Tools (30.0.3, 33.0.2)...")
|
| 128 |
subprocess.run([
|
| 129 |
sdkmanager, f"--sdk_root={ANDROID_SDK_DIR}",
|
| 130 |
+
"platform-tools", "platforms;android-33", "build-tools;33.0.2", "build-tools;30.0.3"
|
| 131 |
], capture_output=True, text=True)
|
| 132 |
|
| 133 |
+
auto_accept_licenses()
|
| 134 |
+
|
| 135 |
+
# Setup Flutter SDK if missing
|
| 136 |
if not os.path.exists(os.path.join(FLUTTER_SDK_DIR, "bin", "flutter")):
|
| 137 |
print("⏬ Downloading Flutter SDK...")
|
| 138 |
subprocess.run([
|
|
|
|
| 150 |
os.path.join(FLUTTER_SDK_DIR, "bin"),
|
| 151 |
os.path.join(ANDROID_SDK_DIR, "cmdline-tools", "latest", "bin"),
|
| 152 |
os.path.join(ANDROID_SDK_DIR, "platform-tools"),
|
| 153 |
+
os.path.join(ANDROID_SDK_DIR, "build-tools", "33.0.2"),
|
| 154 |
+
os.path.join(ANDROID_SDK_DIR, "build-tools", "30.0.3")
|
| 155 |
]
|
| 156 |
for a in additions:
|
| 157 |
if a and a not in path_env:
|