@@ -70,7 +70,7 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
70
70
private int totalSize = 0 ;
71
71
72
72
class SDKUrlHolder {
73
- public String platformVersion ;
73
+ public String platformVersion , buildToolsVersion ;
74
74
public String platformToolsUrl , buildToolsUrl , platformUrl , toolsUrl ;
75
75
public String platformToolsFilename , buildToolsFilename , platformFilename , toolsFilename ;
76
76
public int totalSize = 0 ;
@@ -83,7 +83,6 @@ class SDKDownloadTask extends SwingWorker<Object, Object> {
83
83
84
84
@ Override
85
85
protected Object doInBackground () throws Exception {
86
-
87
86
File modeFolder = mode .getFolder ();
88
87
89
88
// creating sdk folders
@@ -132,18 +131,16 @@ protected Object doInBackground() throws Exception {
132
131
Runtime .getRuntime ().exec ("chmod -R 755 " + sdkFolder .getAbsolutePath ());
133
132
}
134
133
135
- tempFolder .delete ();
136
-
137
- // Normalize platform folder to android-<API LEVEL>
138
- File expectedPath = new File (platformsFolder , "android-" + AndroidBuild .target_sdk );
139
- File actualPath = new File (platformsFolder , "android-" + downloadUrls .platformVersion );
140
- if (!expectedPath .exists ()) {
141
- if (actualPath .exists ()) {
142
- actualPath .renameTo (expectedPath );
143
- } else {
144
- throw new IOException ("Error unpacking platform to " + actualPath .getAbsolutePath ());
145
- }
134
+ for (File f : tempFolder .listFiles ()) {
135
+ f .delete ();
136
+ PApplet .println ("Deleting" , f .getAbsolutePath ());
146
137
}
138
+ tempFolder .delete ();
139
+
140
+ // Normalize built-tools and platform folders to android-<API LEVEL>
141
+ String actualName = "android-" + downloadUrls .platformVersion ;
142
+ renameFolder (platformsFolder , "android-" + AndroidBuild .target_sdk , actualName );
143
+ renameFolder (buildToolsFolder , downloadUrls .buildToolsVersion , actualName );
147
144
148
145
// Done, let's set the environment and load the new SDK!
149
146
Platform .setenv ("ANDROID_SDK" , sdkFolder .getAbsolutePath ());
@@ -254,6 +251,11 @@ private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs
254
251
// build-tools
255
252
Node buildToolsItem = getLatestToolItem (doc .getElementsByTagName ("sdk:build-tool" ));
256
253
if (buildToolsItem != null ) {
254
+ Node revisionListItem = ((Element ) buildToolsItem ).getElementsByTagName ("sdk:revision" ).item (0 );
255
+ String major = ((Element ) revisionListItem ).getElementsByTagName ("sdk:major" ).item (0 ).getTextContent ();
256
+ String minor = ((Element ) revisionListItem ).getElementsByTagName ("sdk:minor" ).item (0 ).getTextContent ();
257
+ String micro = ((Element ) revisionListItem ).getElementsByTagName ("sdk:micro" ).item (0 ).getTextContent ();
258
+ urlHolder .buildToolsVersion = major + "." + minor + "." + micro ;
257
259
archiveListItem = ((Element ) buildToolsItem ).getElementsByTagName ("sdk:archives" ).item (0 );
258
260
archiveList = ((Element ) archiveListItem ).getElementsByTagName ("sdk:archive" );
259
261
for (int i = 0 ; i < archiveList .getLength (); i ++) {
@@ -339,6 +341,20 @@ private Node getLatestToolItem(NodeList list) {
339
341
return latest ;
340
342
}
341
343
344
+ private void renameFolder (File baseFolder , String expected , String actual )
345
+ throws IOException {
346
+ File expectedPath = new File (baseFolder , expected );
347
+ File actualPath = new File (baseFolder , actual );
348
+ if (!expectedPath .exists ()) {
349
+ if (actualPath .exists ()) {
350
+ actualPath .renameTo (expectedPath );
351
+ } else {
352
+ throw new IOException ("Error unpacking platform to " +
353
+ actualPath .getAbsolutePath ());
354
+ }
355
+ }
356
+ }
357
+
342
358
@ Override
343
359
public void propertyChange (PropertyChangeEvent evt ) {
344
360
if (evt .getPropertyName ().equals (PROPERTY_CHANGE_EVENT_TOTAL )) {
0 commit comments