Skip to content

Commit d6908c8

Browse files
committed
support new emulator location
1 parent 8976696 commit d6908c8

File tree

4 files changed

+50
-43
lines changed

4 files changed

+50
-43
lines changed

mode/src/processing/mode/android/AVD.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ static protected void list(final AndroidSDK sdk) throws IOException {
160160
try {
161161
avdList = new ArrayList<String>();
162162
badList = new ArrayList<String>();
163-
ProcessBuilder pb =
164-
new ProcessBuilder(sdk.getAvdManagerPath(), "list", "avd");
163+
File avdManager = sdk.getAVDManagerTool();
164+
ProcessBuilder pb = new ProcessBuilder(avdManager.getCanonicalPath(), "list", "avd");
165165
Map<String, String> env = pb.environment();
166166
env.clear();
167167
env.put("JAVA_HOME", Platform.getJavaHome().getCanonicalPath());
@@ -286,12 +286,13 @@ protected void refreshImages(final AndroidSDK sdk) throws IOException {
286286

287287
protected void getImages(final ArrayList<String> images, final AndroidSDK sdk,
288288
final String imageAbi) throws IOException {
289-
boolean wear = type == WEAR;
289+
final boolean wear = type == WEAR;
290290
final String imagePlatform = getPreferredPlatform(wear, imageAbi);
291291
final String imageTag = getPreferredTag(wear, imageAbi);
292292

293+
final File avdManager = sdk.getAVDManagerTool();
293294
final String[] cmd = new String[] {
294-
sdk.getAvdManagerPath(),
295+
avdManager.getCanonicalPath(),
295296
"create", "avd",
296297
"-n", "dummy",
297298
"-k", "dummy"
@@ -361,8 +362,9 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
361362
if (!androidFolder.exists()) androidFolder.mkdir();
362363
File avdPath = new File(androidFolder, "avd/" + name);
363364

365+
File avdManager = sdk.getAVDManagerTool();
364366
final String[] cmd = new String[] {
365-
sdk.getAvdManagerPath(),
367+
avdManager.getCanonicalPath(),
366368
"create", "avd",
367369
"-n", name,
368370
"-k", getSdkId(),

mode/src/processing/mode/android/AndroidBuild.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ private void writeResXMLWatchFace(final File xmlFolder) {
553553

554554
private void writeLocalProps(final File file) {
555555
final PrintWriter writer = PApplet.createWriter(file);
556-
final String sdkPath = sdk.getSdkFolder().getAbsolutePath();
556+
final String sdkPath = sdk.getFolder().getAbsolutePath();
557557
if (Platform.isWindows()) {
558558
// Windows needs backslashes escaped, or it will also accept forward
559559
// slashes in the build file. We're using the forward slashes since this

mode/src/processing/mode/android/AndroidSDK.java

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ class AndroidSDK {
6161
private final File folder;
6262
private final File tools;
6363
private final File platforms;
64-
private final File highestPlatform;
64+
private final File highestPlatform;
6565
private final File androidJar;
6666
private final File platformTools;
6767
private final File buildTools;
6868
private final File avdManager;
6969
private final File sdkManager;
70+
private final File emulator;
7071

7172
private static final String SDK_DOWNLOAD_URL =
7273
"https://developer.android.com/studio/index.html#downloads";
@@ -122,7 +123,6 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
122123
ArrayList<SDKTarget> targets = getAvailableSdkTargets();
123124
int highest = 1;
124125
for (SDKTarget targ: targets) {
125-
System.out.println(targ);
126126
if (highest < targ.version) {
127127
highest = targ.version;
128128
}
@@ -143,7 +143,16 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
143143

144144
avdManager = findCliTool(new File(tools, "bin"), "avdmanager");
145145
sdkManager = findCliTool(new File(tools, "bin"), "sdkmanager");
146-
146+
147+
File emuFolder = new File(folder, "emulator");
148+
if (emuFolder.exists()) {
149+
// First try the new location of the emulator inside its own folder
150+
emulator = findCliTool(emuFolder, "emulator");
151+
} else {
152+
// If not found, use old location inside tools
153+
emulator = findCliTool(tools, "emulator");
154+
}
155+
147156
String path = Platform.getenv("PATH");
148157

149158
Platform.setenv("ANDROID_SDK", folder.getCanonicalPath());
@@ -214,28 +223,9 @@ protected void checkDebugCertificate() {
214223
}
215224

216225

217-
public File getToolsFolder() {
218-
return tools;
219-
}
220-
221-
222-
public String getAvdManagerPath() {
223-
return avdManager.getAbsolutePath();
224-
}
225-
226-
227-
public File getSdkFolder() {
226+
public File getFolder() {
228227
return folder;
229228
}
230-
231-
232-
public File getHighestPlatform() {
233-
return highestPlatform;
234-
}
235-
236-
public File getAndroidJarPath() {
237-
return androidJar;
238-
}
239229

240230

241231
public File getBuildToolsFolder() {
@@ -246,17 +236,32 @@ public File getBuildToolsFolder() {
246236
public File getPlatformToolsFolder() {
247237
return platformTools;
248238
}
249-
250239

251-
// public File getWearableFolder() {
252-
// return wearablePath;
253-
// }
254240

241+
public File getAndroidJarPath() {
242+
return androidJar;
243+
}
244+
245+
246+
public File getToolsFolder() {
247+
return tools;
248+
}
255249

256-
// public File getSupportLibrary() {
257-
// return supportLibPath;
258-
// }
259250

251+
public File getEmulatorTool() {
252+
return emulator;
253+
}
254+
255+
256+
public File getAVDManagerTool() {
257+
return avdManager;
258+
}
259+
260+
261+
public File getHighestPlatform() {
262+
return highestPlatform;
263+
}
264+
260265

261266
public File getZipAlignTool() {
262267
File[] files = buildTools.listFiles();
@@ -276,8 +281,7 @@ public File getZipAlignTool() {
276281
private static final String response = "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n";
277282

278283
private void acceptLicenses() {
279-
ProcessBuilder pb = new ProcessBuilder(sdkManager.getAbsolutePath(),
280-
"--licenses");
284+
ProcessBuilder pb = new ProcessBuilder(sdkManager.getAbsolutePath(), "--licenses");
281285
pb.redirectErrorStream(true);
282286
try {
283287
Process process = pb.start();
@@ -324,14 +328,17 @@ static public File getGoogleDriverFolder() {
324328

325329
/**
326330
* Checks a path to see if there's a tools/android file inside, a rough check
327-
* for the SDK installation. Also figures out the name of android/android.bat
331+
* for the SDK installation. Also figures out the name of android/android.bat/android.exe
328332
* so that it can be called explicitly.
329333
*/
330334
private static File findCliTool(final File tools, String name)
331335
throws BadSDKException {
332336
if (new File(tools, name + ".bat").exists()) {
333337
return new File(tools, name + ".bat");
334338
}
339+
if (new File(tools, name + ".exe").exists()) {
340+
return new File(tools, name + ".exe");
341+
}
335342
if (new File(tools, name).exists()) {
336343
return new File(tools, name);
337344
}

mode/src/processing/mode/android/EmulatorController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.concurrent.CountDownLatch;
2727

2828
import processing.app.Base;
29-
import processing.app.Platform;
3029
import processing.app.exec.*;
3130

3231
import processing.core.PApplet;
@@ -75,10 +74,9 @@ synchronized public void launch(final AndroidSDK sdk, final boolean wear)
7574
// https://developer.android.com/studio/run/emulator-acceleration.html#accel-graphics
7675
String gpuFlag = "auto";
7776

78-
File emulatorPath = Platform.isWindows() ? new File(sdk.getToolsFolder(), "emulator.exe") :
79-
new File(sdk.getToolsFolder(), "emulator");
77+
final File emulator = sdk.getEmulatorTool();
8078
final String[] cmd = new String[] {
81-
emulatorPath.getCanonicalPath(),
79+
emulator.getCanonicalPath(),
8280
"-avd", avdName,
8381
"-port", portString,
8482
"-gpu", gpuFlag

0 commit comments

Comments
 (0)