52
52
public class SDKDownloader extends JDialog implements PropertyChangeListener {
53
53
// Version 25.3.1 of the SDK tools break the mode, since the android tool
54
54
// no longer works:
55
- private static final int SDK_TOOLS_MAX_MAJOR = 25 ;
56
- private static final int SDK_TOOLS_MAX_MINOR = 2 ;
57
-
58
- private static final int PLATFORM_TOOLS_MAX_MAJOR = 25 ;
59
- private static final int PLATFORM_TOOLS_MAX_MINOR = 0 ;
60
-
61
- private static final int BUILD_TOOLS_MAX_MAJOR = 25 ;
62
- private static final int BUILD_TOOLS_MAX_MINOR = 0 ;
63
-
64
55
// https://code.google.com/p/android/issues/detail?id=235455
65
56
// as well as removing the ant scripts.
66
57
// https://code.google.com/p/android/issues/detail?id=235410
67
58
// See release notes:
68
- // https://developer.android.com/studio/releases/sdk-tools.html
59
+ // https://developer.android.com/studio/releases/sdk-tools.html
60
+
61
+ // The last versions of tools known to work with ant are hard-coded here:
62
+ private static final String SDK_TOOLS_VERSION = "25.2.5" ;
63
+ private static final String PLATFORM_TOOLS_VERSION = "25.0.3" ;
64
+ private static final String BUILD_TOOLS_VERSION = "25.0.3" ;
65
+
66
+ private static final int SDK_TOOLS_MAX_MAJOR = -1 ;
67
+ private static final int SDK_TOOLS_MAX_MINOR = -1 ;
68
+
69
+ private static final int PLATFORM_TOOLS_MAX_MAJOR = -1 ;
70
+ private static final int PLATFORM_TOOLS_MAX_MINOR = -1 ;
71
+
72
+ private static final int BUILD_TOOLS_MAX_MAJOR = -1 ;
73
+ private static final int BUILD_TOOLS_MAX_MINOR = -1 ;
74
+
69
75
private static final String REPOSITORY_URL = "https://dl.google.com/android/repository/" ;
70
76
private static final String REPOSITORY_LIST = "repository-12.xml" ;
71
77
private static final String ADDON_LIST = "addon.xml" ;
@@ -268,7 +274,9 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
268
274
String hostOs = ((Element ) archive ).getElementsByTagName ("sdk:host-os" ).item (0 ).getTextContent ();
269
275
if (hostOs .equals (requiredHostOs )) {
270
276
urlHolder .platformToolsFilename = (((Element ) archive ).getElementsByTagName ("sdk:url" ).item (0 ).getTextContent ());
277
+ urlHolder .platformToolsFilename = replaceVersion (urlHolder .platformToolsFilename , PLATFORM_TOOLS_VERSION );
271
278
urlHolder .platformToolsUrl = REPOSITORY_URL + urlHolder .platformToolsFilename ;
279
+ PApplet .println ("PLATFORM TOOLS: " + urlHolder .platformToolsUrl );
272
280
urlHolder .totalSize += Integer .parseInt (((Element ) archive ).getElementsByTagName ("sdk:size" ).item (0 ).getTextContent ());
273
281
break ;
274
282
}
@@ -279,19 +287,21 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
279
287
// build-tools
280
288
Node buildToolsItem = getLatestToolItem (doc .getElementsByTagName ("sdk:build-tool" ), BUILD_TOOLS_MAX_MAJOR , BUILD_TOOLS_MAX_MINOR );
281
289
if (buildToolsItem != null ) {
282
- Node revisionListItem = ((Element ) buildToolsItem ).getElementsByTagName ("sdk:revision" ).item (0 );
283
- String major = ((Element ) revisionListItem ).getElementsByTagName ("sdk:major" ).item (0 ).getTextContent ();
284
- String minor = ((Element ) revisionListItem ).getElementsByTagName ("sdk:minor" ).item (0 ).getTextContent ();
285
- String micro = ((Element ) revisionListItem ).getElementsByTagName ("sdk:micro" ).item (0 ).getTextContent ();
286
- urlHolder .buildToolsVersion = major + "." + minor + "." + micro ;
290
+ // Node revisionListItem = ((Element) buildToolsItem).getElementsByTagName("sdk:revision").item(0);
291
+ // String major = ((Element) revisionListItem).getElementsByTagName("sdk:major").item(0).getTextContent();
292
+ // String minor = ((Element) revisionListItem).getElementsByTagName("sdk:minor").item(0).getTextContent();
293
+ // String micro = ((Element) revisionListItem).getElementsByTagName("sdk:micro").item(0).getTextContent();
294
+ urlHolder .buildToolsVersion = BUILD_TOOLS_VERSION ;
287
295
archiveListItem = ((Element ) buildToolsItem ).getElementsByTagName ("sdk:archives" ).item (0 );
288
296
archiveList = ((Element ) archiveListItem ).getElementsByTagName ("sdk:archive" );
289
297
for (int i = 0 ; i < archiveList .getLength (); i ++) {
290
298
Node archive = archiveList .item (i );
291
299
String hostOs = ((Element ) archive ).getElementsByTagName ("sdk:host-os" ).item (0 ).getTextContent ();
292
300
if (hostOs .equals (requiredHostOs )) {
293
301
urlHolder .buildToolsFilename = (((Element ) archive ).getElementsByTagName ("sdk:url" ).item (0 ).getTextContent ());
302
+ urlHolder .buildToolsFilename = replaceVersion (urlHolder .buildToolsFilename , BUILD_TOOLS_VERSION );
294
303
urlHolder .buildToolsUrl = REPOSITORY_URL + urlHolder .buildToolsFilename ;
304
+ PApplet .println ("BUILD TOOLS: " + urlHolder .buildToolsFilename );
295
305
urlHolder .totalSize += Integer .parseInt (((Element ) archive ).getElementsByTagName ("sdk:size" ).item (0 ).getTextContent ());
296
306
break ;
297
307
}
@@ -300,7 +310,7 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
300
310
301
311
// -----------------------------------------------------------------------
302
312
// tools
303
- Node toolsItem = getLatestToolItem (doc .getElementsByTagName ("sdk:tool" ), SDK_TOOLS_MAX_MAJOR , SDK_TOOLS_MAX_MINOR );;
313
+ Node toolsItem = getLatestToolItem (doc .getElementsByTagName ("sdk:tool" ), SDK_TOOLS_MAX_MAJOR , SDK_TOOLS_MAX_MINOR );
304
314
if (toolsItem != null ) {
305
315
archiveListItem = ((Element ) toolsItem ).getElementsByTagName ("sdk:archives" ).item (0 );
306
316
archiveList = ((Element ) archiveListItem ).getElementsByTagName ("sdk:archive" );
@@ -309,7 +319,9 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
309
319
String hostOs = ((Element ) archive ).getElementsByTagName ("sdk:host-os" ).item (0 ).getTextContent ();
310
320
if (hostOs .equals (requiredHostOs )) {
311
321
urlHolder .toolsFilename = (((Element ) archive ).getElementsByTagName ("sdk:url" ).item (0 ).getTextContent ());
322
+ urlHolder .toolsFilename = replaceVersion (urlHolder .toolsFilename , SDK_TOOLS_VERSION );
312
323
urlHolder .toolsUrl = REPOSITORY_URL + urlHolder .toolsFilename ;
324
+ PApplet .println ("SDK TOOLS: " + urlHolder .toolsUrl );
313
325
urlHolder .totalSize += Integer .parseInt (((Element ) archive ).getElementsByTagName ("sdk:size" ).item (0 ).getTextContent ());
314
326
break ;
315
327
}
@@ -407,7 +419,8 @@ private Node getLatestToolItem(NodeList list, int max_major, int max_minor) {
407
419
int intMajor = PApplet .parseInt (major .item (0 ).getTextContent ());
408
420
int intMinor = PApplet .parseInt (minor .item (0 ).getTextContent ());
409
421
int intMicro = PApplet .parseInt (micro .item (0 ).getTextContent ());
410
- if (max_major < intMajor || (max_major == intMajor && max_minor < intMinor )) continue ;
422
+ if ((0 <= max_major && 0 <= max_minor ) &&
423
+ max_major < intMajor || (max_major == intMajor && max_minor < intMinor )) continue ;
411
424
if (maxMajor <= intMajor && maxMinor <= intMinor && maxMicro <= intMicro ) {
412
425
latest = item ;
413
426
maxMajor = intMajor ;
@@ -418,6 +431,15 @@ private Node getLatestToolItem(NodeList list, int max_major, int max_minor) {
418
431
return latest ;
419
432
}
420
433
434
+ private String replaceVersion (String fn , String newVer ) {
435
+ int n1 = fn .indexOf ("_r" );
436
+ String ver = fn .substring (n1 );
437
+ int n2 = ver .lastIndexOf ("-" );
438
+ ver = ver .substring (2 , n2 );
439
+ PApplet .println ("Replacing version " + ver + " with " + newVer );
440
+ return fn .replace (ver , newVer );
441
+ }
442
+
421
443
private void renameFolder (File baseFolder , String expected , String actual )
422
444
throws IOException {
423
445
File expectedPath = new File (baseFolder , expected );
0 commit comments