Skip to content

Commit 6b5d6a0

Browse files
committed
Revert "properly manage creation of AVD"
This reverts commit 1cd33d5.
1 parent d5aeb29 commit 6b5d6a0

File tree

1 file changed

+31
-67
lines changed

1 file changed

+31
-67
lines changed

src/processing/mode/android/AVD.java

Lines changed: 31 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AVD {
1717
static private final String AVD_CREATE_SECONDARY =
1818
"The default Android emulator could not be set up. Make sure<br>" +
1919
"that the Android SDK is installed properly, and that the<br>" +
20-
"Android and Google APIs are installed for level %s.<br>" +
20+
"Android and Google APIs are installed for level " + AndroidBuild.sdkVersion + ".<br>" +
2121
"(Between you and me, occasionally, this error is a red herring,<br>" +
2222
"and your sketch may be launching shortly.)";
2323

@@ -48,96 +48,53 @@ public class AVD {
4848
/** x86, x86_64 or armeabi **/
4949
protected String abi;
5050

51-
protected VirtualDevice virtualDevice;
52-
5351
public static final String PREF_KEY_ABI = "android.sdk.abi";
5452
public static final String[] ABI = {"armeabi", "x86", "x86_64"};
5553

5654
/** Default virtual device used by Processing. */
5755
static public AVD defaultAVD;
5856
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
5957

60-
static ArrayList<VirtualDevice> avdList;
61-
static ArrayList<VirtualDevice> badList;
62-
63-
64-
private static class VirtualDevice {
65-
public String name;
66-
public String target;
67-
public String abi;
68-
public VirtualDevice(String name, String target, String abi) {
69-
this.name = name;
70-
this.target = target;
71-
this.abi = abi;
72-
}
58+
static ArrayList<String> avdList;
59+
static ArrayList<String> badList;
60+
// static ArrayList<String> skinList;
7361

74-
@Override
75-
public boolean equals(Object o) {
76-
VirtualDevice device = (VirtualDevice) o;
77-
if (device.name.equals(name) && device.target.equals(target)
78-
&& device.abi.equals(abi)) {
79-
return true;
80-
}
81-
return false;
82-
}
83-
}
84-
8562

8663
public AVD(String name, String target, String abi) {
8764
this.name = name;
8865
this.target = target;
8966
this.abi = abi;
90-
virtualDevice = new VirtualDevice(name, target, abi);
9167
}
9268

9369

9470
static protected void list(final AndroidSDK sdk) throws IOException {
9571
try {
96-
avdList = new ArrayList<VirtualDevice>();
97-
badList = new ArrayList<VirtualDevice>();
72+
avdList = new ArrayList<String>();
73+
badList = new ArrayList<String>();
9874
ProcessResult listResult =
9975
new ProcessHelper(sdk.getAndroidToolPath(), "list", "avds").execute();
10076
if (listResult.succeeded()) {
10177
boolean badness = false;
102-
String mTarget = null;
103-
String mAbi = null;
104-
String mName = null;
10578
for (String line : listResult) {
10679
String[] m = PApplet.match(line, "\\s+Name\\:\\s+(\\S+)");
10780
if (m != null) {
108-
mName = m[1];
109-
continue;
110-
}
111-
112-
m = PApplet.match(line, "API\\slevel\\s([0-9]+)");
113-
if (m != null) {
114-
mTarget = m[1];
115-
continue;
116-
}
117-
118-
m = PApplet.match(line, "\\s+Tag\\/ABI\\:\\s\\S+\\/(\\S+)");
119-
if (m != null) {
120-
mAbi = m[1];
121-
}
122-
123-
if (mName != null && mTarget != null && mAbi != null) {
124-
VirtualDevice mVirtualDevice = new VirtualDevice(mName, mTarget, mAbi);
125-
mTarget = null;
126-
mAbi = null;
12781
if (!badness) {
128-
avdList.add(mVirtualDevice);
82+
// System.out.println("good: " + m[1]);
83+
avdList.add(m[1]);
12984
} else {
130-
badList.add(mVirtualDevice);
85+
// System.out.println("bad: " + m[1]);
86+
badList.add(m[1]);
13187
}
88+
// } else {
89+
// System.out.println("nope: " + line);
13290
}
133-
13491
// "The following Android Virtual Devices could not be loaded:"
13592
if (line.contains("could not be loaded:")) {
13693
// System.out.println("starting the bad list");
13794
// System.err.println("Could not list AVDs:");
13895
// System.err.println(listResult);
13996
badness = true;
140-
break;
97+
// break;
14198
}
14299
}
143100
} else {
@@ -152,9 +109,15 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
152109
if (avdList == null) {
153110
list(sdk);
154111
}
155-
virtualDevice.target = AndroidBuild.sdkVersion;
156-
virtualDevice.abi = abi;
157-
return avdList.contains(virtualDevice);
112+
for (String avd : avdList) {
113+
if (Base.DEBUG) {
114+
System.out.println("AVD.exists() checking for " + name + " against " + avd);
115+
}
116+
if (avd.equals(name)) {
117+
return true;
118+
}
119+
}
120+
return false;
158121
}
159122

160123

@@ -164,7 +127,12 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
164127
* (Prestigious may also not be the right word.)
165128
*/
166129
protected boolean badness() {
167-
return badList.contains(virtualDevice);
130+
for (String avd : badList) {
131+
if (avd.equals(name)) {
132+
return true;
133+
}
134+
}
135+
return false;
168136
}
169137

170138

@@ -197,8 +165,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
197165
} else {
198166
// Just generally not working
199167
// Base.showWarning("Android Error", AVD_CREATE_ERROR, null);
200-
Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY,
201-
String.format(AVD_CREATE_SECONDARY, AndroidBuild.sdkVersion), null);
168+
Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null);
202169
System.out.println(createAvdResult);
203170
// throw new IOException("Error creating the AVD");
204171
}
@@ -211,8 +178,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
211178

212179
static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) {
213180
try {
214-
defaultAVD = new AVD("Processing-0" + Base.getRevision() + "-" + AndroidBuild.sdkVersion +
215-
"-" + abi,
181+
defaultAVD = new AVD("Processing-0" + Base.getRevision(),
216182
"android-" + AndroidBuild.sdkVersion, abi);
217183
if (defaultAVD.exists(sdk)) {
218184
// System.out.println("the avd exists");
@@ -229,10 +195,8 @@ static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) {
229195
return true;
230196
}
231197
} catch (final Exception e) {
232-
e.printStackTrace();
233198
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
234-
Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY,
235-
String.format(AVD_CREATE_SECONDARY, AndroidBuild.sdkVersion), null);
199+
Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null);
236200
}
237201
System.out.println("at bottom of ensure proper");
238202
return false;

0 commit comments

Comments
 (0)