5353
5454@ SuppressWarnings ("serial" )
5555public 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" ;
5956 private static final String PLATFORM_API_LEVEL = "23" ;
6057
6158 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 {
7976 private static ZipFile zip ;
8077
8178 class SDKUrlHolder {
79+ public String platformVersion ;
8280 public String platformToolsUrl , buildToolsUrl , platformUrl , toolsUrl ;
8381 public String platformToolsFilename , buildToolsFilename , platformFilename , toolsFilename ;
8482 public int totalSize = 0 ;
@@ -146,6 +144,17 @@ protected Object doInBackground() throws Exception {
146144 }
147145
148146 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+ }
149158
150159 // Done, let's set the environment and load the new SDK!
151160 Platform .setenv ("ANDROID_SDK" , sdkFolder .getAbsolutePath ());
@@ -214,14 +223,21 @@ private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs
214223 Document doc = db .parse (new URL (repositoryUrl ).openStream ());
215224
216225 // platform
226+ String platformDescription = "Android SDK Platform " + PLATFORM_API_LEVEL ;
217227 NodeList platformList = doc .getElementsByTagName ("sdk:platform" );
218228 for (int i = 0 ; i < platformList .getLength (); i ++) {
219229 Node platform = platformList .item (i );
220230 NodeList version = ((Element ) platform ).getElementsByTagName ("sdk:version" );
221231 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 )) {
223238 Node archiveListItem = ((Element ) platform ).getElementsByTagName ("sdk:archives" ).item (0 );
224239 Node archiveItem = ((Element ) archiveListItem ).getElementsByTagName ("sdk:archive" ).item (0 );
240+ urlHolder .platformVersion = version .item (0 ).getTextContent ();
225241 urlHolder .platformUrl = ((Element ) archiveItem ).getElementsByTagName ("sdk:url" ).item (0 ).getTextContent ();
226242 urlHolder .platformFilename = urlHolder .platformUrl .split ("/" )[urlHolder .platformUrl .split ("/" ).length -1 ];
227243 urlHolder .totalSize += Integer .parseInt (((Element ) archiveItem ).getElementsByTagName ("sdk:size" ).item (0 ).getTextContent ());
0 commit comments