29
29
30
30
import processing .app .Platform ;
31
31
import processing .app .ui .Toolkit ;
32
+ import processing .core .PApplet ;
32
33
33
34
import javax .swing .*;
34
35
import javax .swing .border .EmptyBorder ;
@@ -53,13 +54,15 @@ public class SysImageDownloader extends JDialog implements PropertyChangeListene
53
54
private static final String URL_SYS_IMAGES_WEAR = "https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml" ;
54
55
private static final String URL_SYS_IMAGES_WEAR_FOLDER = "https://dl-ssl.google.com/android/repository/sys-img/android-wear/" ;
55
56
56
- private static final String SYSTEM_IMAGE_MACOSX = "Intel x86 Atom System Image" ;
57
- private static final String SYSTEM_IMAGE_WINDOWS = "ARM EABI v7a System Image" ;
58
- private static final String SYSTEM_IMAGE_LINUX = "ARM EABI v7a System Image" ;
57
+ public static final String SYSTEM_IMAGE_TAG = "google_apis" ;
58
+ private static final String SYSTEM_IMAGE_MACOSX = "Google APIs Intel x86 Atom System Image" ;
59
+ private static final String SYSTEM_IMAGE_WINDOWS = "Google APIs Intel x86 Atom System Image" ;
60
+ private static final String SYSTEM_IMAGE_LINUX = "Google APIs Intel x86 Atom System Image" ;
59
61
62
+ public static final String SYSTEM_IMAGE_WEAR_TAG = "android-wear" ;
60
63
private static final String SYSTEM_IMAGE_WEAR_MACOSX = "Android Wear Intel x86 Atom System Image" ;
61
- private static final String SYSTEM_IMAGE_WEAR_WINDOWS = "Android Wear ARM EABI v7a System Image" ;
62
- private static final String SYSTEM_IMAGE_WEAR_LINUX = "Android Wear ARM EABI v7a System Image" ;
64
+ private static final String SYSTEM_IMAGE_WEAR_WINDOWS = "Android Wear Intel x86 Atom System Image" ;
65
+ private static final String SYSTEM_IMAGE_WEAR_LINUX = "Android Wear Intel x86 Atom System Image" ;
63
66
64
67
private static final String PROPERTY_CHANGE_EVENT_TOTAL = "total" ;
65
68
private static final String PROPERTY_CHANGE_EVENT_DOWNLOADED = "downloaded" ;
@@ -121,37 +124,25 @@ protected Object doInBackground() throws Exception {
121
124
if (!tmp .exists ()) tmp .mkdir ();
122
125
File sysImgWearFinalFolder = new File (tmp , downloadUrls .sysImgWearTag );
123
126
if (!sysImgWearFinalFolder .exists ()) sysImgWearFinalFolder .mkdir ();
124
- downloadAndUnpack (downloadUrls .sysImgWearUrl , downloadedSysImgWear , sysImgWearFinalFolder , false );
127
+ downloadAndUnpack (downloadUrls .sysImgWearUrl , downloadedSysImgWear , sysImgWearFinalFolder , false );
128
+ fixSourceProperties (sysImgWearFinalFolder );
125
129
} else {
126
130
// default system images
127
131
File downloadedSysImg = new File (tempFolder , downloadUrls .sysImgFilename );
128
132
File tmp = new File (sysImgFolder , "android-" + AndroidBuild .target_sdk );
129
133
if (!tmp .exists ()) tmp .mkdir ();
130
134
File sysImgFinalFolder = new File (tmp , downloadUrls .sysImgTag );
131
135
if (!sysImgFinalFolder .exists ()) sysImgFinalFolder .mkdir ();
132
- downloadAndUnpack (downloadUrls .sysImgUrl , downloadedSysImg , sysImgFinalFolder , false );
136
+ downloadAndUnpack (downloadUrls .sysImgUrl , downloadedSysImg , sysImgFinalFolder , false );
137
+ fixSourceProperties (sysImgFinalFolder );
133
138
}
134
139
135
140
if (Platform .isLinux () || Platform .isMacOS ()) {
136
141
Runtime .getRuntime ().exec ("chmod -R 755 " + sysImgFolder .getAbsolutePath ());
137
142
}
138
143
144
+ for (File f : tempFolder .listFiles ()) f .delete ();
139
145
tempFolder .delete ();
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
- //
152
- // // Done, let's set the environment and load the new SDK!
153
- // Platform.setenv("ANDROID_SDK", sdkFolder.getAbsolutePath());
154
- // Preferences.set("android.sdk.path", sdkFolder.getAbsolutePath());
155
146
156
147
result = true ;
157
148
} catch (ParserConfigurationException e ) {
@@ -203,6 +194,27 @@ private void downloadAndUnpack(String urlString, File saveTo,
203
194
AndroidMode .extractFolder (saveTo , unpackTo , setExec );
204
195
}
205
196
197
+ // For some reason the source.properties file includes Addon entries,
198
+ // and this breaks the image...
199
+ private void fixSourceProperties (File imageFolder ) {
200
+ for (File d : imageFolder .listFiles ()) {
201
+ // Should iterate over the installed archs (x86, etc)
202
+ if (d .isDirectory ()) {
203
+ for (File f : d .listFiles ()) {
204
+ if (PApplet .getExtension (f .getName ()).equals ("properties" )) {
205
+ String [] linesIn = PApplet .loadStrings (f );
206
+ String concat = "" ;
207
+ for (String l : linesIn ) {
208
+ if (l .indexOf ("Addon" ) == -1 ) concat += l + "\n " ;
209
+ }
210
+ String [] linesOut = concat .split ("\n " );
211
+ PApplet .saveStrings (f , linesOut );
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+
206
218
private UrlHolder getDownloadUrls (String repositoryUrl , String requiredHostOs )
207
219
throws ParserConfigurationException , IOException , SAXException {
208
220
UrlHolder urlHolder = new UrlHolder ();
@@ -260,7 +272,7 @@ private UrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs)
260
272
NodeList desc = ((Element ) img ).getElementsByTagName ("sdk:description" );
261
273
NodeList codename = ((Element ) img ).getElementsByTagName ("sdk:codename" );
262
274
// Only considering nodes without a codename, which correspond to the platform
263
- // pre-releases.
275
+ // pre-releases.
264
276
if (level .item (0 ).getTextContent ().equals (AndroidBuild .target_sdk ) &&
265
277
desc .item (0 ).getTextContent ().equals (systemImage ) &&
266
278
codename .item (0 ) == null ) {
0 commit comments