Skip to content

Commit ff8fd7f

Browse files
committed
Make abi selectable while creating new AVD
Signed-off-by: Umair Khan <[email protected]>
1 parent 973ac89 commit ff8fd7f

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

src/processing/mode/android/AVD.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processing.mode.android;
22

33
import processing.app.Base;
4+
import processing.app.Preferences;
45
import processing.app.exec.ProcessHelper;
56
import processing.app.exec.ProcessResult;
67
import processing.core.PApplet;
@@ -43,21 +44,26 @@ public class AVD {
4344

4445
/** "android-7" or "Google Inc.:Google APIs:7" */
4546
protected String target;
47+
48+
/** x86, x86_64 or armeabi-v7a **/
49+
protected String abi;
50+
51+
public static final String PREF_KEY_ABI = "android.sdk.abi";
52+
public static final String[] ABI = {"armeabi-v7a", "x86", "x86_64"};
4653

4754
/** Default virtual device used by Processing. */
48-
static public final AVD defaultAVD =
49-
new AVD("Processing-0" + Base.getRevision(),
50-
"android-" + AndroidBuild.sdkVersion);
55+
static public AVD defaultAVD;
5156
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
5257

5358
static ArrayList<String> avdList;
5459
static ArrayList<String> badList;
5560
// static ArrayList<String> skinList;
5661

5762

58-
public AVD(final String name, final String target) {
63+
public AVD(String name, String target, String abi) {
5964
this.name = name;
6065
this.target = target;
66+
this.abi = abi;
6167
}
6268

6369

@@ -138,12 +144,11 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
138144
"-t", target,
139145
"-c", DEFAULT_SDCARD_SIZE,
140146
"-s", DEFAULT_SKIN,
141-
"--abi", "armeabi"
147+
"--abi", abi
142148
};
143149

144150
// Set the list to null so that exists() will check again
145151
avdList = null;
146-
147152
final ProcessHelper p = new ProcessHelper(params);
148153
try {
149154
// Passes 'no' to "Do you wish to create a custom hardware profile [no]"
@@ -171,8 +176,10 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
171176
}
172177

173178

174-
static public boolean ensureProperAVD(final AndroidSDK sdk) {
179+
static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) {
175180
try {
181+
defaultAVD = new AVD("Processing-0" + Base.getRevision(),
182+
"android-" + AndroidBuild.sdkVersion, abi);
176183
if (defaultAVD.exists(sdk)) {
177184
// System.out.println("the avd exists");
178185
return true;

src/processing/mode/android/AndroidEditor.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.swing.*;
2929
import javax.swing.event.ChangeEvent;
3030
import javax.swing.event.ChangeListener;
31+
3132
import java.awt.event.ActionEvent;
3233
import java.awt.event.ActionListener;
3334
import java.io.File;
@@ -238,7 +239,32 @@ public void run() {
238239
}.start();
239240

240241
menu.add(sdkMenu);
241-
242+
menu.addSeparator();
243+
244+
final JMenu abiMenu = new JMenu("Select CPU/ABI");
245+
for (int i = 0; i < AVD.ABI.length; ++i) {
246+
JMenuItem menuItem = new JCheckBoxMenuItem(AVD.ABI[i]);
247+
abiMenu.add(menuItem);
248+
if (AVD.ABI[i].equals(Preferences.get(AVD.PREF_KEY_ABI))) {
249+
menuItem.setSelected(true);
250+
}
251+
}
252+
253+
for (int i = 0; i < abiMenu.getItemCount(); ++i) {
254+
final JMenuItem abiItem = abiMenu.getItem(i);
255+
abiItem.addActionListener(new ActionListener() {
256+
@Override
257+
public void actionPerformed(ActionEvent e) {
258+
for (int j = 0; j < abiMenu.getItemCount(); ++j) {
259+
abiMenu.getItem(j).setSelected(false);
260+
}
261+
abiItem.setSelected(true);
262+
Preferences.set(AVD.PREF_KEY_ABI, abiItem.getText());
263+
}
264+
});
265+
}
266+
267+
menu.add(abiMenu);
242268
menu.addSeparator();
243269

244270
item = new JMenuItem("Android SDK Manager");

src/processing/mode/android/AndroidMode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ public void handleRunEmulator(Sketch sketch, RunnerListener listener) throws Ske
191191
listener.statusNotice("Building Android project...");
192192
build.build("debug");
193193

194-
boolean avd = AVD.ensureProperAVD(sdk);
194+
String abi = Preferences.get(AVD.PREF_KEY_ABI);
195+
if (abi.equals("")) {
196+
abi = "x86_64";
197+
}
198+
boolean avd = AVD.ensureProperAVD(sdk, abi);
195199
if (!avd) {
196200
SketchException se =
197201
new SketchException("Could not create a virtual device for the emulator.");

0 commit comments

Comments
 (0)