@@ -52,6 +52,7 @@ async def check_status() -> bool:
5252
5353 if java_path .exists ():
5454 print ("[installer][android-java] Already installed" )
55+
5556 await send_response ({
5657 "action" : "status" ,
5758 "data" : {
@@ -107,29 +108,59 @@ def update_java_path():
107108
108109
109110async def _get_jdk_download_url ():
110- """Get the appropriate JDK 21 LTS download URL based on platform"""
111+ """Get the appropriate JDK 21 LTS download URL from Eclipse Temurin (Adoptium) based on platform"""
111112 system = platform .system ()
112113
114+ # Map platform to Temurin API format
113115 if system == "Windows" :
114- return "https://download.oracle.com/java/21/latest/jdk-21_windows-x64_bin.zip "
116+ os_name = "windows "
115117 elif system == "Linux" :
116- return "https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz "
118+ os_name = "linux "
117119 elif system == "Darwin" :
118- # macOS - use ARM64 for Apple Silicon or x64 for Intel
119- import subprocess
120- try :
121- # Check if running on Apple Silicon
122- result = subprocess .run (["uname" , "-m" ], capture_output = True , text = True )
123- arch = result .stdout .strip ()
124- if arch == "arm64" :
125- return "https://download.oracle.com/java/21/latest/jdk-21_macos-aarch64_bin.tar.gz"
126- else :
127- return "https://download.oracle.com/java/21/latest/jdk-21_macos-x64_bin.tar.gz"
128- except :
129- # Default to x64 if detection fails
130- return "https://download.oracle.com/java/21/latest/jdk-21_macos-x64_bin.tar.gz"
120+ os_name = "mac"
131121 else :
132122 raise OSError (f"Unsupported platform: { system } " )
123+
124+ # Detect machine architecture dynamically (Temurin supports: x64, aarch64, ppc64, ppc64le, riscv64, s390x)
125+ machine = platform .machine ().lower ()
126+
127+ # Map common architecture names to Temurin format
128+ if machine in ["x86_64" , "amd64" , "x64" ]:
129+ arch = "x64"
130+ elif machine in ["aarch64" , "arm64" ]:
131+ arch = "aarch64"
132+ elif machine in ["ppc64le" ]:
133+ arch = "ppc64le"
134+ elif machine in ["ppc64" ]:
135+ arch = "ppc64"
136+ elif machine in ["riscv64" ]:
137+ arch = "riscv64"
138+ elif machine in ["s390x" ]:
139+ arch = "s390x"
140+ else :
141+ # Default to x64 for unknown architectures
142+ print (f"[installer][android-java] Warning: Unknown architecture '{ machine } ', defaulting to x64" )
143+ arch = "x64"
144+
145+ # Use Temurin metadata API to get latest JDK 21 download URL
146+ api_url = f"https://api.adoptium.net/v3/assets/latest/21/hotspot?os={ os_name } &architecture={ arch } &image_type=jdk&vendor=eclipse"
147+
148+ try :
149+ async with httpx .AsyncClient (timeout = 30.0 ) as client :
150+ response = await client .get (api_url )
151+ response .raise_for_status ()
152+ data = response .json ()
153+
154+ # Extract download URL from API response
155+ if data and len (data ) > 0 :
156+ download_url = data [0 ]["binary" ]["package" ]["link" ]
157+ print (f"[installer][android-java] Found Temurin JDK 21 download URL: { download_url } " )
158+ return download_url
159+ else :
160+ raise Exception ("No download URL found in API response" )
161+ except Exception as e :
162+ print (f"[installer][android-java] Error fetching Temurin download URL: { e } " )
163+ raise Exception (f"Failed to get JDK download URL from Temurin API: { e } " )
133164
134165
135166async def _download_jdk ():
@@ -162,7 +193,7 @@ async def _download_jdk():
162193 try :
163194 jdk_archive .parent .mkdir (parents = True , exist_ok = True )
164195
165- async with httpx .AsyncClient (timeout = 900.0 ) as client :
196+ async with httpx .AsyncClient (timeout = 900.0 , follow_redirects = True ) as client :
166197 async with client .stream ("GET" , jdk_url ) as response :
167198 response .raise_for_status ()
168199
0 commit comments