OSDN Git Service

Add "android create avd --abi" parameter.
authorRaphael Moll <ralf@android.com>
Fri, 8 Jul 2011 21:48:17 +0000 (17:48 -0400)
committerRaphael Moll <ralf@android.com>
Wed, 3 Aug 2011 22:46:17 +0000 (15:46 -0700)
SDK bug 4965341

(cherry picked from commit 65aa2161c1ad294ef141b479b6f49dabb2edb23b)

Change-Id: Ic401e4ca56e19e416b0331baadbf742229bf60a0

sdkmanager/app/src/com/android/sdkmanager/Main.java
sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java

index 461a508..ebb2037 100644 (file)
@@ -904,6 +904,28 @@ public class Main {
     }
 
     /**
+     * Displays the ABIs valid for the given target.
+     */
+    private void displayAbiList(IAndroidTarget target, String message) {
+        String[] abis = target.getAbiList();
+        mSdkLog.printf(message);
+        if (abis != null) {
+            boolean first = true;
+            for (String skin : abis) {
+                if (first == false) {
+                    mSdkLog.printf(", ");
+                } else {
+                    first = false;
+                }
+                mSdkLog.printf(skin);
+            }
+            mSdkLog.printf("\n");
+        } else {
+            mSdkLog.printf("no ABIs.\n");
+        }
+    }
+
+    /**
      * Displays the list of available AVDs for the given AvdManager.
      *
      * @param avdManager
@@ -1106,14 +1128,26 @@ public class Main {
                 oldAvdInfo = avdManager.getAvd(avdName, false /*validAvdOnly*/);
             }
 
-            // NOTE: need to update with command line processor selectivity
+            String abiType = mSdkCommandLine.getParamAbi();
+            if (target != null && (abiType == null || abiType.length() == 0)) {
+                String[] abis = target.getAbiList();
+                if (abis != null && abis.length == 1) {
+                    // Auto-select the single ABI available
+                    abiType = abis[0];
+                    mSdkLog.printf("Auto-selecting single ABI %1$s", abiType);
+                } else {
+                    displayAbiList(target, "Valid ABIs: ");
+                    errorAndExit("This platform has more than one ABI. Please specify one using --%1$s.",
+                            SdkCommandLine.KEY_ABI);
+
+                }
+            }
 
-            String preferredAbi = SdkConstants.ABI_ARMEABI;
             @SuppressWarnings("unused") // newAvdInfo is never read, yet useful for debugging
             AvdInfo newAvdInfo = avdManager.createAvd(avdFolder,
                     avdName,
                     target,
-                    preferredAbi,
+                    abiType,
                     skin,
                     mSdkCommandLine.getParamSdCard(),
                     hardwareConfig,
index 7b73f65..9323bee 100644 (file)
@@ -82,6 +82,7 @@ class SdkCommandLine extends CommandLineProcessor {
     public static final String KEY_SNAPSHOT     = "snapshot";                       //$NON-NLS-1$
     public static final String KEY_COMPACT      = "compact";                        //$NON-NLS-1$
     public static final String KEY_EOL_NULL     = "null";                           //$NON-NLS-1$
+    public static final String KEY_ABI          = "abi";                            //$NON-NLS-1$
 
     /**
      * Action definitions for SdkManager command line.
@@ -203,6 +204,10 @@ class SdkCommandLine extends CommandLineProcessor {
         define(Mode.BOOLEAN, false,
                 VERB_CREATE, OBJECT_AVD, "a", KEY_SNAPSHOT,                         //$NON-NLS-1$
                 "Place a snapshots file in the AVD, to enable persistence.", false);
+        define(Mode.STRING, false,
+                VERB_CREATE, OBJECT_AVD, "b", KEY_ABI,                           //$NON-NLS-1$
+                "The ABI to use for the AVD. The default is to auto-select the ABI if the platform has only one ABI for its system images.",
+                null);
 
         // --- delete avd ---
 
@@ -535,6 +540,11 @@ class SdkCommandLine extends CommandLineProcessor {
         return ((String) getValue(null, null, KEY_FILTER));
     }
 
+    /** Helper to retrieve the --abi value. */
+    public String getParamAbi() {
+        return ((String) getValue(null, null, KEY_ABI));
+    }
+
     /** Helper to retrieve the --proxy-host value. */
     public String getParamProxyHost() {
         return ((String) getValue(null, null, KEY_PROXY_HOST));
index 7a3b23c..1ca7c07 100644 (file)
@@ -527,8 +527,7 @@ public class AvdManager {
             File userdataSrc = new File(imagePath, USERDATA_IMG);
 
             if (userdataSrc.exists() == false && target.isPlatform() == false) {
-                imagePath =
-                    target.getParent().getImagePath(abiType);
+                imagePath = target.getParent().getImagePath(abiType);
                 userdataSrc = new File(imagePath, USERDATA_IMG);
             }
 
@@ -836,9 +835,8 @@ public class AvdManager {
         return null;
     }
 
-    /** Copy the nominated file to the given destination.
-     * @param source
-     * @param destination
+    /**
+     * Copy the nominated file to the given destination.
      *
      * @throws FileNotFoundException
      * @throws IOException