53
53
54
54
@ SuppressWarnings ("serial" )
55
55
public class SDKDownloader extends JDialog implements PropertyChangeListener {
56
- // Version and API level are both used to avoid ambiguity with preview versions,
57
- // which might share the API level with the earlier stable platform.
58
- private static final String PLATFORM_VERSION = "6.0" ;
59
56
private static final String PLATFORM_API_LEVEL = "23" ;
60
57
61
58
private static final String URL_REPOSITORY = "https://dl-ssl.google.com/android/repository/repository-11.xml" ;
@@ -79,6 +76,7 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
79
76
private static ZipFile zip ;
80
77
81
78
class SDKUrlHolder {
79
+ public String platformVersion ;
82
80
public String platformToolsUrl , buildToolsUrl , platformUrl , toolsUrl ;
83
81
public String platformToolsFilename , buildToolsFilename , platformFilename , toolsFilename ;
84
82
public int totalSize = 0 ;
@@ -146,6 +144,17 @@ protected Object doInBackground() throws Exception {
146
144
}
147
145
148
146
tempFolder .delete ();
147
+
148
+ // Normalize platform folder to android-<API LEVEL>
149
+ File expectedPath = new File (platformsFolder , "android-" + PLATFORM_API_LEVEL );
150
+ File actualPath = new File (platformsFolder , "android-" + downloadUrls .platformVersion );
151
+ if (!expectedPath .exists ()) {
152
+ if (actualPath .exists ()) {
153
+ actualPath .renameTo (expectedPath );
154
+ } else {
155
+ throw new IOException ("Error unpacking platform to " + actualPath .getAbsolutePath ());
156
+ }
157
+ }
149
158
150
159
// Done, let's set the environment and load the new SDK!
151
160
Platform .setenv ("ANDROID_SDK" , sdkFolder .getAbsolutePath ());
@@ -214,14 +223,21 @@ private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs
214
223
Document doc = db .parse (new URL (repositoryUrl ).openStream ());
215
224
216
225
// platform
226
+ String platformDescription = "Android SDK Platform " + PLATFORM_API_LEVEL ;
217
227
NodeList platformList = doc .getElementsByTagName ("sdk:platform" );
218
228
for (int i = 0 ; i < platformList .getLength (); i ++) {
219
229
Node platform = platformList .item (i );
220
230
NodeList version = ((Element ) platform ).getElementsByTagName ("sdk:version" );
221
231
NodeList level = ((Element ) platform ).getElementsByTagName ("sdk:api-level" );
222
- if (version .item (0 ).getTextContent ().equals (PLATFORM_VERSION ) && level .item (0 ).getTextContent ().equals (PLATFORM_API_LEVEL )) {
232
+ NodeList desc = ((Element ) platform ).getElementsByTagName ("sdk:description" );
233
+ // API level and platform description are both used to avoid ambiguity with
234
+ // preview versions, which might share the API level with the earlier stable
235
+ // platform, but use the letter codename in their description.
236
+ if (level .item (0 ).getTextContent ().equals (PLATFORM_API_LEVEL ) &&
237
+ desc .item (0 ).getTextContent ().equals (platformDescription )) {
223
238
Node archiveListItem = ((Element ) platform ).getElementsByTagName ("sdk:archives" ).item (0 );
224
239
Node archiveItem = ((Element ) archiveListItem ).getElementsByTagName ("sdk:archive" ).item (0 );
240
+ urlHolder .platformVersion = version .item (0 ).getTextContent ();
225
241
urlHolder .platformUrl = ((Element ) archiveItem ).getElementsByTagName ("sdk:url" ).item (0 ).getTextContent ();
226
242
urlHolder .platformFilename = urlHolder .platformUrl .split ("/" )[urlHolder .platformUrl .split ("/" ).length -1 ];
227
243
urlHolder .totalSize += Integer .parseInt (((Element ) archiveItem ).getElementsByTagName ("sdk:size" ).item (0 ).getTextContent ());
0 commit comments