Skip to content

Commit f70dd4d

Browse files
committed
ported AVD fixes from master
1 parent 76078e1 commit f70dd4d

File tree

3 files changed

+127
-62
lines changed

3 files changed

+127
-62
lines changed

src/processing/mode/android/AVD.java

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ public AVD(final String name, final String target) {
9090
}
9191

9292
private void initializeAbiList() {
93-
if (abiList.size() == 0) {
94-
//The order in this list determines the preference of one abi over the other
95-
abiList.add("armeabi");
96-
abiList.add("x86");
97-
abiList.add("x86_64");
98-
}
93+
if (abiList.size() == 0) {
94+
// The order in this list determines the preference of one abi over the other
95+
abiList.add("default/x86");
96+
abiList.add("google_apis/x86");
97+
abiList.add("default/x86_64");
98+
abiList.add("google_apis/x86_64");
99+
abiList.add("default/armeabi-v7a");
100+
abiList.add("google_apis/armeabi-v7a");
101+
}
99102
}
100103

101104

@@ -170,42 +173,67 @@ protected boolean badness() {
170173

171174
protected boolean create(final AndroidSDK sdk) throws IOException {
172175

173-
final String[] list_abi = {
174-
sdk.getAndroidToolPath(),
175-
"list", "targets"
176-
};
177-
178-
ProcessHelper p = new ProcessHelper(list_abi);
179-
try {
180-
final ProcessResult abiListResult = p.execute();
181-
String api = null;
182-
String abi = null;
183-
for (String line : abiListResult) {
184-
String[] m = PApplet.match(line, "API\\slevel:\\s(\\S+)");
185-
if (m != null) {
186-
api = m[1];
187-
}
188-
189-
m = PApplet.match(line, "Tag\\/ABIs\\s:\\sdefault\\/(\\S+)");
190-
if (m != null) {
191-
abi = m[1];
192-
193-
if (api != null && abi != null) {
194-
if (preferredAbi.get(api) == null) {
195-
preferredAbi.put(api, abi);
196-
} else if (abiList.indexOf(preferredAbi.get(api)) < abiList.indexOf(abi)) {
197-
preferredAbi.put(api, abi);
198-
}
199-
api = null;
200-
abi = null;
201-
}
202-
}
203-
}
204-
} catch (InterruptedException e) {}
205-
206-
if (preferredAbi.get(AndroidBuild.target_sdk) == null) {
207-
return false;
208-
}
176+
final String[] list_abi = {
177+
sdk.getAndroidToolPath(),
178+
"list", "targets"
179+
};
180+
181+
ProcessHelper p = new ProcessHelper(list_abi);
182+
try {
183+
final ProcessResult abiListResult = p.execute();
184+
185+
String api = null;
186+
String[] abis = null;
187+
for (String line : abiListResult) {
188+
line = line.trim();
189+
if (line.equals("")) continue;
190+
191+
if (-1 < line.indexOf("API level")) {
192+
api = line.split(":")[1];
193+
api = api.trim();
194+
}
195+
196+
if (-1 < line.indexOf("Tag/ABIs")) {
197+
String str = line.split(":")[1];
198+
abis = str.split(",");
199+
for (int i = 0; i < abis.length; i++) {
200+
abis[i] = abis[i].trim();
201+
}
202+
}
203+
204+
if (api != null && abis != null) {
205+
for (String abi: abis) {
206+
if (preferredAbi.get(api) == null) {
207+
preferredAbi.put(api, abi);
208+
} else if (abiList.indexOf(preferredAbi.get(api)) < abiList.indexOf(abi)) {
209+
preferredAbi.put(api, abi);
210+
}
211+
}
212+
api = null;
213+
abis = null;
214+
}
215+
216+
// String[] m = PApplet.match(line, "API\\slevel:\\s(\\S+)");
217+
// if (m != null) {
218+
// api = m[1];
219+
// }
220+
//
221+
// m = PApplet.match(line, "Tag\\/ABIs\\s:\\sdefault\\/(\\S+)");
222+
// if (m != null) {
223+
// abi = m[1];
224+
//
225+
// if (api != null && abi != null) {
226+
// if (preferredAbi.get(api) == null) {
227+
// preferredAbi.put(api, abi);
228+
// } else if (abiList.indexOf(preferredAbi.get(api)) < abiList.indexOf(abi)) {
229+
// preferredAbi.put(api, abi);
230+
// }
231+
// api = null;
232+
// abi = null;
233+
// }
234+
// }
235+
}
236+
} catch (InterruptedException e) {}
209237

210238
final String[] params = {
211239
sdk.getAndroidToolPath(),
@@ -216,29 +244,24 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
216244
"-s", DEFAULT_SKIN,
217245
"--abi", preferredAbi.get(AndroidBuild.target_sdk)
218246
};
219-
247+
220248
// Set the list to null so that exists() will check again
221249
avdList = null;
222250

223251
p = new ProcessHelper(params);
224252
try {
225253
// Passes 'no' to "Do you wish to create a custom hardware profile [no]"
226-
// System.out.println("CREATE AVD STARTING");
227254
final ProcessResult createAvdResult = p.execute("no");
228-
// System.out.println("CREATE AVD HAS COMPLETED");
229255
if (createAvdResult.succeeded()) {
230256
return true;
231257
}
232258
if (createAvdResult.toString().contains("Target id is not valid")) {
233259
// They didn't install the Google APIs
234260
Messages.showWarningTiered("Android Error", AVD_TARGET_PRIMARY, AVD_TARGET_SECONDARY, null);
235-
// throw new IOException("Missing required SDK components");
236261
} else {
237262
// Just generally not working
238-
// Base.showWarning("Android Error", AVD_CREATE_ERROR, null);
239263
Messages.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null);
240264
System.out.println(createAvdResult);
241-
// throw new IOException("Error creating the AVD");
242265
}
243266
//System.err.println(createAvdResult);
244267
} catch (final InterruptedException ie) { }
@@ -247,6 +270,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
247270
}
248271

