Skip to content

Commit 5bd250e

Browse files
committed
SDKDownloader : download emulator package
1 parent 23881bc commit 5bd250e

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

src/processing/mode/android/SDKDownloader.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
8181

8282
class SDKUrlHolder {
8383
public String platformVersion, buildToolsVersion;
84-
public String platformToolsUrl, buildToolsUrl, platformUrl, toolsUrl;
85-
public String platformToolsFilename, buildToolsFilename, platformFilename, toolsFilename;
84+
public String platformToolsUrl, buildToolsUrl, platformUrl, toolsUrl, emulatorUrl;
85+
public String platformToolsFilename, buildToolsFilename, platformFilename, toolsFilename, emulatorFilename;
8686
public String supportRepoUrl, googleRepoUrl, usbDriverUrl;
8787
public String supportRepoFilename, googleRepoFilename, usbDriverFilename;
8888
public int totalSize = 0;
@@ -106,6 +106,8 @@ protected Object doInBackground() throws Exception {
106106
if (!platformsFolder.exists()) platformsFolder.mkdir();
107107
File buildToolsFolder = new File(sdkFolder, "build-tools");
108108
if (!buildToolsFolder.exists()) buildToolsFolder.mkdir();
109+
File emulatorFolder = new File(sdkFolder, "emulator");
110+
if (!emulatorFolder.exists()) emulatorFolder.mkdir();
109111
File extrasFolder = new File(sdkFolder, "extras");
110112
if (!extrasFolder.exists()) extrasFolder.mkdir();
111113
File googleRepoFolder = new File(extrasFolder, "google");
@@ -140,6 +142,10 @@ protected Object doInBackground() throws Exception {
140142
// platform
141143
File downloadedPlatform = new File(tempFolder, downloadUrls.platformFilename);
142144
downloadAndUnpack(downloadUrls.platformUrl, downloadedPlatform, platformsFolder, false);
145+
146+
// emulator
147+
File downloadedEmulator = new File(tempFolder, downloadUrls.emulatorFilename);
148+
downloadAndUnpack(downloadUrls.emulatorUrl, downloadedEmulator, emulatorFolder, true);
143149

144150
// google repository
145151
File downloadedGoogleRepo = new File(tempFolder, downloadUrls.googleRepoFilename);
@@ -347,7 +353,42 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
347353
}
348354
} else {
349355
throw new IOException("Cannot find the tools");
350-
}
356+
}
357+
358+
// -----------------------------------------------------------------------
359+
// emulator
360+
expr = xpath.compile("//remotePackage[@path=\"emulator\"]"); //Matches two items according to xml file
361+
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
362+
if (remotePackages != null) {
363+
for(int i = 0; i < remotePackages.getLength(); ++i) {
364+
NodeList childNodes = remotePackages.item(i).getChildNodes();
365+
366+
NodeList channel = ((Element) childNodes).getElementsByTagName("channelRef");
367+
if(!channel.item(0).getAttributes().item(0).getNodeValue().equals("channel-0"))
368+
continue; //Stable channel only, skip others
369+
370+
NodeList archives = ((Element) childNodes).getElementsByTagName("archive");
371+
372+
for (int j = 0; j < archives.getLength(); ++j) {
373+
NodeList archive = archives.item(j).getChildNodes();
374+
NodeList complete = ((Element) archive).getElementsByTagName("complete");
375+
376+
NodeList os = ((Element) archive).getElementsByTagName("host-os");
377+
NodeList url = ((Element) complete.item(0)).getElementsByTagName("url");
378+
NodeList size = ((Element) complete.item(0)).getElementsByTagName("size");
379+
380+
if (os.item(0).getTextContent().equals(requiredHostOs)) {
381+
urlHolder.emulatorFilename = url.item(0).getTextContent();
382+
urlHolder.emulatorUrl = REPOSITORY_URL + urlHolder.emulatorFilename;
383+
urlHolder.totalSize += Integer.parseInt(size.item(0).getTextContent());
384+
break;
385+
}
386+
}
387+
break;
388+
}
389+
} else {
390+
throw new IOException("Cannot find the emulator");
391+
}
351392
}
352393
}
353394

0 commit comments

Comments
 (0)