@@ -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 " + AndroidBuild . sdkVersion + " .<br>" +
20+ "Android and Google APIs are installed for level %s .<br>" +
2121 "(Between you and me, occasionally, this error is a red herring,<br>" +
2222 "and your sketch may be launching shortly.)" ;
2323
@@ -48,53 +48,96 @@ public class AVD {
4848 /** x86, x86_64 or armeabi-v7a **/
4949 protected String abi ;
5050
51+ protected VirtualDevice virtualDevice ;
52+
5153 public static final String PREF_KEY_ABI = "android.sdk.abi" ;
5254 public static final String [] ABI = {"armeabi-v7a" , "x86" , "x86_64" };
5355
5456 /** Default virtual device used by Processing. */
5557 static public AVD defaultAVD ;
5658// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
5759
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+ }
6173
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+
6285
6386 public AVD (String name , String target , String abi ) {
6487 this .name = name ;
6588 this .target = target ;
6689 this .abi = abi ;
90+ virtualDevice = new VirtualDevice (name , target , abi );
6791 }
6892
6993
7094 static protected void list (final AndroidSDK sdk ) throws IOException {
7195 try {
72- avdList = new ArrayList <String >();
73- badList = new ArrayList <String >();
96+ avdList = new ArrayList <VirtualDevice >();
97+ badList = new ArrayList <VirtualDevice >();
7498 ProcessResult listResult =
7599 new ProcessHelper (sdk .getAndroidToolPath (), "list" , "avds" ).execute ();
76100 if (listResult .succeeded ()) {
77101 boolean badness = false ;
102+ String mTarget = null ;
103+ String mAbi = null ;
104+ String mName = null ;
78105 for (String line : listResult ) {
79106 String [] m = PApplet .match (line , "\\ s+Name\\ :\\ s+(\\ S+)" );
80107 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 ;
81127 if (!badness ) {
82- // System.out.println("good: " + m[1]);
83- avdList .add (m [1 ]);
128+ avdList .add (mVirtualDevice );
84129 } else {
85- // System.out.println("bad: " + m[1]);
86- badList .add (m [1 ]);
130+ badList .add (mVirtualDevice );
87131 }
88- // } else {
89- // System.out.println("nope: " + line);
90132 }
133+
91134 // "The following Android Virtual Devices could not be loaded:"
92135 if (line .contains ("could not be loaded:" )) {
93136// System.out.println("starting the bad list");
94137// System.err.println("Could not list AVDs:");
95138// System.err.println(listResult);
96139 badness = true ;
97- // break;
140+ break ;
98141 }
99142 }
100143 } else {
@@ -109,15 +152,9 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
109152 if (avdList == null ) {
110153 list (sdk );
111154 }
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 );
121158 }
122159
123160
@@ -127,12 +164,7 @@ protected boolean exists(final AndroidSDK sdk) throws IOException {
127164 * (Prestigious may also not be the right word.)
128165 */
129166 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 );
136168 }
137169
138170
@@ -165,7 +197,8 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
165197 } else {
166198 // Just generally not working
167199// 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 );
169202 System .out .println (createAvdResult );
170203// throw new IOException("Error creating the AVD");
171204 }
@@ -178,7 +211,8 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
178211
179212 static public boolean ensureProperAVD (final AndroidSDK sdk , final String abi ) {
180213 try {
181- defaultAVD = new AVD ("Processing-0" + Base .getRevision (),
214+ defaultAVD = new AVD ("Processing-0" + Base .getRevision () + "-" + AndroidBuild .sdkVersion +
215+ "-" + abi ,
182216 "android-" + AndroidBuild .sdkVersion , abi );
183217 if (defaultAVD .exists (sdk )) {
184218// System.out.println("the avd exists");
@@ -195,8 +229,10 @@ static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) {
195229 return true ;
196230 }
197231 } catch (final Exception e ) {
232+ e .printStackTrace ();
198233// 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 );
200236 }
201237 System .out .println ("at bottom of ensure proper" );
202238 return false ;
0 commit comments