249272

273+
250274
static public boolean ensureProperAVD(final AndroidSDK sdk) {
251275
try {
252276
if (defaultAVD.exists(sdk)) {

src/processing/mode/android/AndroidSDK.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,20 @@ class AndroidSDK {
4949
private final File platformTools;
5050
private final File androidTool;
5151

52+
static final String DOWNLOAD_URL ="https://developer.android.com/studio/index.html#downloads";
53+
5254
private static final String ANDROID_SDK_PRIMARY =
5355
"Is the Android SDK installed?";
5456

5557
private static final String ANDROID_SDK_SECONDARY =
56-
"The Android SDK does not appear to be installed, <br>" +
57-
"because the ANDROID_SDK variable is not set. <br>" +
58-
"If it is installed, click “Locate SDK path” to select the <br>" +
59-
"location of the SDK, or “Download SDK” to let <br>" +
60-
"Processing download the SDK automatically.<br><br>" +
61-
"If you want to download the SDK manually, you can visit <br>"+
62-
"http://developer.android.com/sdk/installing/index.html <br>" +
63-
"and select the stand-alone SDK tools. Make sure to install <br>"+
64-
"the SDK platform for API " + AndroidBuild.target_sdk + ".";
58+
"The Android SDK does not appear to be installed, <br>" +
59+
"because the ANDROID_SDK variable is not set. <br>" +
60+
"If it is installed, click “Locate SDK path” to select the <br>" +
61+
"location of the SDK, or “Download SDK” to let <br>" +
62+
"Processing download the SDK automatically.<br><br>" +
63+
"If you want to download the SDK manually, you can get <br>"+
64+
"the command line tools from <a href=\"" + DOWNLOAD_URL + "\">here</a>. Make sure to install<br>" +
65+
"the SDK platform for API " + AndroidBuild.target_sdk + ".";
6566

6667
private static final String SELECT_ANDROID_SDK_FOLDER =
6768
"Choose the location of the Android SDK";

src/processing/mode/android/SDKDownloader.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
5252
private static final String URL_REPOSITORY = "https://dl-ssl.google.com/android/repository/repository-11.xml";
5353
private static final String URL_REPOSITORY_FOLDER = "http://dl-ssl.google.com/android/repository/";
5454
private static final String URL_USB_DRIVER = "https://dl-ssl.google.com//android/repository/latest_usb_driver_windows.zip";
55-
55+
private static final String URL_SYS_IMAGES = "https://dl-ssl.google.com/android/repository/sys-img/android/sys-img.xml";
56+
private static final String URL_SYS_IMAGES_FOLDER = "http://dl-ssl.google.com/android/repository/sys-img/android/";
57+
private static final String SYSTEM_IMAGE = "Intel x86 Atom System Image";
58+
// private static final String URL_SYS_IMAGES_WEAR = "https://dl-ssl.google.com/android/repository/sys-img/android-wear/sys-img.xml";
59+
5660
private static final String PROPERTY_CHANGE_EVENT_TOTAL = "total";
5761
private static final String PROPERTY_CHANGE_EVENT_DOWNLOADED = "downloaded";
5862

@@ -70,8 +74,8 @@ public class SDKDownloader extends JDialog implements PropertyChangeListener {
7074

7175
class SDKUrlHolder {
7276
public String platformVersion;
73-
public String platformToolsUrl, buildToolsUrl, platformUrl, toolsUrl;
74-
public String platformToolsFilename, buildToolsFilename, platformFilename, toolsFilename;
77+
public String platformToolsUrl, buildToolsUrl, platformUrl, sysImgUrl, sysImgTag, toolsUrl;
78+
public String platformToolsFilename, buildToolsFilename, platformFilename, sysImgFilename, toolsFilename;
7579
public int totalSize = 0;
7680
}
7781

@@ -97,6 +101,8 @@ protected Object doInBackground() throws Exception {
97101
if (!platformsFolder.exists()) platformsFolder.mkdir();
98102
File buildToolsFolder = new File(sdkFolder, "build-tools");
99103
if (!buildToolsFolder.exists()) buildToolsFolder.mkdir();
104+
File sysImgFolder = new File(sdkFolder, "system-images");
105+
if (!sysImgFolder.exists()) sysImgFolder.mkdir();
100106
File extrasFolder = new File(sdkFolder, "extras");
101107
if(!extrasFolder.exists()) extrasFolder.mkdir();
102108

@@ -105,7 +111,7 @@ protected Object doInBackground() throws Exception {
105111
if (!tempFolder.exists()) tempFolder.mkdir();
106112

107113
try {
108-
SDKUrlHolder downloadUrls = getDownloadUrls(URL_REPOSITORY, Platform.getName());
114+
SDKUrlHolder downloadUrls = getDownloadUrls(URL_REPOSITORY, URL_SYS_IMAGES, Platform.getName());
109115
firePropertyChange(PROPERTY_CHANGE_EVENT_TOTAL, 0, downloadUrls.totalSize);
110116
totalSize = downloadUrls.totalSize;
111117

@@ -125,6 +131,14 @@ protected Object doInBackground() throws Exception {
125131
File downloadedPlatform = new File(tempFolder, downloadUrls.platformFilename);
126132
downloadAndUnpack(downloadUrls.platformUrl, downloadedPlatform, platformsFolder, false);
127133

134+
// system images
135+
File downloadedSysImg = new File(tempFolder, downloadUrls.sysImgFilename);
136+
File tmp = new File(sysImgFolder, "android-" + AndroidBuild.target_sdk);
137+
if (!tmp.exists()) tmp.mkdir();
138+
File sysImgFinalFolder = new File(tmp, downloadUrls.sysImgTag);
139+
if (!sysImgFinalFolder.exists()) sysImgFinalFolder.mkdir();
140+
downloadAndUnpack(downloadUrls.sysImgUrl, downloadedSysImg, sysImgFinalFolder, false);
141+
128142
// usb driver
129143
if (Platform.isWindows()) {
130144
File usbDriverFolder = new File(extrasFolder, "google");
@@ -208,7 +222,9 @@ private void downloadAndUnpack(String urlString, File saveTo,
208222
AndroidMode.extractFolder(saveTo, unpackTo, setExec);
209223
}
210224

211-
private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs) throws ParserConfigurationException, IOException, SAXException {
225+
private SDKUrlHolder getDownloadUrls(String repositoryUrl,
226+
String repositorySysImgUrlString, String requiredHostOs)
227+
throws ParserConfigurationException, IOException, SAXException {
212228
SDKUrlHolder urlHolder = new SDKUrlHolder();
213229

214230
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -281,6 +297,30 @@ private SDKUrlHolder getDownloadUrls(String repositoryUrl, String requiredHostOs
281297
break;
282298
}
283299
}
300+
301+
// system image
302+
Document docSysImg = db.parse(new URL(repositorySysImgUrlString).openStream());
303+
NodeList sysImgList = docSysImg.getElementsByTagName("sdk:system-image");
304+
for (int i = 0; i < sysImgList.getLength(); i++) {
305+
Node img = sysImgList.item(i);
306+
NodeList level = ((Element) img).getElementsByTagName("sdk:api-level");
307+
NodeList desc = ((Element) img).getElementsByTagName("sdk:description");
308+
NodeList codename = ((Element) img).getElementsByTagName("sdk:codename");
309+
// Only considering nodes without a codename, which correspond to the platform
310+
// pre-releases.
311+
if (level.item(0).getTextContent().equals(AndroidBuild.target_sdk) &&
312+
desc.item(0).getTextContent().equals(SYSTEM_IMAGE) &&
313+
codename.item(0) == null) {
314+
NodeList tag = ((Element) img).getElementsByTagName("sdk:tag-id");
315+
urlHolder.sysImgTag = tag.item(0).getTextContent();
316+
archiveListItem = ((Element) img).getElementsByTagName("sdk:archives").item(0);
317+
Node archiveItem = ((Element) archiveListItem).getElementsByTagName("sdk:archive").item(0);
318+
urlHolder.sysImgFilename = ((Element) archiveItem).getElementsByTagName("sdk:url").item(0).getTextContent();
319+
urlHolder.sysImgUrl = URL_SYS_IMAGES_FOLDER + urlHolder.sysImgFilename;
320+
urlHolder.totalSize += Integer.parseInt(((Element) archiveItem).getElementsByTagName("sdk:size").item(0).getTextContent());
321+
break;
322+
}
323+
}
284324

285325
return urlHolder;
286326
}

0 commit comments

Comments
 (0)