Search in sources :

Example 1 with InstallPlatformHyperlink

use of com.android.tools.idea.gradle.project.sync.hyperlink.InstallPlatformHyperlink in project android by JetBrains.

the class SdksCleanupStep method reinstallMissingPlatforms.

private void reinstallMissingPlatforms(@NotNull Collection<Sdk> invalidAndroidSdks, @NotNull Project project) {
    List<AndroidVersion> versionsToInstall = Lists.newArrayList();
    List<String> missingPlatforms = Lists.newArrayList();
    for (Sdk sdk : invalidAndroidSdks) {
        AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
        if (additionalData != null) {
            String platform = additionalData.getBuildTargetHashString();
            if (platform != null) {
                missingPlatforms.add("'" + platform + "'");
                AndroidVersion version = AndroidTargetHash.getPlatformVersion(platform);
                if (version != null) {
                    versionsToInstall.add(version);
                }
            }
        }
    }
    if (!versionsToInstall.isEmpty()) {
        String text = "Missing Android platform(s) detected: " + Joiner.on(", ").join(missingPlatforms);
        SyncMessage msg = new SyncMessage(SyncMessage.DEFAULT_GROUP, ERROR, text);
        msg.add(new InstallPlatformHyperlink(versionsToInstall));
        SyncMessages.getInstance(project).report(msg);
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) Sdk(com.intellij.openapi.projectRoots.Sdk) AndroidVersion(com.android.sdklib.AndroidVersion) InstallPlatformHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallPlatformHyperlink)

Example 2 with InstallPlatformHyperlink

use of com.android.tools.idea.gradle.project.sync.hyperlink.InstallPlatformHyperlink in project android by JetBrains.

the class MissingPlatformErrorHandler method findAndAddQuickFixes.

private void findAndAddQuickFixes(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
    String missingPlatform = getMissingPlatform(text);
    if (missingPlatform == null) {
        return;
    }
    String loadError = null;
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    AndroidSdkHandler sdkHandler = null;
    AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (androidSdkData != null) {
        sdkHandler = androidSdkData.getSdkHandler();
    }
    if (sdkHandler != null) {
        AndroidVersion version = AndroidTargetHash.getPlatformVersion(missingPlatform);
        if (version != null) {
            // Is the platform installed?
            ProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
            loadError = sdkHandler.getAndroidTargetManager(logger).getErrorForPackage(DetailsTypes.getPlatformPath(version));
            hyperlinks.add(new InstallPlatformHyperlink(version));
        }
    }
    if (hyperlinks.isEmpty()) {
        // We are unable to install platform automatically.
        List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
        if (!facets.isEmpty()) {
            // We can only open SDK manager if the project has an Android facet. Android facet has a reference to the Android SDK manager.
            hyperlinks.add(new OpenAndroidSdkManagerHyperlink());
        }
    }
    if (isNotEmpty(loadError)) {
        text += "\nPossible cause: " + loadError;
    }
    SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
Also used : OpenAndroidSdkManagerHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenAndroidSdkManagerHyperlink) ArrayList(java.util.ArrayList) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidVersion(com.android.sdklib.AndroidVersion) InstallPlatformHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallPlatformHyperlink) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)2 InstallPlatformHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.InstallPlatformHyperlink)2 ProgressIndicator (com.android.repository.api.ProgressIndicator)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 OpenAndroidSdkManagerHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.OpenAndroidSdkManagerHyperlink)1 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ArrayList (java.util.ArrayList)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)1 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)1