4949
5050@ SuppressWarnings ("serial" )
5151public 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-
5752 private static final String URL_REPOSITORY = "https://dl-ssl.google.com/android/repository/repository-11.xml" ;
5853 private static final String URL_REPOSITORY_FOLDER = "http://dl-ssl.google.com/android/repository/" ;
5954 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 {
7469 private int totalSize = 0 ;
7570
7671 class SDKUrlHolder {
72+ public String platformVersion ;
7773 public String platformToolsUrl , buildToolsUrl , platformUrl , toolsUrl ;
7874 public String platformToolsFilename , buildToolsFilename , platformFilename , toolsFilename ;
7975 public int totalSize = 0 ;
@@ -128,7 +124,7 @@ protected Object doInBackground() throws Exception {
128124 // platform
129125 File downloadedPlatform = new File (tempFolder , downloadUrls .platformFilename );
130126 downloadAndUnpack (downloadUrls .platformUrl , downloadedPlatform , platformsFolder , false );
131-
127+
132128 // usb driver
133129 if (Platform .isWindows ()) {
134130 File usbDriverFolder = new File (extrasFolder , "google" );
@@ -142,6 +138,17 @@ protected Object doInBackground() throws Exception {
142138
143139 tempFolder .delete ();
144140
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+
145152 // Done, let's set the environment and load the new SDK!
146153 Platform .setenv ("ANDROID_SDK" , sdkFolder .getAbsolutePath ());
147154 Preferences .set ("android.sdk.path" , sdkFolder .getAbsolutePath ());
@@ -209,14 +216,21 @@ private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs
209216 Document doc = db .parse (new URL (repositoryUrl ).openStream ());
210217
211218 // platform
219+ String platformDescription = "Android SDK Platform " + AndroidBuild .target_sdk ;
212220 NodeList platformList = doc .getElementsByTagName ("sdk:platform" );
213221 for (int i = 0 ; i < platformList .getLength (); i ++) {
214222 Node platform = platformList .item (i );
215223 NodeList version = ((Element ) platform ).getElementsByTagName ("sdk:version" );
216224 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 )) {
218231 Node archiveListItem = ((Element ) platform ).getElementsByTagName ("sdk:archives" ).item (0 );
219232 Node archiveItem = ((Element ) archiveListItem ).getElementsByTagName ("sdk:archive" ).item (0 );
233+ urlHolder .platformVersion = version .item (0 ).getTextContent ();
220234 urlHolder .platformUrl = ((Element ) archiveItem ).getElementsByTagName ("sdk:url" ).item (0 ).getTextContent ();
221235 urlHolder .platformFilename = urlHolder .platformUrl .split ("/" )[urlHolder .platformUrl .split ("/" ).length -1 ];
222236 urlHolder .totalSize += Integer .parseInt (((Element ) archiveItem ).getElementsByTagName ("sdk:size" ).item (0 ).getTextContent ());
0 commit comments