49
49
50
50
@ SuppressWarnings ("serial" )
51
51
public class SDKDownloader extends JDialog implements PropertyChangeListener {
52
- // Version and API level are both used to avoid ambiguity with preview versions,
53
- // which might share the API level with the earlier stable platform.
54
- private static final String PLATFORM_VERSION = "6.0" ;
55
- private static final String PLATFORM_API_LEVEL = "23" ;
56
-
57
52
private static final String URL_REPOSITORY = "https://dl-ssl.google.com/android/repository/repository-11.xml" ;
58
53
private static final String URL_REPOSITORY_FOLDER = "http://dl-ssl.google.com/android/repository/" ;
59
54
private static final String URL_USB_DRIVER = "https://dl-ssl.google.com//android/repository/latest_usb_driver_windows.zip" ;
@@ -74,6 +69,7 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
74
69
private int totalSize = 0 ;
75
70
76
71
class SDKUrlHolder {
72
+ public String platformVersion ;
77
73
public String platformToolsUrl , buildToolsUrl , platformUrl , toolsUrl ;
78
74
public String platformToolsFilename , buildToolsFilename , platformFilename , toolsFilename ;
79
75
public int totalSize = 0 ;
@@ -128,7 +124,7 @@ protected Object doInBackground() throws Exception {
128
124
// platform
129
125
File downloadedPlatform = new File (tempFolder , downloadUrls .platformFilename );
130
126
downloadAndUnpack (downloadUrls .platformUrl , downloadedPlatform , platformsFolder , false );
131
-
127
+
132
128
// usb driver
133
129
if (Platform .isWindows ()) {
134
130
File usbDriverFolder = new File (extrasFolder , "google" );
@@ -142,6 +138,17 @@ protected Object doInBackground() throws Exception {
142
138
143
139
tempFolder .delete ();
144
140
141
+ // Normalize platform folder to android-<API LEVEL>
142
+ File expectedPath = new File (platformsFolder , "android-" + AndroidBuild .target_sdk );
143
+ File actualPath = new File (platformsFolder , "android-" + downloadUrls .platformVersion );
144
+ if (!expectedPath .exists ()) {
145
+ if (actualPath .exists ()) {
146
+ actualPath .renameTo (expectedPath );
147
+ } else {
148
+ throw new IOException ("Error unpacking platform to " + actualPath .getAbsolutePath ());
149
+ }
150
+ }
151
+
145
152
// Done, let's set the environment and load the new SDK!
146
153
Platform .setenv ("ANDROID_SDK" , sdkFolder .getAbsolutePath ());
147
154
Preferences .set ("android.sdk.path" , sdkFolder .getAbsolutePath ());
@@ -209,14 +216,21 @@ private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs
209
216
Document doc = db .parse (new URL (repositoryUrl ).openStream ());
210
217
211
218
// platform
219
+ String platformDescription = "Android SDK Platform " + AndroidBuild .target_sdk ;
212
220
NodeList platformList = doc .getElementsByTagName ("sdk:platform" );
213
221
for (int i = 0 ; i < platformList .getLength (); i ++) {
214
222
Node platform = platformList .item (i );
215
223
NodeList version = ((Element ) platform ).getElementsByTagName ("sdk:version" );
216
224
NodeList level = ((Element ) platform ).getElementsByTagName ("sdk:api-level" );
217
- if (version .item (0 ).getTextContent ().equals (PLATFORM_VERSION ) && level .item (0 ).getTextContent ().equals (PLATFORM_API_LEVEL )) {
225
+ NodeList desc = ((Element ) platform ).getElementsByTagName ("sdk:description" );
226
+ // API level and platform description are both used to avoid ambiguity with
227
+ // preview versions, which might share the API level with the earlier stable
228
+ // platform, but use the letter codename in their description.
229
+ if (level .item (0 ).getTextContent ().equals ( AndroidBuild .target_sdk ) &&
230
+ desc .item (0 ).getTextContent ().equals (platformDescription )) {
218
231
Node archiveListItem = ((Element ) platform ).getElementsByTagName ("sdk:archives" ).item (0 );
219
232
Node archiveItem = ((Element ) archiveListItem ).getElementsByTagName ("sdk:archive" ).item (0 );
233
+ urlHolder .platformVersion = version .item (0 ).getTextContent ();
220
234
urlHolder .platformUrl = ((Element ) archiveItem ).getElementsByTagName ("sdk:url" ).item (0 ).getTextContent ();
221
235
urlHolder .platformFilename = urlHolder .platformUrl .split ("/" )[urlHolder .platformUrl .split ("/" ).length -1 ];
222
236
urlHolder .totalSize += Integer .parseInt (((Element ) archiveItem ).getElementsByTagName ("sdk:size" ).item (0 ).getTextContent ());
0 commit comments