@@ -81,8 +81,8 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
81
81
82
82
class SDKUrlHolder {
83
83
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 ;
86
86
public String supportRepoUrl , googleRepoUrl , usbDriverUrl ;
87
87
public String supportRepoFilename , googleRepoFilename , usbDriverFilename ;
88
88
public int totalSize = 0 ;
@@ -106,6 +106,8 @@ protected Object doInBackground() throws Exception {
106
106
if (!platformsFolder .exists ()) platformsFolder .mkdir ();
107
107
File buildToolsFolder = new File (sdkFolder , "build-tools" );
108
108
if (!buildToolsFolder .exists ()) buildToolsFolder .mkdir ();
109
+ File emulatorFolder = new File (sdkFolder , "emulator" );
110
+ if (!emulatorFolder .exists ()) emulatorFolder .mkdir ();
109
111
File extrasFolder = new File (sdkFolder , "extras" );
110
112
if (!extrasFolder .exists ()) extrasFolder .mkdir ();
111
113
File googleRepoFolder = new File (extrasFolder , "google" );
@@ -140,6 +142,10 @@ protected Object doInBackground() throws Exception {
140
142
// platform
141
143
File downloadedPlatform = new File (tempFolder , downloadUrls .platformFilename );
142
144
downloadAndUnpack (downloadUrls .platformUrl , downloadedPlatform , platformsFolder , false );
145
+
146
+ // emulator
147
+ File downloadedEmulator = new File (tempFolder , downloadUrls .emulatorFilename );
148
+ downloadAndUnpack (downloadUrls .emulatorUrl , downloadedEmulator , emulatorFolder , true );
143
149
144
150
// google repository
145
151
File downloadedGoogleRepo = new File (tempFolder , downloadUrls .googleRepoFilename );
@@ -347,7 +353,42 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
347
353
}
348
354
} else {
349
355
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
+ }
351
392
}
352
393
}
353
394
0 commit comments