Skip to content

Commit 7e7f372

Browse files
committed
download cmdline tools package
1 parent 88d6053 commit 7e7f372

File tree

1 file changed

+20
-37
lines changed

1 file changed

+20
-37
lines changed

mode/src/processing/mode/android/SDKDownloader.java

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
7979

8080
class SDKUrlHolder {
8181
public String platformVersion, buildToolsVersion;
82-
public String platformToolsUrl, buildToolsUrl, platformUrl, toolsUrl, emulatorUrl;
83-
public String platformToolsFilename, buildToolsFilename, platformFilename, toolsFilename, emulatorFilename;
82+
public String platformToolsUrl, buildToolsUrl, platformUrl, cmdlineToolsUrl, emulatorUrl;
83+
public String platformToolsFilename, buildToolsFilename, platformFilename, cmdlineToolsFilename, emulatorFilename;
8484
public String usbDriverUrl;
8585
public String usbDriverFilename;
8686
public String haxmFilename, haxmUrl;
@@ -128,9 +128,9 @@ protected Object doInBackground() throws Exception {
128128
getHaxmDownloadUrl(downloadUrls, haxmUrl, Platform.getName());
129129
firePropertyChange(AndroidMode.getTextString("download_property.change_event_total"), 0, downloadUrls.totalSize);
130130

131-
// tools
132-
File downloadedTools = new File(tempFolder, downloadUrls.toolsFilename);
133-
downloadAndUnpack(downloadUrls.toolsUrl, downloadedTools, sdkFolder, true);
131+
// command-line tools
132+
File downloadedCmdLineTools = new File(tempFolder, downloadUrls.cmdlineToolsFilename);
133+
downloadAndUnpack(downloadUrls.cmdlineToolsUrl, downloadedCmdLineTools, sdkFolder, true);
134134

135135
// platform-tools
136136
File downloadedPlatformTools = new File(tempFolder, downloadUrls.platformToolsFilename);
@@ -246,7 +246,7 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
246246
boolean found;
247247

248248
// -----------------------------------------------------------------------
249-
// platform
249+
// Platform
250250
expr = xpath.compile("//remotePackage[starts-with(@path, \"platforms;\")" +
251251
"and contains(@path, '" + AndroidBuild.TARGET_SDK + "')]"); // Skip latest platform; download only the targeted
252252
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
@@ -271,12 +271,12 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
271271
throw new IOException(AndroidMode.getTextString("sdk_downloader.error_cannot_find_platform_files"));
272272
}
273273

274-
// Difference between platform tools, build tools, and SDK tools:
274+
// Difference between platform tools, build tools, and SDK (now command-line) tools:
275275
// http://stackoverflow.com/questions/19911762/what-is-android-sdk-build-tools-and-which-version-should-be-used
276276
// Always get the latest!
277277

278278
// -----------------------------------------------------------------------
279-
// platform-tools
279+
// Platform tools
280280
expr = xpath.compile("//remotePackage[@path=\"platform-tools\"]");
281281
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
282282
if (remotePackages != null) {
@@ -286,7 +286,7 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
286286
}
287287

288288
// -----------------------------------------------------------------------
289-
// build-tools
289+
// Build tools
290290
expr = xpath.compile("//remotePackage[starts-with(@path, \"build-tools;\")]");
291291
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
292292
found = false;
@@ -332,14 +332,19 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
332332
}
333333

334334
// -----------------------------------------------------------------------
335-
// tools
336-
expr = xpath.compile("//remotePackage[@path=\"tools\"]"); // Matches two items according to xml file
335+
// Command-line tools
336+
// expr = xpath.compile("//remotePackage[@path=\"cmdline-tools;\"]");
337+
expr = xpath.compile("//remotePackage[starts-with(@path, \"cmdline-tools;\")]");
337338
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
338339
found = false;
339340
if (remotePackages != null) {
340341
for (int tool = 0; tool < remotePackages.getLength(); tool++) {
341342
NodeList childNodes = remotePackages.item(tool).getChildNodes();
342343

344+
NodeList channel = ((Element) childNodes).getElementsByTagName("channelRef");
345+
if(!channel.item(0).getAttributes().item(0).getNodeValue().equals("channel-0"))
346+
continue; // Stable channel only, skip others
347+
343348
NodeList archives = ((Element) childNodes).getElementsByTagName("archive");
344349
for (int i = 0; i < archives.getLength(); ++i) {
345350
NodeList archive = archives.item(i).getChildNodes();
@@ -350,45 +355,23 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
350355
NodeList size = ((Element) complete.item(0)).getElementsByTagName("size");
351356

352357
if (os.item(0).getTextContent().equals(requiredHostOs)) {
353-
urlHolder.toolsFilename = url.item(0).getTextContent();
354-
urlHolder.toolsUrl = REPOSITORY_URL + urlHolder.toolsFilename;
358+
urlHolder.cmdlineToolsFilename = url.item(0).getTextContent();
359+
urlHolder.cmdlineToolsUrl = REPOSITORY_URL + urlHolder.cmdlineToolsFilename;
355360
urlHolder.totalSize += Integer.parseInt(size.item(0).getTextContent());
356361
found = true;
357362
break;
358363
}
359364
}
360365
if (found) break;
361366
}
362-
363-
// NodeList childNodes = remotePackages.item(1).getChildNodes(); // Second item is the latest tools for now
364-
// NodeList archives = ((Element) childNodes).getElementsByTagName("archive");
365-
//
366-
// for (int i = 0; i < archives.getLength(); ++i) {
367-
// NodeList archive = archives.item(i).getChildNodes();
368-
// NodeList complete = ((Element) archive).getElementsByTagName("complete");
369-
//
370-
// NodeList os = ((Element) archive).getElementsByTagName("host-os");
371-
// NodeList url = ((Element) complete.item(0)).getElementsByTagName("url");
372-
// NodeList size = ((Element) complete.item(0)).getElementsByTagName("size");
373-
//
374-
// if (os.item(0).getTextContent().equals(requiredHostOs)) {
375-
// urlHolder.toolsFilename = url.item(0).getTextContent();
376-
// urlHolder.toolsUrl = REPOSITORY_URL + urlHolder.toolsFilename;
377-
// urlHolder.totalSize += Integer.parseInt(size.item(0).getTextContent());
378-
// found = true;
379-
// break;
380-
// }
381-
// }
382-
383-
384367
}
385368
if (!found) {
386369
throw new IOException(AndroidMode.getTextString("sdk_downloader.error_cannot_find_tools"));
387370
}
388371

389372
// -----------------------------------------------------------------------
390-
// emulator
391-
expr = xpath.compile("//remotePackage[@path=\"emulator\"]"); // Matches two items according to xml file
373+
// Emulator
374+
expr = xpath.compile("//remotePackage[@path=\"emulator\"]");
392375
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
393376
found = false;
394377
if (remotePackages != null) {

0 commit comments

Comments
 (0)