From 6b5d6a013228b9ae489577bfb70e9af404810195 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Tue, 28 Jul 2015 19:20:28 +0530 Subject: [PATCH 1/5] Revert "properly manage creation of AVD" This reverts commit 1cd33d50a86f75d29a84c1f3d1108a6ae30edf57. --- src/processing/mode/android/AVD.java | 98 +++++++++------------------- 1 file changed, 31 insertions(+), 67 deletions(-) diff --git a/src/processing/mode/android/AVD.java b/src/processing/mode/android/AVD.java index 2faabf5e6..5ec43985d 100644 --- a/src/processing/mode/android/AVD.java +++ b/src/processing/mode/android/AVD.java @@ -17,7 +17,7 @@ public class AVD { static private final String AVD_CREATE_SECONDARY = "The default Android emulator could not be set up. Make sure
" + "that the Android SDK is installed properly, and that the
" + - "Android and Google APIs are installed for level %s.
" + + "Android and Google APIs are installed for level " + AndroidBuild.sdkVersion + ".
" + "(Between you and me, occasionally, this error is a red herring,
" + "and your sketch may be launching shortly.)"; @@ -48,8 +48,6 @@ public class AVD { /** x86, x86_64 or armeabi **/ protected String abi; - protected VirtualDevice virtualDevice; - public static final String PREF_KEY_ABI = "android.sdk.abi"; public static final String[] ABI = {"armeabi", "x86", "x86_64"}; @@ -57,87 +55,46 @@ public class AVD { static public AVD defaultAVD; // "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion); - static ArrayList avdList; - static ArrayList badList; - - - private static class VirtualDevice { - public String name; - public String target; - public String abi; - public VirtualDevice(String name, String target, String abi) { - this.name = name; - this.target = target; - this.abi = abi; - } + static ArrayList avdList; + static ArrayList badList; +// static ArrayList skinList; - @Override - public boolean equals(Object o) { - VirtualDevice device = (VirtualDevice) o; - if (device.name.equals(name) && device.target.equals(target) - && device.abi.equals(abi)) { - return true; - } - return false; - } - } - public AVD(String name, String target, String abi) { this.name = name; this.target = target; this.abi = abi; - virtualDevice = new VirtualDevice(name, target, abi); } static protected void list(final AndroidSDK sdk) throws IOException { try { - avdList = new ArrayList(); - badList = new ArrayList(); + avdList = new ArrayList(); + badList = new ArrayList(); ProcessResult listResult = new ProcessHelper(sdk.getAndroidToolPath(), "list", "avds").execute(); if (listResult.succeeded()) { boolean badness = false; - String mTarget = null; - String mAbi = null; - String mName = null; for (String line : listResult) { String[] m = PApplet.match(line, "\\s+Name\\:\\s+(\\S+)"); if (m != null) { - mName = m[1]; - continue; - } - - m = PApplet.match(line, "API\\slevel\\s([0-9]+)"); - if (m != null) { - mTarget = m[1]; - continue; - } - - m = PApplet.match(line, "\\s+Tag\\/ABI\\:\\s\\S+\\/(\\S+)"); - if (m != null) { - mAbi = m[1]; - } - - if (mName != null && mTarget != null && mAbi != null) { - VirtualDevice mVirtualDevice = new VirtualDevice(mName, mTarget, mAbi); - mTarget = null; - mAbi = null; if (!badness) { - avdList.add(mVirtualDevice); +// System.out.println("good: " + m[1]); + avdList.add(m[1]); } else { - badList.add(mVirtualDevice); +// System.out.println("bad: " + m[1]); + badList.add(m[1]); } +// } else { +// System.out.println("nope: " + line); } - // "The following Android Virtual Devices could not be loaded:" if (line.contains("could not be loaded:")) { // System.out.println("starting the bad list"); // System.err.println("Could not list AVDs:"); // System.err.println(listResult); badness = true; - break; +// break; } } } else { @@ -152,9 +109,15 @@ protected boolean exists(final AndroidSDK sdk) throws IOException { if (avdList == null) { list(sdk); } - virtualDevice.target = AndroidBuild.sdkVersion; - virtualDevice.abi = abi; - return avdList.contains(virtualDevice); + for (String avd : avdList) { + if (Base.DEBUG) { + System.out.println("AVD.exists() checking for " + name + " against " + avd); + } + if (avd.equals(name)) { + return true; + } + } + return false; } @@ -164,7 +127,12 @@ protected boolean exists(final AndroidSDK sdk) throws IOException { * (Prestigious may also not be the right word.) */ protected boolean badness() { - return badList.contains(virtualDevice); + for (String avd : badList) { + if (avd.equals(name)) { + return true; + } + } + return false; } @@ -197,8 +165,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException { } else { // Just generally not working // Base.showWarning("Android Error", AVD_CREATE_ERROR, null); - Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, - String.format(AVD_CREATE_SECONDARY, AndroidBuild.sdkVersion), null); + Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null); System.out.println(createAvdResult); // throw new IOException("Error creating the AVD"); } @@ -211,8 +178,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException { static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) { try { - defaultAVD = new AVD("Processing-0" + Base.getRevision() + "-" + AndroidBuild.sdkVersion + - "-" + abi, + defaultAVD = new AVD("Processing-0" + Base.getRevision(), "android-" + AndroidBuild.sdkVersion, abi); if (defaultAVD.exists(sdk)) { // System.out.println("the avd exists"); @@ -229,10 +195,8 @@ static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) { return true; } } catch (final Exception e) { - e.printStackTrace(); // Base.showWarning("Android Error", AVD_CREATE_ERROR, e); - Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, - String.format(AVD_CREATE_SECONDARY, AndroidBuild.sdkVersion), null); + Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null); } System.out.println("at bottom of ensure proper"); return false; From b7fd754ae1d437b5be0797f3cca72c49187ab0d5 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Tue, 28 Jul 2015 19:23:13 +0530 Subject: [PATCH 2/5] Revert "keep an abi selected initially" This reverts commit cb74b67df95f8a45c866a271bdafa4aa80bc5f2c. --- src/processing/mode/android/AndroidEditor.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/processing/mode/android/AndroidEditor.java b/src/processing/mode/android/AndroidEditor.java index 204425a07..7b11418fa 100644 --- a/src/processing/mode/android/AndroidEditor.java +++ b/src/processing/mode/android/AndroidEditor.java @@ -251,19 +251,13 @@ public void run() { menu.addSeparator(); final JMenu abiMenu = new JMenu("Select CPU/ABI"); - boolean abiSelected = false; for (int i = 0; i < AVD.ABI.length; ++i) { JMenuItem menuItem = new JCheckBoxMenuItem(AVD.ABI[i]); abiMenu.add(menuItem); if (AVD.ABI[i].equals(Preferences.get(AVD.PREF_KEY_ABI))) { menuItem.setSelected(true); - abiSelected = true; } } - if (!abiSelected) { - abiMenu.getItem(2).setSelected(true); //Select x86_64 as the default - Preferences.set(AVD.PREF_KEY_ABI, AVD.ABI[2]); - } for (int i = 0; i < abiMenu.getItemCount(); ++i) { final JMenuItem abiItem = abiMenu.getItem(i); From 2ad0545cb4e213eca3010b0135967785454a0df7 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Tue, 28 Jul 2015 19:26:13 +0530 Subject: [PATCH 3/5] Revert "Make abi selectable while creating new AVD" This reverts commit ff8fd7f8cfcd31b6c11268110ec23d076e005b31. Conflicts: src/processing/mode/android/AVD.java src/processing/mode/android/AndroidEditor.java --- src/processing/mode/android/AVD.java | 21 +++++--------- .../mode/android/AndroidEditor.java | 28 +------------------ src/processing/mode/android/AndroidMode.java | 6 +--- 3 files changed, 9 insertions(+), 46 deletions(-) diff --git a/src/processing/mode/android/AVD.java b/src/processing/mode/android/AVD.java index 5ec43985d..92dad4cab 100644 --- a/src/processing/mode/android/AVD.java +++ b/src/processing/mode/android/AVD.java @@ -1,7 +1,6 @@ package processing.mode.android; import processing.app.Base; -//import processing.app.Preferences; import processing.app.exec.ProcessHelper; import processing.app.exec.ProcessResult; import processing.core.PApplet; @@ -44,15 +43,11 @@ public class AVD { /** "android-7" or "Google Inc.:Google APIs:7" */ protected String target; - - /** x86, x86_64 or armeabi **/ - protected String abi; - - public static final String PREF_KEY_ABI = "android.sdk.abi"; - public static final String[] ABI = {"armeabi", "x86", "x86_64"}; /** Default virtual device used by Processing. */ - static public AVD defaultAVD; + static public final AVD defaultAVD = + new AVD("Processing-0" + Base.getRevision(), + "android-" + AndroidBuild.sdkVersion); // "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion); static ArrayList avdList; @@ -60,10 +55,9 @@ public class AVD { // static ArrayList skinList; - public AVD(String name, String target, String abi) { + public AVD(final String name, final String target) { this.name = name; this.target = target; - this.abi = abi; } @@ -144,11 +138,12 @@ protected boolean create(final AndroidSDK sdk) throws IOException { "-t", target, "-c", DEFAULT_SDCARD_SIZE, "-s", DEFAULT_SKIN, - "--abi", abi + "--abi", "armeabi" }; // Set the list to null so that exists() will check again avdList = null; + final ProcessHelper p = new ProcessHelper(params); try { // Passes 'no' to "Do you wish to create a custom hardware profile [no]" @@ -176,10 +171,8 @@ protected boolean create(final AndroidSDK sdk) throws IOException { } - static public boolean ensureProperAVD(final AndroidSDK sdk, final String abi) { + static public boolean ensureProperAVD(final AndroidSDK sdk) { try { - defaultAVD = new AVD("Processing-0" + Base.getRevision(), - "android-" + AndroidBuild.sdkVersion, abi); if (defaultAVD.exists(sdk)) { // System.out.println("the avd exists"); return true; diff --git a/src/processing/mode/android/AndroidEditor.java b/src/processing/mode/android/AndroidEditor.java index 7b11418fa..13242363c 100644 --- a/src/processing/mode/android/AndroidEditor.java +++ b/src/processing/mode/android/AndroidEditor.java @@ -34,7 +34,6 @@ import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; - import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @@ -248,32 +247,7 @@ public void run() { }.start(); menu.add(sdkMenu); - menu.addSeparator(); - - final JMenu abiMenu = new JMenu("Select CPU/ABI"); - for (int i = 0; i < AVD.ABI.length; ++i) { - JMenuItem menuItem = new JCheckBoxMenuItem(AVD.ABI[i]); - abiMenu.add(menuItem); - if (AVD.ABI[i].equals(Preferences.get(AVD.PREF_KEY_ABI))) { - menuItem.setSelected(true); - } - } - - for (int i = 0; i < abiMenu.getItemCount(); ++i) { - final JMenuItem abiItem = abiMenu.getItem(i); - abiItem.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - for (int j = 0; j < abiMenu.getItemCount(); ++j) { - abiMenu.getItem(j).setSelected(false); - } - abiItem.setSelected(true); - Preferences.set(AVD.PREF_KEY_ABI, abiItem.getText()); - } - }); - } - - menu.add(abiMenu); + menu.addSeparator(); item = new JMenuItem("Android SDK Manager"); diff --git a/src/processing/mode/android/AndroidMode.java b/src/processing/mode/android/AndroidMode.java index 32680fc82..ebce1ab62 100644 --- a/src/processing/mode/android/AndroidMode.java +++ b/src/processing/mode/android/AndroidMode.java @@ -198,11 +198,7 @@ public void handleRunEmulator(Sketch sketch, RunnerListener listener) throws Ske listener.statusNotice("Building Android project..."); build.build("debug"); - String abi = Preferences.get(AVD.PREF_KEY_ABI); - if (abi.equals("")) { - abi = "x86_64"; - } - boolean avd = AVD.ensureProperAVD(sdk, abi); + boolean avd = AVD.ensureProperAVD(sdk); if (!avd) { SketchException se = new SketchException("Could not create a virtual device for the emulator."); From c9aee98d2267e28586ea7e66284a7a035f91ab8f Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Wed, 29 Jul 2015 00:39:44 +0530 Subject: [PATCH 4/5] automatically choose the best available abi for a particular API level Signed-off-by: Umair Khan --- src/processing/mode/android/AVD.java | 55 ++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/src/processing/mode/android/AVD.java b/src/processing/mode/android/AVD.java index 92dad4cab..1076b5cb1 100644 --- a/src/processing/mode/android/AVD.java +++ b/src/processing/mode/android/AVD.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; public class AVD { @@ -54,11 +55,21 @@ public class AVD { static ArrayList badList; // static ArrayList skinList; + private String[] preferredAbi = new String[50]; + private static ArrayList abiList = new ArrayList<>(); public AVD(final String name, final String target) { this.name = name; this.target = target; } + + private void initializeAbiList() { + if (abiList.size() == 0) { + abiList.add("armeabi"); + abiList.add("x86"); + abiList.add("x86_64"); + } + } static protected void list(final AndroidSDK sdk) throws IOException { @@ -131,6 +142,45 @@ protected boolean badness() { protected boolean create(final AndroidSDK sdk) throws IOException { + + final String[] list_abi = { + sdk.getAndroidToolPath(), + "list", "targets" + }; + + ProcessHelper p = new ProcessHelper(list_abi); + try { + final ProcessResult abiListResult = p.execute(); + String api = null; + String abi = null; + for (String line : abiListResult) { + String[] m = PApplet.match(line, "API\\slevel:\\s(\\S+)"); + if (m != null) { + api = m[1]; + } + + m = PApplet.match(line, "Tag\\/ABIs\\s:\\sdefault\\/(\\S+)"); + if (m != null) { + abi = m[1]; + + if (api != null && abi != null) { + int index = Integer.parseInt(api); + if (preferredAbi[index] == null) { + preferredAbi[index] = abi; + } else if (abiList.indexOf(preferredAbi[index]) < abiList.indexOf(abi)) { + preferredAbi[index] = abi; + } + api = null; + abi = null; + } + } + } + } catch (InterruptedException e) {} + + if (preferredAbi[Integer.parseInt(AndroidBuild.sdkVersion)] == null) { + return false; + } + final String[] params = { sdk.getAndroidToolPath(), "create", "avd", @@ -138,13 +188,13 @@ protected boolean create(final AndroidSDK sdk) throws IOException { "-t", target, "-c", DEFAULT_SDCARD_SIZE, "-s", DEFAULT_SKIN, - "--abi", "armeabi" + "--abi", preferredAbi[Integer.parseInt(AndroidBuild.sdkVersion)] }; // Set the list to null so that exists() will check again avdList = null; - final ProcessHelper p = new ProcessHelper(params); + p = new ProcessHelper(params); try { // Passes 'no' to "Do you wish to create a custom hardware profile [no]" // System.out.println("CREATE AVD STARTING"); @@ -191,7 +241,6 @@ static public boolean ensureProperAVD(final AndroidSDK sdk) { // Base.showWarning("Android Error", AVD_CREATE_ERROR, e); Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null); } - System.out.println("at bottom of ensure proper"); return false; } } From 30c84104b7a433beae897bd4bcb03bd6cb769e91 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Wed, 29 Jul 2015 17:09:09 +0530 Subject: [PATCH 5/5] Show proper AVD creation error Signed-off-by: Umair Khan --- src/processing/mode/android/AVD.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/processing/mode/android/AVD.java b/src/processing/mode/android/AVD.java index 1076b5cb1..3610d9718 100644 --- a/src/processing/mode/android/AVD.java +++ b/src/processing/mode/android/AVD.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; public class AVD { @@ -17,7 +16,7 @@ public class AVD { static private final String AVD_CREATE_SECONDARY = "The default Android emulator could not be set up. Make sure
" + "that the Android SDK is installed properly, and that the
" + - "Android and Google APIs are installed for level " + AndroidBuild.sdkVersion + ".
" + + "system images are installed for level %s.
" + "(Between you and me, occasionally, this error is a red herring,
" + "and your sketch may be launching shortly.)"; @@ -239,7 +238,8 @@ static public boolean ensureProperAVD(final AndroidSDK sdk) { } } catch (final Exception e) { // Base.showWarning("Android Error", AVD_CREATE_ERROR, e); - Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, AVD_CREATE_SECONDARY, null); + Base.showWarningTiered("Android Error", AVD_CREATE_PRIMARY, + String.format(AVD_CREATE_SECONDARY, AndroidBuild.sdkVersion), null); } return false; }