Search in sources :

Example 31 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class InstantRunConfigurable method updateProjectToInstantRunTools.

/** Update versions relevant for Instant Run, and trigger a Gradle sync if successful */
public static boolean updateProjectToInstantRunTools(@NotNull Project project, @Nullable GradleSyncListener listener) {
    String pluginVersion = MINIMUM_GRADLE_PLUGIN_VERSION_STRING;
    // Pick max version of "recommended Gradle plugin" and "minimum required for instant run"
    if (GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION).compareTo(MINIMUM_GRADLE_PLUGIN_VERSION) > 0) {
        pluginVersion = GRADLE_PLUGIN_RECOMMENDED_VERSION;
    }
    // Update plugin version
    AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
    UpdateResult result = updater.updatePluginVersion(GradleVersion.parse(pluginVersion), GradleVersion.parse(GRADLE_LATEST_VERSION));
    if (result.isPluginVersionUpdated() && result.versionUpdateSuccess()) {
        // Should be at least 23.0.2
        String buildToolsVersion = "23.0.2";
        AndroidSdkHandler sdk = AndroidSdks.getInstance().tryToChooseSdkHandler();
        BuildToolInfo latestBuildTool = sdk.getLatestBuildTool(new StudioLoggerProgressIndicator(InstantRunConfigurable.class), false);
        if (latestBuildTool != null) {
            Revision revision = latestBuildTool.getRevision();
            if (revision.compareTo(Revision.parseRevision(buildToolsVersion)) > 0) {
                buildToolsVersion = revision.toShortString();
            }
        }
        // Also update build files to set build tools version 23.0.2
        GradleUtil.setBuildToolsVersion(project, buildToolsVersion);
        // Also update Gradle wrapper version
        GradleWrapper gradleWrapper = GradleWrapper.find(project);
        if (gradleWrapper != null) {
            gradleWrapper.updateDistributionUrlAndDisplayFailure(GRADLE_LATEST_VERSION);
        }
        // Request a sync
        GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
        GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
        return true;
    } else {
        return false;
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater) UpdateResult(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper)

Example 32 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.

@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    boolean buildToolInstalled = false;
    AndroidSdkHandler sdkHandler = null;
    AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (androidSdkData != null) {
        sdkHandler = androidSdkData.getSdkHandler();
    }
    if (sdkHandler != null) {
        ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
        RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
        LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
        buildToolInstalled = buildTool != null;
    }
    if (module != null) {
        VirtualFile buildFile = getGradleBuildFile(module);
        AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
        if (!buildToolInstalled) {
            if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
            } else {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
            }
        } else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
            hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
        }
        if (buildFile != null) {
            hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
        }
    }
    return hyperlinks;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalPackage(com.android.repository.api.LocalPackage) FixBuildToolsVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixBuildToolsVersionHyperlink) ArrayList(java.util.ArrayList) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) InstallBuildToolsHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallBuildToolsHyperlink) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler 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)

Example 34 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class FormFactorApiComboBox method loadRemoteTargets.

private void loadRemoteTargets(final int minSdkLevel, final Runnable completedCallback, final Runnable foundItemsCallback, final Runnable noItemsCallback) {
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    final Runnable runCallbacks = () -> {
        if (completedCallback != null) {
            completedCallback.run();
        }
        if (getItemCount() > 0) {
            if (foundItemsCallback != null) {
                foundItemsCallback.run();
            }
        } else {
            if (noItemsCallback != null) {
                noItemsCallback.run();
            }
        }
    };
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        addPackages(packages.getNewPkgs(), minSdkLevel);
        addOfflineLevels();
        loadSavedApi();
        runCallbacks.run();
    };
    // We need to pick up addons that don't have a target created due to the base platform not being installed.
    RepoManager.RepoLoadedCallback onLocalComplete = packages -> addPackages(packages.getLocalPackages().values(), minSdkLevel);
    Runnable onError = () -> ApplicationManager.getApplication().invokeLater(() -> {
        addOfflineLevels();
        runCallbacks.run();
    }, ModalityState.any());
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Refreshing Targets", true, null);
    sdkHandler.getSdkManager(REPO_LOG).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(onLocalComplete), ImmutableList.of(onComplete), ImmutableList.of(onError), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : Iterables(com.google.common.collect.Iterables) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) ActionListener(java.awt.event.ActionListener) ModalityState(com.intellij.openapi.application.ModalityState) WizardConstants(com.android.tools.idea.wizard.WizardConstants) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) INSTALL_REQUESTS_KEY(com.android.tools.idea.wizard.WizardConstants.INSTALL_REQUESTS_KEY) RemotePackage(com.android.repository.api.RemotePackage) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) ConfigureAndroidProjectPath(com.android.tools.idea.npw.deprecated.ConfigureAndroidProjectPath) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidTargetManager(com.android.sdklib.repository.targets.AndroidTargetManager) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) RepoPackage(com.android.repository.api.RepoPackage) Collection(java.util.Collection) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata) Set(java.util.Set) AndroidSdkUtils(org.jetbrains.android.sdk.AndroidSdkUtils) TemplateUtils(com.android.tools.idea.templates.TemplateUtils) com.android.sdklib(com.android.sdklib) IdDisplay(com.android.sdklib.repository.IdDisplay) ScopedDataBinder(com.android.tools.idea.wizard.dynamic.ScopedDataBinder) Sets(com.google.common.collect.Sets) Sdk(com.intellij.openapi.projectRoots.Sdk) ProgressIndicator(com.android.repository.api.ProgressIndicator) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) Nullable(org.jetbrains.annotations.Nullable) ApiComboBoxItem(com.android.tools.idea.ui.ApiComboBoxItem) List(java.util.List) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) ATTR_MIN_API(com.android.tools.idea.templates.TemplateMetadata.ATTR_MIN_API) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Key(com.android.tools.idea.wizard.dynamic.ScopedStateStore.Key) RepoManager(com.android.repository.api.RepoManager) SystemImage(com.android.sdklib.repository.targets.SystemImage) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) javax.swing(javax.swing) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Example 35 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class AndroidSdksTest method testTryToChooseSdkHandler.

public void testTryToChooseSdkHandler() {
    myAndroidSdks.create(findAndroidTarget(), mySdkPath, myJdk, false);
    AndroidSdkHandler sdkHandler = myAndroidSdks.tryToChooseSdkHandler();
    AndroidSdkData sdkData = getSdkData(mySdkPath);
    assertNotNull(sdkData);
    assertSame(sdkData.getSdkHandler(), sdkHandler);
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler)

Aggregations

AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)38 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)23 File (java.io.File)11 Nullable (org.jetbrains.annotations.Nullable)11 RepoManager (com.android.repository.api.RepoManager)10 NotNull (org.jetbrains.annotations.NotNull)9 RemotePackage (com.android.repository.api.RemotePackage)8 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)8 ProgressIndicator (com.android.repository.api.ProgressIndicator)6 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)6 BuildToolInfo (com.android.sdklib.BuildToolInfo)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)6 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)6 ImmutableList (com.google.common.collect.ImmutableList)4 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 Revision (com.android.repository.Revision)3 LocalPackage (com.android.repository.api.LocalPackage)3 RepoPackage (com.android.repository.api.RepoPackage)3 FakeRepoManager (com.android.repository.testframework.FakeRepoManager)3 MockFileOp (com.android.repository.testframework.MockFileOp)3