From 06f1db5f1e0dc01f7a318b2fabbbd24f00823ca3 Mon Sep 17 00:00:00 2001 From: Raphael Moll Date: Wed, 21 Apr 2010 15:32:40 -0700 Subject: Fix auto launch config to respect minSdkVersion When launch config is in automatic mode with no preferred AVD and minSdkVersion is smaller than the project targert's API level, try to find an AVD that's as close to the minSdkVersion as possible. SDK Bug http://b.android.com/7897 Change-Id: Ied1f2db8f61c27430b466b2b7afbb5494fd0ffed --- .../internal/launch/AndroidLaunchController.java | 47 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java index 4c8621e..2f959ff 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java @@ -313,7 +313,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener } // get the project target - final IAndroidTarget projectTarget = currentSdk.getTarget(project); + IAndroidTarget projectTarget = currentSdk.getTarget(project); // FIXME: check errors on missing sdk, AVD manager, or project target. @@ -358,6 +358,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener if (preferredAvd != null) { // look for a matching device + for (IDevice d : devices) { String deviceAvd = d.getAvdName(); if (deviceAvd != null && deviceAvd.equals(config.mAvdName)) { @@ -385,6 +386,47 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener } // no (valid) preferred AVD? look for one. + + // If the API level requested in the manifest is lower than the current project + // target, when we will iterate devices/avds later ideally we will want to find + // a device/avd which target is as close to the manifest as possible (instead of + // a device which target is the same as the project's target) and use it as the + // new default. + + int reqApiLevel = 0; + try { + reqApiLevel = Integer.parseInt(requiredApiVersionNumber); + + if (reqApiLevel > 0 && reqApiLevel < projectTarget.getVersion().getApiLevel()) { + int maxDist = projectTarget.getVersion().getApiLevel() - reqApiLevel; + IAndroidTarget candidate = null; + + for (IAndroidTarget target : currentSdk.getTargets()) { + if (target.canRunOn(projectTarget)) { + int currDist = target.getVersion().getApiLevel() - reqApiLevel; + if (currDist >= 0 && currDist < maxDist) { + maxDist = currDist; + candidate = target; + if (maxDist == 0) { + // Found a perfect match + break; + } + } + } + } + + if (candidate != null) { + // We found a better SDK target candidate, that is closer to the + // API level from minSdkVersion than the one currently used by the + // project. Below (in the for...devices loop) we'll try to find + // a device/AVD for it. + projectTarget = candidate; + } + } + } catch (NumberFormatException e) { + // pass + } + HashMap compatibleRunningAvds = new HashMap(); boolean hasDevice = false; // if there's 1+ device running, we may force manual mode, // as we cannot always detect proper compatibility with @@ -507,6 +549,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener } // bring up the device chooser. + final IAndroidTarget desiredProjectTarget = projectTarget; AdtPlugin.getDisplay().asyncExec(new Runnable() { public void run() { try { @@ -514,7 +557,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener // or the AVD to launch. DeviceChooserDialog dialog = new DeviceChooserDialog( AdtPlugin.getDisplay().getActiveShell(), - response, launchInfo.getPackageName(), projectTarget); + response, launchInfo.getPackageName(), desiredProjectTarget); if (dialog.open() == Dialog.OK) { AndroidLaunchController.this.continueLaunch(response, project, launch, launchInfo, config); -- cgit v1.1