1
1
package processing .mode .android ;
2
2
3
3
import processing .app .Base ;
4
- //import processing.app.Preferences;
5
4
import processing .app .exec .ProcessHelper ;
6
5
import processing .app .exec .ProcessResult ;
7
6
import processing .core .PApplet ;
@@ -17,7 +16,7 @@ public class AVD {
17
16
static private final String AVD_CREATE_SECONDARY =
18
17
"The default Android emulator could not be set up. Make sure<br>" +
19
18
"that the Android SDK is installed properly, and that the<br>" +
20
- "Android and Google APIs are installed for level %s.<br>" +
19
+ "system images are installed for level %s.<br>" +
21
20
"(Between you and me, occasionally, this error is a red herring,<br>" +
22
21
"and your sketch may be launching shortly.)" ;
23
22
@@ -44,100 +43,62 @@ public class AVD {
44
43
45
44
/** "android-7" or "Google Inc.:Google APIs:7" */
46
45
protected String target ;
47
-
48
- /** x86, x86_64 or armeabi **/
49
- protected String abi ;
50
-
51
- protected VirtualDevice virtualDevice ;
52
-
53
- public static final String PREF_KEY_ABI = "android.sdk.abi" ;
54
- public static final String [] ABI = {"armeabi" , "x86" , "x86_64" };
55
46
56
47
/** Default virtual device used by Processing. */
57
- static public AVD defaultAVD ;
48
+ static public final AVD defaultAVD =
49
+ new AVD ("Processing-0" + Base .getRevision (),
50
+ "android-" + AndroidBuild .sdkVersion );
58
51
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
59
52
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
- }
53
+ static ArrayList <String > avdList ;
54
+ static ArrayList <String > badList ;
55
+ // static ArrayList<String> skinList;
73
56
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
-
57
+ private String [] preferredAbi = new String [50 ];
58
+ private static ArrayList <String > abiList = new ArrayList <>();
85
59
86
- public AVD (String name , String target , String abi ) {
60
+ public AVD (final String name , final String target ) {
87
61
this .name = name ;
88
62
this .target = target ;
89
- this .abi = abi ;
90
- virtualDevice = new VirtualDevice (name , target , abi );
63
+ }
64
+
65
+ private void initializeAbiList () {
66
+ if (abiList .size () == 0 ) {
67
+ abiList .add ("armeabi" );
68
+ abiList .add ("x86" );
69
+ abiList .add ("x86_64" );
70
+ }
91
71
}
92
72
93
73
94
74
static protected void list (final AndroidSDK sdk ) throws IOException {
95
75
try {
96
- avdList = new ArrayList <VirtualDevice >();
97
- badList = new ArrayList <VirtualDevice >();
76
+ avdList = new ArrayList <String >();
77
+ badList = new ArrayList <String >();
98
78
ProcessResult listResult =
99
79
new ProcessHelper (sdk .getAndroidToolPath (), "list" , "avds" ).execute ();
100
80
if (listResult .succeeded ()) {
101
81
boolean badness = false ;
102
- String mTarget = null ;
103
- String mAbi = null ;
104
- String mName = null ;
105
82
for (String line : listResult ) {
106
83
String [] m = PApplet .match (line , "\\ s+Name\\ :\\ s+(\\ S+)" );
107
84
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 ;
127
85
if (!badness ) {
128
- avdList .add (mVirtualDevice );
86
+ // System.out.println("good: " + m[1]);
87
+ avdList .add (m [1 ]);
129
88
} else {
130
- badList .add (mVirtualDevice );
89
+ // System.out.println("bad: " + m[1]);
90
+ badList .add (m [1 ]);
131
91
}
92
+ // } else {
93
+ // System.out.println("nope: " + line);
132
94
}
133
-
134
95
// "The following Android Virtual Devices could not be loaded:"
135
96
if (line .contains ("could not be loaded:" )) {
136
97
// System.out.println("starting the bad list");
137
98
// System.err.println("Could not list AVDs:");
138
99
// System.err.println(listResult);
139
100
badness = true ;
140
- break ;
101
+ // break;
141
102
}
142
103
}
143
104
} else {
@@ -152,9 +113,15 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
152
113
if (avdList == null ) {
153
114
list (sdk );
154
115
}
155
- virtualDevice .target = AndroidBuild .sdkVersion ;
156
- virtualDevice .abi = abi ;
157
- return avdList .contains (virtualDevice );
116
+ for (String avd : avdList ) {
117
+ if (Base .DEBUG ) {
118
+ System .out .println ("AVD.exists() checking for " + name + " against " + avd );
119
+ }
120
+ if (avd .equals (name )) {
121
+ return true ;
122
+ }
123
+ }
124
+ return false ;
158
125
}
159
126
160
127
@@ -164,24 +131,69 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
164
131
* (Prestigious may also not be the right word.)
165
132
*/
166
133
protected boolean badness () {
167
- return badList .contains (virtualDevice );
134
+ for (String avd : badList ) {
135
+ if (avd .equals (name )) {
136
+ return true ;
137
+ }
138
+ }
139
+ return false ;
168
140
}
169
141
170
142
171
143
protected boolean create (final AndroidSDK sdk ) throws IOException {
144
+
145
+ final String [] list_abi = {
146
+ sdk .getAndroidToolPath (),
147
+ "list" , "targets"
148
+ };
149
+
150
+ ProcessHelper p = new ProcessHelper (list_abi );
151
+ try {
152
+ final ProcessResult abiListResult = p .execute ();
153
+ String api = null ;
154
+ String abi = null ;
155
+ for (String line : abiListResult ) {
156
+ String [] m = PApplet .match (line , "API\\ slevel:\\ s(\\ S+)" );
157
+ if (m != null ) {
158
+ api = m [1 ];
159
+ }
160
+
161
+ m = PApplet .match (line , "Tag\\ /ABIs\\ s:\\ sdefault\\ /(\\ S+)" );
162
+ if (m != null ) {
163
+ abi = m [1 ];
164
+
165
+ if (api != null && abi != null ) {
166
+ int index = Integer .parseInt (api );
167
+ if (preferredAbi [index ] == null ) {
168
+ preferredAbi [index ] = abi ;
169
+ } else if (abiList .indexOf (preferredAbi [index ]) < abiList .indexOf (abi )) {
170
+ preferredAbi [index ] = abi ;
171
+ }
172
+ api = null ;
173
+ abi = null ;
174
+ }
175
+ }
176
+ }
177
+ } catch (InterruptedException e ) {}
178
+
179
+ if (preferredAbi [Integer .parseInt (AndroidBuild .sdkVersion )] == null ) {
180
+ return false ;
181
+ }
182
+
172
183
final String [] params = {
173
184
sdk .getAndroidToolPath (),
174
185
"create" , "avd" ,
175
186
"-n" , name ,
176
187
"-t" , target ,
177
188
"-c" , DEFAULT_SDCARD_SIZE ,
178
189
"-s" , DEFAULT_SKIN ,
179
- "--abi" , abi
190
+ "--abi" , preferredAbi [ Integer . parseInt ( AndroidBuild . sdkVersion )]
180
191
};
181
192
182
193
// Set the list to null so that exists() will check again
183
194
avdList = null ;
184
- final ProcessHelper p = new ProcessHelper (params );
195
+
196
+ p = new ProcessHelper (params );
185
197
try {
186
198
// Passes 'no' to "Do you wish to create a custom hardware profile [no]"
187
199
// System.out.println("CREATE AVD STARTING");
@@ -197,8 +209,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
197
209
} else {
198
210
// Just generally not working
199
211
// 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 );
212
+ Base .showWarningTiered ("Android Error" , AVD_CREATE_PRIMARY , AVD_CREATE_SECONDARY , null );
202
213
System .out .println (createAvdResult );
203
214
// throw new IOException("Error creating the AVD");
204
215
}
@@ -209,11 +220,8 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
209
220
}
210
221
211
222
212
- static public boolean ensureProperAVD (final AndroidSDK sdk , final String abi ) {
223
+ static public boolean ensureProperAVD (final AndroidSDK sdk ) {
213
224
try {
214
- defaultAVD = new AVD ("Processing-0" + Base .getRevision () + "-" + AndroidBuild .sdkVersion +
215
- "-" + abi ,
216
- "android-" + AndroidBuild .sdkVersion , abi );
217
225
if (defaultAVD .exists (sdk )) {
218
226
// System.out.println("the avd exists");
219
227
return true ;
@@ -229,12 +237,10 @@ static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) {
229
237
return true ;
230
238
}
231
239
} catch (final Exception e ) {
232
- e .printStackTrace ();
233
240
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
234
241
Base .showWarningTiered ("Android Error" , AVD_CREATE_PRIMARY ,
235
- String .format (AVD_CREATE_SECONDARY , AndroidBuild .sdkVersion ), null );
242
+ String .format (AVD_CREATE_SECONDARY , AndroidBuild .sdkVersion ), null );
236
243
}
237
- System .out .println ("at bottom of ensure proper" );
238
244
return false ;
239
245
}
240
246
}
0 commit comments