Sjwjne commited on
Commit
419f06f
·
verified ·
1 Parent(s): ad8a299

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -11
app.py CHANGED
@@ -32,6 +32,7 @@ ANDROID_SDK_DIR = os.path.join(BASE_DIR, "android-sdk")
32
  FLUTTER_SDK_DIR = os.path.join(BASE_DIR, "flutter")
33
 
34
  def ensure_java_home():
 
35
  javac_bin = shutil.which("javac") or shutil.which("java")
36
  if javac_bin:
37
  try:
@@ -43,17 +44,32 @@ def ensure_java_home():
43
  except Exception:
44
  pass
45
 
46
- candidates = [
47
- "/usr/lib/jvm/java-17-openjdk-amd64",
48
- "/usr/lib/jvm/java-17-openjdk-arm64",
49
- "/usr/lib/jvm/java-17-openjdk",
50
- "/usr/lib/jvm/default-java",
51
- "/usr/lib/jvm/java-11-openjdk-amd64",
52
- ]
53
- for c in candidates:
54
- if os.path.exists(os.path.join(c, "bin", "java")):
55
- os.environ["JAVA_HOME"] = c
56
- return c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  return ""
58
 
59
  def init_environment():
 
32
  FLUTTER_SDK_DIR = os.path.join(BASE_DIR, "flutter")
33
 
34
  def ensure_java_home():
35
+ # 1. Try finding javac/java from system PATH
36
  javac_bin = shutil.which("javac") or shutil.which("java")
37
  if javac_bin:
38
  try:
 
44
  except Exception:
45
  pass
46
 
47
+ # 2. Check Debian JVM folder
48
+ jvm_base = "/usr/lib/jvm"
49
+ if os.path.exists(jvm_base):
50
+ for item in sorted(os.listdir(jvm_base), reverse=True):
51
+ candidate = os.path.join(jvm_base, item)
52
+ if os.path.isdir(candidate) and os.path.exists(os.path.join(candidate, "bin", "java")):
53
+ os.environ["JAVA_HOME"] = candidate
54
+ return candidate
55
+
56
+ # 3. Fallback: Download Portable OpenJDK 17 if system Java is missing
57
+ portable_jdk = os.path.join(BASE_DIR, "jdk17")
58
+ java_bin_check = os.path.join(portable_jdk, "bin", "java")
59
+ if not os.path.exists(java_bin_check):
60
+ print("⏬ System Java missing. Downloading Portable OpenJDK 17...")
61
+ tar_path = os.path.join(BASE_DIR, "openjdk17.tar.gz")
62
+ 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"
63
+ subprocess.run(["curl", "-sSL", url, "-o", tar_path])
64
+ os.makedirs(portable_jdk, exist_ok=True)
65
+ subprocess.run(["tar", "-xzf", tar_path, "-C", portable_jdk, "--strip-components=1"])
66
+ if os.path.exists(tar_path):
67
+ os.remove(tar_path)
68
+
69
+ if os.path.exists(java_bin_check):
70
+ os.environ["JAVA_HOME"] = portable_jdk
71
+ return portable_jdk
72
+
73
  return ""
74
 
75
  def init_environment():