@@ -17,7 +17,7 @@ public class AVD {
17
17
static private final String AVD_CREATE_SECONDARY =
18
18
"The default Android emulator could not be set up. Make sure<br>" +
19
19
"that the Android SDK is installed properly, and that the<br>" +
20
- "Android and Google APIs are installed for level " + AndroidBuild . sdkVersion + " .<br>" +
20
+ "Android and Google APIs are installed for level %s .<br>" +
21
21
"(Between you and me, occasionally, this error is a red herring,<br>" +
22
22
"and your sketch may be launching shortly.)" ;
23
23
@@ -48,53 +48,96 @@ public class AVD {
48
48
/** x86, x86_64 or armeabi-v7a **/
49
49
protected String abi ;
50
50
51
+ protected VirtualDevice virtualDevice ;
52
+
51
53
public static final String PREF_KEY_ABI = "android.sdk.abi" ;
52
54
public static final String [] ABI = {"armeabi-v7a" , "x86" , "x86_64" };
53
55
54
56
/** Default virtual device used by Processing. */
55
57
static public AVD defaultAVD ;
56
58
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
57
59
58
- static ArrayList <String > avdList ;
59
- static ArrayList <String > badList ;
60
- // static ArrayList<String> skinList;
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
+ }
61
73
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
+
62
85
63
86
public AVD (String name , String target , String abi ) {
64
87
this .name = name ;
65
88
this .target = target ;
66
89
this .abi = abi ;
90
+ virtualDevice = new VirtualDevice (name , target , abi );
67
91
}
68
92
69
93
70
94
static protected void list (final AndroidSDK sdk ) throws IOException {
71
95
try {
72
- avdList = new ArrayList <String >();
73
- badList = new ArrayList <String >();
96
+ avdList = new ArrayList <VirtualDevice >();
97
+ badList = new ArrayList <VirtualDevice >();
74
98
ProcessResult listResult =
75
99
new ProcessHelper (sdk .getAndroidToolPath (), "list" , "avds" ).execute ();
76
100
if (listResult .succeeded ()) {
77
101
boolean badness = false ;
102
+ String mTarget = null ;
103
+ String mAbi = null ;
104
+ String mName = null ;
78
105
for (String line : listResult ) {
79
106
String [] m = PApplet .match (line , "\\ s+Name\\ :\\ s+(\\ S+)" );
80
107
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 ;
81
127
if (!badness ) {
82
- // System.out.println("good: " + m[1]);
83
- avdList .add (m [1 ]);
128
+ avdList .add (mVirtualDevice );
84
129
} else {
85
- // System.out.println("bad: " + m[1]);
86
- badList .add (m [1 ]);
130
+ badList .add (mVirtualDevice );
87
131
}
88
- // } else {
89
- // System.out.println("nope: " + line);
90
132
}
133
+
91
134
// "The following Android Virtual Devices could not be loaded:"
92
135
if (line .contains ("could not be loaded:" )) {
93
136
// System.out.println("starting the bad list");
94
137
// System.err.println("Could not list AVDs:");
95
138
// System.err.println(listResult);
96
139
badness = true ;
97
- // break;
140
+ break ;
98
141
}
99
142
}
100
143
} else {
@@ -109,15 +152,9 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
109
152
if (avdList == null ) {
110
153
list (sdk );
111
154
}
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 ;
155
+ virtualDevice .target = AndroidBuild .sdkVersion ;
156
+ virtualDevice .abi = abi ;
157
+ return avdList .contains (virtualDevice );
121
158
}
122
159
123
160
@@ -127,12 +164,7 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
127
164
* (Prestigious may also not be the right word.)
128
165
*/
129
166
protected boolean badness () {
130
- for (String avd : badList ) {
131
- if (avd .equals (name )) {
132
- return true ;
133
- }
134
- }
135
- return false ;
167
+ return badList .contains (virtualDevice );
136
168
}
137
169
138
170
@@ -165,7 +197,8 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
165
197
} else {
166
198
// Just generally not working
167
199
// Base.showWarning("Android Error", AVD_CREATE_ERROR, null);
168
- Base .showWarningTiered ("Android Error" , AVD_CREATE_PRIMARY , AVD_CREATE_SECONDARY , null );
200
+ Base .showWarningTiered ("Android Error" , AVD_CREATE_PRIMARY ,
201
+ String .format (AVD_CREATE_SECONDARY , AndroidBuild .sdkVersion ), null );
169
202
System .out .println (createAvdResult );
170
203
// throw new IOException("Error creating the AVD");
171
204
}
@@ -178,7 +211,8 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
178
211
179
212
static public boolean ensureProperAVD (final AndroidSDK sdk , final String abi ) {
180
213
try {
181
- defaultAVD = new AVD ("Processing-0" + Base .getRevision (),
214
+ defaultAVD = new AVD ("Processing-0" + Base .getRevision () + "-" + AndroidBuild .sdkVersion +
215
+ "-" + abi ,
182
216
"android-" + AndroidBuild .sdkVersion , abi );
183
217
if (defaultAVD .exists (sdk )) {
184
218
// System.out.println("the avd exists");
@@ -195,8 +229,10 @@ static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) {
195
229
return true ;
196
230
}
197
231
} catch (final Exception e ) {
232
+ e .printStackTrace ();
198
233
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
199
- Base .showWarningTiered ("Android Error" , AVD_CREATE_PRIMARY , AVD_CREATE_SECONDARY , null );
234
+ Base .showWarningTiered ("Android Error" , AVD_CREATE_PRIMARY ,
235
+ String .format (AVD_CREATE_SECONDARY , AndroidBuild .sdkVersion ), null );
200
236
}
201
237
System .out .println ("at bottom of ensure proper" );
202
238
return false ;
0 commit comments