@@ -62,6 +62,7 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
62
62
private static final int USB_DRIVER = 6 ;
63
63
64
64
private static final String REPOSITORY_URL = "https://dl.google.com/android/repository/" ;
65
+ private static final String HAXM_URL = "https://dl.google.com/android/repository/extras/intel/" ;
65
66
private static final String REPOSITORY_LIST = "repository2-1.xml" ;
66
67
private static final String ADDON_LIST = "addon2-1.xml" ;
67
68
@@ -81,10 +82,11 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
81
82
82
83
class SDKUrlHolder {
83
84
public String platformVersion , buildToolsVersion ;
84
- public String platformToolsUrl , buildToolsUrl , platformUrl , toolsUrl ;
85
- public String platformToolsFilename , buildToolsFilename , platformFilename , toolsFilename ;
85
+ public String platformToolsUrl , buildToolsUrl , platformUrl , toolsUrl , emulatorUrl ;
86
+ public String platformToolsFilename , buildToolsFilename , platformFilename , toolsFilename , emulatorFilename ;
86
87
public String supportRepoUrl , googleRepoUrl , usbDriverUrl ;
87
- public String supportRepoFilename , googleRepoFilename , usbDriverFilename ;
88
+ public String supportRepoFilename , googleRepoFilename , usbDriverFilename ;
89
+ public String haxmFilename , haxmUrl ;
88
90
public int totalSize = 0 ;
89
91
}
90
92
@@ -106,6 +108,8 @@ protected Object doInBackground() throws Exception {
106
108
if (!platformsFolder .exists ()) platformsFolder .mkdir ();
107
109
File buildToolsFolder = new File (sdkFolder , "build-tools" );
108
110
if (!buildToolsFolder .exists ()) buildToolsFolder .mkdir ();
111
+ File emulatorFolder = new File (sdkFolder , "emulator" );
112
+ if (!emulatorFolder .exists ()) emulatorFolder .mkdir ();
109
113
File extrasFolder = new File (sdkFolder , "extras" );
110
114
if (!extrasFolder .exists ()) extrasFolder .mkdir ();
111
115
File googleRepoFolder = new File (extrasFolder , "google" );
@@ -120,9 +124,11 @@ protected Object doInBackground() throws Exception {
120
124
try {
121
125
SDKUrlHolder downloadUrls = new SDKUrlHolder ();
122
126
String repositoryUrl = REPOSITORY_URL + REPOSITORY_LIST ;
123
- String addonUrl = REPOSITORY_URL + ADDON_LIST ;
127
+ String addonUrl = REPOSITORY_URL + ADDON_LIST ;
128
+ String haxmUrl = HAXM_URL + ADDON_LIST ;
124
129
getMainDownloadUrls (downloadUrls , repositoryUrl , Platform .getName ());
125
130
getExtrasDownloadUrls (downloadUrls , addonUrl , Platform .getName ());
131
+ getHaxmDownloadUrl (downloadUrls , haxmUrl , Platform .getName ());
126
132
firePropertyChange (PROPERTY_CHANGE_EVENT_TOTAL , 0 , downloadUrls .totalSize );
127
133
128
134
// tools
@@ -140,6 +146,10 @@ protected Object doInBackground() throws Exception {
140
146
// platform
141
147
File downloadedPlatform = new File (tempFolder , downloadUrls .platformFilename );
142
148
downloadAndUnpack (downloadUrls .platformUrl , downloadedPlatform , platformsFolder , false );
149
+
150
+ // emulator
151
+ File downloadedEmulator = new File (tempFolder , downloadUrls .emulatorFilename );
152
+ downloadAndUnpack (downloadUrls .emulatorUrl , downloadedEmulator , emulatorFolder , true );
143
153
144
154
// google repository
145
155
File downloadedGoogleRepo = new File (tempFolder , downloadUrls .googleRepoFilename );
@@ -155,6 +165,22 @@ protected Object doInBackground() throws Exception {
155
165
downloadAndUnpack (downloadUrls .usbDriverUrl , downloadedFolder , googleRepoFolder , false );
156
166
}
157
167
168
+ // HAXM
169
+ if (!Platform .isLinux ()) {
170
+ File downloadedFolder = new File (tempFolder , downloadUrls .haxmFilename );
171
+ File haxmFolder = new File (tempFolder , "HAXM" );
172
+ downloadAndUnpack (downloadUrls .haxmUrl , downloadedFolder , haxmFolder , true );
173
+
174
+ ProcessBuilder pb ;
175
+ if (Platform .isWindows ())
176
+ pb = new ProcessBuilder ("cmd.exe" , "/c" , "start" , "silent_install.bat" );
177
+ else
178
+ pb = new ProcessBuilder ("silent_install.sh" );
179
+
180
+ pb .directory (haxmFolder );
181
+ pb .start ().waitFor ();
182
+ }
183
+
158
184
if (Platform .isLinux () || Platform .isMacOS ()) {
159
185
Runtime .getRuntime ().exec ("chmod -R 755 " + sdkFolder .getAbsolutePath ());
160
186
}
@@ -347,7 +373,42 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
347
373
}
348
374
} else {
349
375
throw new IOException ("Cannot find the tools" );
350
- }
376
+ }
377
+
378
+ // -----------------------------------------------------------------------
379
+ // emulator
380
+ expr = xpath .compile ("//remotePackage[@path=\" emulator\" ]" ); //Matches two items according to xml file
381
+ remotePackages = (NodeList ) expr .evaluate (doc , XPathConstants .NODESET );
382
+ if (remotePackages != null ) {
383
+ for (int i = 0 ; i < remotePackages .getLength (); ++i ) {
384
+ NodeList childNodes = remotePackages .item (i ).getChildNodes ();
385
+
386
+ NodeList channel = ((Element ) childNodes ).getElementsByTagName ("channelRef" );
387
+ if (!channel .item (0 ).getAttributes ().item (0 ).getNodeValue ().equals ("channel-0" ))
388
+ continue ; //Stable channel only, skip others
389
+
390
+ NodeList archives = ((Element ) childNodes ).getElementsByTagName ("archive" );
391
+
392
+ for (int j = 0 ; j < archives .getLength (); ++j ) {
393
+ NodeList archive = archives .item (j ).getChildNodes ();
394
+ NodeList complete = ((Element ) archive ).getElementsByTagName ("complete" );
395
+
396
+ NodeList os = ((Element ) archive ).getElementsByTagName ("host-os" );
397
+ NodeList url = ((Element ) complete .item (0 )).getElementsByTagName ("url" );
398
+ NodeList size = ((Element ) complete .item (0 )).getElementsByTagName ("size" );
399
+
400
+ if (os .item (0 ).getTextContent ().equals (requiredHostOs )) {
401
+ urlHolder .emulatorFilename = url .item (0 ).getTextContent ();
402
+ urlHolder .emulatorUrl = REPOSITORY_URL + urlHolder .emulatorFilename ;
403
+ urlHolder .totalSize += Integer .parseInt (size .item (0 ).getTextContent ());
404
+ break ;
405
+ }
406
+ }
407
+ break ;
408
+ }
409
+ } else {
410
+ throw new IOException ("Cannot find the emulator" );
411
+ }
351
412
}
352
413
}
353
414
@@ -388,6 +449,46 @@ private void getExtrasDownloadUrls(SDKUrlHolder urlHolder,
388
449
}
389
450
}
390
451
452
+ private void getHaxmDownloadUrl (SDKUrlHolder urlHolder ,
453
+ String repositoryUrl , String requiredHostOs )
454
+ throws ParserConfigurationException , IOException , SAXException , XPathException {
455
+ if (requiredHostOs .equals ("linux" ))
456
+ return ;
457
+
458
+ DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance ();
459
+ DocumentBuilder db = dbf .newDocumentBuilder ();
460
+ Document doc = db .parse (new URL (repositoryUrl ).openStream ());
461
+
462
+ XPathFactory xPathfactory = XPathFactory .newInstance ();
463
+ XPath xpath = xPathfactory .newXPath ();
464
+ XPathExpression expr ;
465
+ NodeList remotePackages ;
466
+
467
+ expr = xpath .compile ("//remotePackage[@path=\" extras;intel;Hardware_Accelerated_Execution_Manager\" ]" );
468
+ remotePackages = (NodeList ) expr .evaluate (doc , XPathConstants .NODESET );
469
+ if (remotePackages != null ) {
470
+ for (int i =0 ; i < remotePackages .getLength (); ++i ) {
471
+ NodeList childNodes = remotePackages .item (i ).getChildNodes ();
472
+ NodeList archives = ((Element ) childNodes ).getElementsByTagName ("archive" );
473
+
474
+ NodeList archive = archives .item (0 ).getChildNodes ();
475
+ NodeList os = ((Element ) archive ).getElementsByTagName ("host-os" );
476
+
477
+ if (!os .item (0 ).getTextContent ().equals (requiredHostOs ))
478
+ continue ;
479
+
480
+ NodeList complete = ((Element ) archive ).getElementsByTagName ("complete" );
481
+ NodeList url = ((Element ) complete .item (0 )).getElementsByTagName ("url" );
482
+ NodeList size = ((Element ) complete .item (0 )).getElementsByTagName ("size" );
483
+
484
+ urlHolder .haxmFilename = url .item (0 ).getTextContent ();
485
+ urlHolder .haxmUrl = HAXM_URL + urlHolder .haxmFilename ;
486
+ urlHolder .totalSize += Integer .parseInt (size .item (0 ).getTextContent ());
487
+ break ;
488
+ }
489
+ }
490
+ }
491
+
391
492
private void parseAndSet (SDKUrlHolder urlHolder , NodeList remotePackages , String requiredHostOs , int packageN ) {
392
493
NodeList childNodes = remotePackages .item (0 ).getChildNodes ();
393
494
NodeList archives = ((Element ) childNodes ).getElementsByTagName ("archive" );
0 commit comments