Skip to content

Commit cf8dc49

Browse files
committed
hardcode last versions of tools that work with ant
1 parent 650d34c commit cf8dc49

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

src/processing/mode/android/SDKDownloader.java

+39-17
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,26 @@
5252
public class SDKDownloader extends JDialog implements PropertyChangeListener {
5353
// Version 25.3.1 of the SDK tools break the mode, since the android tool
5454
// 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-
6455
// https://code.google.com/p/android/issues/detail?id=235455
6556
// as well as removing the ant scripts.
6657
// https://code.google.com/p/android/issues/detail?id=235410
6758
// 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+
6975
private static final String REPOSITORY_URL = "https://dl.google.com/android/repository/";
7076
private static final String REPOSITORY_LIST = "repository-12.xml";
7177
private static final String ADDON_LIST = "addon.xml";
@@ -268,7 +274,9 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
268274
String hostOs = ((Element) archive).getElementsByTagName("sdk:host-os").item(0).getTextContent();
269275
if (hostOs.equals(requiredHostOs)) {
270276
urlHolder.platformToolsFilename = (((Element) archive).getElementsByTagName("sdk:url").item(0).getTextContent());
277+
urlHolder.platformToolsFilename = replaceVersion(urlHolder.platformToolsFilename, PLATFORM_TOOLS_VERSION);
271278
urlHolder.platformToolsUrl = REPOSITORY_URL + urlHolder.platformToolsFilename;
279+
PApplet.println("PLATFORM TOOLS: " + urlHolder.platformToolsUrl);
272280
urlHolder.totalSize += Integer.parseInt(((Element) archive).getElementsByTagName("sdk:size").item(0).getTextContent());
273281
break;
274282
}
@@ -279,19 +287,21 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
279287
// build-tools
280288
Node buildToolsItem = getLatestToolItem(doc.getElementsByTagName("sdk:build-tool"), BUILD_TOOLS_MAX_MAJOR, BUILD_TOOLS_MAX_MINOR);
281289
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;
287295
archiveListItem = ((Element) buildToolsItem).getElementsByTagName("sdk:archives").item(0);
288296
archiveList = ((Element) archiveListItem).getElementsByTagName("sdk:archive");
289297
for (int i = 0; i < archiveList.getLength(); i++) {
290298
Node archive = archiveList.item(i);
291299
String hostOs = ((Element) archive).getElementsByTagName("sdk:host-os").item(0).getTextContent();
292300
if (hostOs.equals(requiredHostOs)) {
293301
urlHolder.buildToolsFilename = (((Element) archive).getElementsByTagName("sdk:url").item(0).getTextContent());
302+
urlHolder.buildToolsFilename = replaceVersion(urlHolder.buildToolsFilename, BUILD_TOOLS_VERSION);
294303
urlHolder.buildToolsUrl = REPOSITORY_URL + urlHolder.buildToolsFilename;
304+
PApplet.println("BUILD TOOLS: " + urlHolder.buildToolsFilename);
295305
urlHolder.totalSize += Integer.parseInt(((Element) archive).getElementsByTagName("sdk:size").item(0).getTextContent());
296306
break;
297307
}
@@ -300,7 +310,7 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
300310

301311
// -----------------------------------------------------------------------
302312
// 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);
304314
if (toolsItem != null) {
305315
archiveListItem = ((Element) toolsItem).getElementsByTagName("sdk:archives").item(0);
306316
archiveList = ((Element) archiveListItem).getElementsByTagName("sdk:archive");
@@ -309,7 +319,9 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
309319
String hostOs = ((Element) archive).getElementsByTagName("sdk:host-os").item(0).getTextContent();
310320
if (hostOs.equals(requiredHostOs)) {
311321
urlHolder.toolsFilename = (((Element) archive).getElementsByTagName("sdk:url").item(0).getTextContent());
322+
urlHolder.toolsFilename = replaceVersion(urlHolder.toolsFilename, SDK_TOOLS_VERSION);
312323
urlHolder.toolsUrl = REPOSITORY_URL + urlHolder.toolsFilename;
324+
PApplet.println("SDK TOOLS: " + urlHolder.toolsUrl);
313325
urlHolder.totalSize += Integer.parseInt(((Element) archive).getElementsByTagName("sdk:size").item(0).getTextContent());
314326
break;
315327
}
@@ -407,7 +419,8 @@ private Node getLatestToolItem(NodeList list, int max_major, int max_minor) {
407419
int intMajor = PApplet.parseInt(major.item(0).getTextContent());
408420
int intMinor = PApplet.parseInt(minor.item(0).getTextContent());
409421
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;
411424
if (maxMajor <= intMajor && maxMinor <= intMinor && maxMicro <= intMicro) {
412425
latest = item;
413426
maxMajor = intMajor;
@@ -418,6 +431,15 @@ private Node getLatestToolItem(NodeList list, int max_major, int max_minor) {
418431
return latest;
419432
}
420433

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+
421443
private void renameFolder(File baseFolder, String expected, String actual)
422444
throws IOException {
423445
File expectedPath = new File(baseFolder, expected);

0 commit comments

Comments
 (0)