Skip to content

Commit c9aee98

Browse files
committed
automatically choose the best available abi for a particular API level
Signed-off-by: Umair Khan <[email protected]>
1 parent 2ad0545 commit c9aee98

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

src/processing/mode/android/AVD.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.io.IOException;
99
import java.util.ArrayList;
10+
import java.util.Arrays;
1011

1112

1213
public class AVD {
@@ -54,11 +55,21 @@ public class AVD {
5455
static ArrayList<String> badList;
5556
// static ArrayList<String> skinList;
5657

58+
private String[] preferredAbi = new String[50];
59+
private static ArrayList<String> abiList = new ArrayList<>();
5760

5861
public AVD(final String name, final String target) {
5962
this.name = name;
6063
this.target = target;
6164
}
65+
66+
private void initializeAbiList() {
67+
if (abiList.size() == 0) {
68+
abiList.add("armeabi");
69+
abiList.add("x86");
70+
abiList.add("x86_64");
71+
}
72+
}
6273

6374

6475
static protected void list(final AndroidSDK sdk) throws IOException {
@@ -131,20 +142,59 @@ protected boolean badness() {
131142

132143

133144
protected boolean create(final AndroidSDK sdk) throws IOException {
145+
146+
final String[] list_abi = {
147+
sdk.getAndroidToolPath(),
148+
"list", "targets"
149+
};
150+
151+
ProcessHelper p = new ProcessHelper(list_abi);
152+
try {
153+
final ProcessResult abiListResult = p.execute();
154+
String api = null;
155+
String abi = null;
156+
for (String line : abiListResult) {
157+
String[] m = PApplet.match(line, "API\\slevel:\\s(\\S+)");
158+
if (m != null) {
159+
api = m[1];
160+
}
161+
162+
m = PApplet.match(line, "Tag\\/ABIs\\s:\\sdefault\\/(\\S+)");
163+
if (m != null) {
164+
abi = m[1];
165+
166+
if (api != null && abi != null) {
167+
int index = Integer.parseInt(api);
168+
if (preferredAbi[index] == null) {
169+
preferredAbi[index] = abi;
170+
} else if (abiList.indexOf(preferredAbi[index]) < abiList.indexOf(abi)) {
171+
preferredAbi[index] = abi;
172+
}
173+
api = null;
174+
abi = null;
175+
}
176+
}
177+
}
178+
} catch (InterruptedException e) {}
179+
180+
if (preferredAbi[Integer.parseInt(AndroidBuild.sdkVersion)] == null) {
181+
return false;
182+
}
183+
134184
final String[] params = {
135185
sdk.getAndroidToolPath(),
136186
"create", "avd",
137187
"-n", name,
138188
"-t", target,
139189
"-c", DEFAULT_SDCARD_SIZE,
140190
"-s", DEFAULT_SKIN,
141-
"--abi", "armeabi"
191+
"--abi", preferredAbi[Integer.parseInt(AndroidBuild.sdkVersion)]
142192
};
143193

144194
// Set the list to null so that exists() will check again
145195
avdList = null;
146196

147-
final ProcessHelper p = new ProcessHelper(params);
197+
p = new ProcessHelper(params);
148198
try {
149199
// Passes 'no' to "Do you wish to create a custom hardware profile [no]"
150200
// System.out.println("CREATE AVD STARTING");
@@ -191,7 +241,6 @@ static public boolean ensureProperAVD(final AndroidSDK sdk) {
191241
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
192242
Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null);
193243
}
194-
System.out.println("at bottom of ensure proper");
195244
return false;
196245
}
197246
}

0 commit comments

Comments
 (0)