Search in sources :

Example 46 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class DeveloperServiceCreator method createContext.

@NotNull
private static ServiceContext createContext(@NotNull Module module) {
    String buildSystemId = getBuildSystemOperations(module.getProject()).getBuildSystemId();
    ServiceContext context = new ServiceContext(buildSystemId);
    String packageName = MergedManifest.get(module).getPackage();
    if (packageName != null) {
        context.putValue("packageName", new StringValueProperty(packageName));
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform != null) {
        // Add the compileSdkVersion (or buildApiVersion) such that compatible dependencies are chosen
        AndroidVersion version = platform.getApiVersion();
        context.putValue(ATTR_BUILD_API, new IntValueProperty(version.getFeatureLevel()));
        context.putValue(ATTR_BUILD_API_STRING, new StringValueProperty(getBuildApiString(version)));
    }
    return context;
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) StringValueProperty(com.android.tools.idea.ui.properties.core.StringValueProperty) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) TemplateMetadata.getBuildApiString(com.android.tools.idea.templates.TemplateMetadata.getBuildApiString) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class AndroidSdkUtils method getTargetLabel.

/**
   * For a given target, returns a brief user-facing string that describes the platform, including the API level, platform version number,
   * and codename. Does the right thing with pre-release platforms.
   */
@NotNull
public static String getTargetLabel(@NotNull IAndroidTarget target) {
    if (!target.isPlatform()) {
        return String.format("%1$s (API %2$s)", target.getFullName(), target.getVersion().getApiString());
    }
    AndroidVersion version = target.getVersion();
    if (version.isPreview()) {
        return String.format("API %d+: %s", target.getVersion().getApiLevel(), target.getName());
    }
    String name = SdkVersionInfo.getAndroidName(target.getVersion().getApiLevel());
    if (isNotEmpty(name)) {
        return name;
    }
    //$NON-NLS-1$
    String release = target.getProperty("ro.build.version.release");
    if (release != null) {
        return String.format("API %1$d: Android %2$s", version.getApiLevel(), release);
    }
    return String.format("API %1$d", version.getApiLevel());
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class AndroidSdkType method setupSdkPaths.

@Override
public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) {
    final List<String> javaSdks = Lists.newArrayList();
    final Sdk[] sdks = sdkModel.getSdks();
    for (Sdk jdk : sdks) {
        if (Jdks.getInstance().isApplicableJdk(jdk)) {
            javaSdks.add(jdk.getName());
        }
    }
    if (javaSdks.isEmpty()) {
        Messages.showErrorDialog(AndroidBundle.message("no.jdk.for.android.found.error"), "No Java SDK Found");
        return false;
    }
    MessageBuildingSdkLog log = new MessageBuildingSdkLog();
    AndroidSdkData sdkData = getSdkData(sdk);
    if (sdkData == null) {
        String errorMessage = !log.getErrorMessage().isEmpty() ? log.getErrorMessage() : AndroidBundle.message("cannot.parse.sdk.error");
        Messages.showErrorDialog(errorMessage, "SDK Parsing Error");
        return false;
    }
    IAndroidTarget[] targets = sdkData.getTargets();
    if (targets.length == 0) {
        if (Messages.showOkCancelDialog(AndroidBundle.message("no.android.targets.error"), CommonBundle.getErrorTitle(), "Open SDK Manager", Messages.CANCEL_BUTTON, Messages.getErrorIcon()) == Messages.OK) {
            ActionManager.getInstance().getAction("Android.RunAndroidSdkManager").actionPerformed(null);
        }
        return false;
    }
    String[] targetNames = new String[targets.length];
    String newestPlatform = null;
    AndroidVersion version = null;
    for (int i = 0; i < targets.length; i++) {
        IAndroidTarget target = targets[i];
        String targetName = getTargetPresentableName(target);
        targetNames[i] = targetName;
        if (target.isPlatform() && (version == null || target.getVersion().compareTo(version) > 0)) {
            newestPlatform = targetName;
            version = target.getVersion();
        }
    }
    AndroidNewSdkDialog dialog = new AndroidNewSdkDialog(null, javaSdks, javaSdks.get(0), Arrays.asList(targetNames), newestPlatform != null ? newestPlatform : targetNames[0]);
    if (!dialog.showAndGet()) {
        return false;
    }
    String name = javaSdks.get(dialog.getSelectedJavaSdkIndex());
    Sdk jdk = sdkModel.findSdk(name);
    IAndroidTarget target = targets[dialog.getSelectedTargetIndex()];
    String sdkName = AndroidSdks.getInstance().chooseNameForNewLibrary(target);
    AndroidSdks.getInstance().setUpSdk(sdk, target, sdkName, Arrays.asList(sdks), jdk, true);
    return true;
}
Also used : SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 49 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class SystemImagePreview method setImage.

/**
   * Set the image to display.
   */
public void setImage(@Nullable SystemImageDescription image) {
    myImageDescription = image;
    myHaxmAlert.setSystemImageDescription(image);
    ((CardLayout) myRootPanel.getLayout()).show(myRootPanel, NO_IMAGE_CONTENT);
    if (image != null) {
        ((CardLayout) myRootPanel.getLayout()).show(myRootPanel, MAIN_CONTENT);
        AndroidVersion version = image.getVersion();
        if (version == null) {
            return;
        }
        int apiLevel = version.getApiLevel();
        myApiLevelListener.setApiLevel(apiLevel);
        String codeName = SdkVersionInfo.getCodeName(myImageDescription.getVersion().getApiLevel());
        if (codeName != null) {
            myReleaseName.setText(codeName);
        }
        Icon icon = getIcon(codeName);
        if (icon != null) {
            myReleaseIcon.setIcon(icon);
        }
        myApiLevel.setText(image.getVersion().getApiString());
        myAndroidVersion.setVisible(!image.getVersion().isPreview());
        myAndroidVersion.setText(SdkVersionInfo.getVersionString(apiLevel));
        String vendorName;
        IdDisplay tag = myImageDescription.getTag();
        if (tag.getId().equals("android-wear") || tag.getId().equals("android-tv")) {
            vendorName = "Android";
        } else {
            vendorName = myImageDescription.getVendor();
        }
        myVendor.setText("<html>" + vendorName + "</html>");
        myAbi.setText(myImageDescription.getAbiType());
    }
}
Also used : IdDisplay(com.android.sdklib.repository.IdDisplay) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 50 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class AndroidVersionsInfo method getInstallRequestPaths.

@NotNull
public Collection<String> getInstallRequestPaths(@NotNull VersionItem... versionItems) {
    Set<String> res = Sets.newHashSet();
    for (VersionItem versionItem : versionItems) {
        AndroidVersion androidVersion = versionItem.myAndroidVersion;
        String platformPath = DetailsTypes.getPlatformPath(androidVersion);
        // Check to see if this is installed. If not, request that we install it
        if (versionItem.myAddon != null) {
            // The user selected a non platform SDK (e.g. for Google Glass). Let us install it:
            res.add(versionItem.myAddon.getPath());
            // We also need the platform if not already installed:
            AndroidTargetManager targetManager = AndroidSdks.getInstance().tryToChooseSdkHandler().getAndroidTargetManager(REPO_LOG);
            if (targetManager.getTargetFromHashString(AndroidTargetHash.getPlatformHashString(androidVersion), REPO_LOG) == null) {
                res.add(platformPath);
            }
        } else {
            // unlikely, so this logic can wait for a followup CL.
            if (myHighestInstalledApiTarget == null || (androidVersion.getApiLevel() > myHighestInstalledApiTarget.getVersion().getApiLevel() && !myInstalledVersions.contains(androidVersion))) {
                // Let us install the HIGHEST_KNOWN_STABLE_API.
                res.add(DetailsTypes.getPlatformPath(new AndroidVersion(SdkVersionInfo.HIGHEST_KNOWN_STABLE_API, null)));
            }
        }
    }
    return res;
}
Also used : AndroidTargetManager(com.android.sdklib.repository.targets.AndroidTargetManager) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)89 Test (org.junit.Test)21 NotNull (org.jetbrains.annotations.NotNull)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)12 IDevice (com.android.ddmlib.IDevice)11 Nullable (org.jetbrains.annotations.Nullable)9 MockPlatformTarget (com.android.sdklib.internal.androidTarget.MockPlatformTarget)8 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)8 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)6 Project (com.intellij.openapi.project.Project)5 Abi (com.android.sdklib.devices.Abi)4 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 OutputFile (com.android.build.OutputFile)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3