Search in sources :

Example 11 with AndroidSdkHandler

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

the class InstallNdkHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    File path = getNdkPath(project);
    if (path != null) {
        // Try to install SDK in local.properties.
        SelectNdkDialog dialog = new SelectNdkDialog(path.getPath(), false, true);
        dialog.setModal(true);
        if (dialog.showAndGet() && setNdkPath(project, dialog.getAndroidNdkPath())) {
            // Saving NDK path is successful.
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
        }
        return;
    }
    // There is no path. Try installing from SDK.
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    StudioLoggerProgressIndicator progressIndicator = new StudioLoggerProgressIndicator(getClass());
    RepoManager sdkManager = sdkHandler.getSdkManager(progressIndicator);
    StudioProgressRunner progressRunner = new StudioProgressRunner(false, /* backgroundable */
    false, /* cancellable */
    "Loading Remote SDK", true, /* in UI thread */
    project);
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        Map<String, RemotePackage> remotePackages = packages.getRemotePackages();
        RemotePackage ndkPackage = remotePackages.get(FD_NDK);
        if (ndkPackage != null) {
            ModelWizardDialog dialog = createDialogForPaths(project, ImmutableList.of(ndkPackage.getPath()));
            if (dialog != null && dialog.showAndGet()) {
                GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
            }
            return;
        }
        notifyNdkPackageNotFound(project);
    };
    Runnable onError = () -> notifyNdkPackageNotFound(project);
    sdkManager.load(DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), ImmutableList.of(onError), progressRunner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IOException(java.io.IOException) DEFAULT_EXPIRATION_PERIOD_MS(com.android.repository.api.RepoManager.DEFAULT_EXPIRATION_PERIOD_MS) RemotePackage(com.android.repository.api.RemotePackage) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) File(java.io.File) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable) SelectNdkDialog(com.android.tools.idea.sdk.SelectNdkDialog) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Map(java.util.Map) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) RepoManager(com.android.repository.api.RepoManager) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) FD_NDK(com.android.SdkConstants.FD_NDK) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) SdkQuickfixUtils.createDialogForPaths(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.createDialogForPaths) SelectNdkDialog(com.android.tools.idea.sdk.SelectNdkDialog) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepoManager(com.android.repository.api.RepoManager) File(java.io.File) Map(java.util.Map) RemotePackage(com.android.repository.api.RemotePackage) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 12 with AndroidSdkHandler

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

the class SmwOldApiDirectInstall method startSdkInstallUsingNonSwtOldApi.

private void startSdkInstallUsingNonSwtOldApi() {
    // Get the SDK instance.
    final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    if (sdkHandler.getLocation() == null) {
        myErrorLabel.setText("Error: can't get SDK instance.");
        myErrorLabel.setIcon(AllIcons.General.BalloonError);
        return;
    }
    File androidSdkPath = IdeSdks.getInstance().getAndroidSdkPath();
    if (androidSdkPath != null && androidSdkPath.exists() && !androidSdkPath.canWrite()) {
        myErrorLabel.setText(String.format("SDK folder is read-only: '%1$s'", androidSdkPath.getPath()));
        myErrorLabel.setIcon(AllIcons.General.BalloonError);
        return;
    }
    myLabelSdkPath.setText(sdkHandler.getLocation().getPath());
    final CustomLogger logger = new CustomLogger();
    final com.android.repository.api.ProgressIndicator repoProgress = new StudioLoggerProgressIndicator(getClass());
    RepoManager.RepoLoadedCallback onComplete = packages -> UIUtil.invokeLaterIfNeeded(() -> {
        List<String> requestedChanges = myState.get(INSTALL_REQUESTS_KEY);
        if (requestedChanges == null) {
            assert false : "Shouldn't be in installer with no requests";
            myInstallFinished = true;
            invokeUpdate(null);
            return;
        }
        Map<String, RemotePackage> remotes = packages.getRemotePackages();
        List<RemotePackage> requestedPackages = Lists.newArrayList();
        boolean notFound = false;
        for (String path : requestedChanges) {
            RemotePackage remotePackage = remotes.get(path);
            if (remotePackage != null) {
                requestedPackages.add(remotePackage);
            } else {
                notFound = true;
            }
        }
        if (requestedPackages.isEmpty()) {
            myInstallFinished = true;
            invokeUpdate(null);
        } else {
            requestedPackages = InstallerUtil.computeRequiredPackages(requestedPackages, packages, repoProgress);
            if (requestedPackages == null) {
                notFound = true;
            } else {
                InstallTask task = new InstallTask(sdkHandler, requestedPackages, logger);
                BackgroundableProcessIndicator indicator = new BackgroundableProcessIndicator(task);
                logger.setIndicator(indicator);
                ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
            }
        }
        if (notFound) {
            myErrorLabel.setText("Problem: Some required packages could not be installed. Check internet connection.");
            myErrorLabel.setIcon(AllIcons.General.BalloonError);
        }
    });
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Updating SDK", false, null);
    sdkHandler.getSdkManager(repoProgress).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, null, ImmutableList.of(onComplete), null, runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
Also used : ILogger(com.android.utils.ILogger) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) StudioSdkInstallerUtil(com.android.tools.idea.sdk.install.StudioSdkInstallerUtil) NEWLY_INSTALLED_API_KEY(com.android.tools.idea.wizard.WizardConstants.NEWLY_INSTALLED_API_KEY) FileOp(com.android.repository.io.FileOp) INSTALL_REQUESTS_KEY(com.android.tools.idea.wizard.WizardConstants.INSTALL_REQUESTS_KEY) JBLabel(com.intellij.ui.components.JBLabel) RemotePackage(com.android.repository.api.RemotePackage) IPkgDesc(com.android.sdklib.repository.legacy.descriptors.IPkgDesc) Lists(com.google.common.collect.Lists) Task(com.intellij.openapi.progress.Task) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Map(java.util.Map) InstallerFactory(com.android.repository.api.InstallerFactory) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) ProgressManager(com.intellij.openapi.progress.ProgressManager) Installer(com.android.repository.api.Installer) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidVersion(com.android.sdklib.AndroidVersion) PkgType(com.android.sdklib.repository.legacy.descriptors.PkgType) LoggerProgressIndicatorWrapper(com.android.sdklib.repository.LoggerProgressIndicatorWrapper) InstallerUtil(com.android.repository.util.InstallerUtil) Disposable(com.intellij.openapi.Disposable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) com.android.tools.idea.sdk(com.android.tools.idea.sdk) DynamicWizardStepWithDescription(com.android.tools.idea.wizard.dynamic.DynamicWizardStepWithDescription) InstallSelectedPackagesStep(com.android.tools.idea.sdk.wizard.InstallSelectedPackagesStep) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) FileOpUtils(com.android.repository.io.FileOpUtils) RepoManager(com.android.repository.api.RepoManager) NotNull(org.jetbrains.annotations.NotNull) PerformInBackgroundOption(com.intellij.openapi.progress.PerformInBackgroundOption) javax.swing(javax.swing) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepoManager(com.android.repository.api.RepoManager) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) RemotePackage(com.android.repository.api.RemotePackage)

Example 13 with AndroidSdkHandler

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

the class RepositoryUrlManagerTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    myFileOp = new MockFileOp();
    myRepositoryUrlManager = new RepositoryUrlManager(true);
    mySdkHandler = new AndroidSdkHandler(SDK_DIR, ANDROID_HOME, myFileOp);
    mySdk = Mockito.mock(AndroidSdkData.class);
    Mockito.when(mySdk.getLocation()).thenReturn(SDK_DIR);
    String[] paths = new String[] { // Android repository
    "extras/android/m2repository/com/android/support/appcompat-v7/18.0.0/appcompat-v7-18.0.0.aar", "extras/android/m2repository/com/android/support/appcompat-v7/19.0.0/appcompat-v7-19.0.0.aar", "extras/android/m2repository/com/android/support/appcompat-v7/19.0.1/appcompat-v7-19.0.1.aar", "extras/android/m2repository/com/android/support/appcompat-v7/19.1.0/appcompat-v7-19.1.0.aar", "extras/android/m2repository/com/android/support/appcompat-v7/20.0.0/appcompat-v7-20.0.0.aar", "extras/android/m2repository/com/android/support/appcompat-v7/21.0.0/appcompat-v7-21.0.0.aar", "extras/android/m2repository/com/android/support/appcompat-v7/21.0.2/appcompat-v7-21.0.2.aar", "extras/android/m2repository/com/android/support/cardview-v7/21.0.0/cardview-v7-21.0.0.aar", "extras/android/m2repository/com/android/support/cardview-v7/21.0.2/cardview-v7-21.0.2.aar", "extras/android/m2repository/com/android/support/support-v13/20.0.0/support-v13-20.0.0.aar", "extras/android/m2repository/com/android/support/support-v13/21.0.0/support-v13-21.0.0.aar", "extras/android/m2repository/com/android/support/support-v13/21.0.2/support-v13-21.0.2.aar", // JARs were used before 19.0.0
    "extras/android/m2repository/com/android/support/support-v4/13.0.0/support-v4-13.0.0.jar", "extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.aar", "extras/android/m2repository/com/android/support/support-v4/20.0.0/support-v4-20.0.0.aar", "extras/android/m2repository/com/android/support/support-v4/20.0.0/support-v4-20.0.0-rc1.aar", "extras/android/m2repository/com/android/support/support-v4/21.0.0/support-v4-21.0.0.aar", "extras/android/m2repository/com/android/support/support-v4/21.0.2/support-v4-21.0.2.aar", "extras/android/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha7/constraint-layout-1.0.0-alpha7.aar", // Google repository
    "extras/google/m2repository/com/google/android/gms/play-services/3.1.36/play-services-3.1.36.aar", "extras/google/m2repository/com/google/android/gms/play-services/3.1.59/play-services-3.1.59.aar", "extras/google/m2repository/com/google/android/gms/play-services/3.2.25/play-services-3.2.25.aar", "extras/google/m2repository/com/google/android/gms/play-services/3.2.65/play-services-3.2.65.aar", "extras/google/m2repository/com/google/android/gms/play-services/4.0.30/play-services-4.0.30.aar", "extras/google/m2repository/com/google/android/gms/play-services/4.1.32/play-services-4.1.32.aar", "extras/google/m2repository/com/google/android/gms/play-services/4.2.42/play-services-4.2.42.aar", "extras/google/m2repository/com/google/android/gms/play-services/4.3.23/play-services-4.3.23.aar", "extras/google/m2repository/com/google/android/gms/play-services/4.4.52/play-services-4.4.52.aar", "extras/google/m2repository/com/google/android/gms/play-services/5.0.89/play-services-5.0.89.aar", "extras/google/m2repository/com/google/android/gms/play-services/5.2.08/play-services-5.2.08.aar", "extras/google/m2repository/com/google/android/gms/play-services-wearable/5.0.77/play-services-wearable-5.0.77.aar", "extras/google/m2repository/com/google/android/gms/play-services-wearable/6.1.11/play-services-wearable-6.1.11.aar", "extras/google/m2repository/com/google/android/gms/play-services-wearable/6.1.71/play-services-wearable-6.1.71.aar", "extras/google/m2repository/com/google/android/support/wearable/1.0.0/wearable-1.0.0.aar", "extras/google/m2repository/com/google/android.wearable/wearable/2.0.0-alpha2/wearable-2.0.0-alpha2.aar" };
    for (String path : paths) {
        myFileOp.createNewFile(new File(SDK_DIR, path));
    }
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) MockFileOp(com.android.repository.testframework.MockFileOp) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) File(java.io.File)

Example 14 with AndroidSdkHandler

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

the class RepositoryUrlManagerTest method testResolvedCoordinateRemoteSdk.

public void testResolvedCoordinateRemoteSdk() throws Exception {
    RemotePackage pkg = new FakePackage.FakeRemotePackage("extras;m2repository;com;google;android;gms;play-services;4.5.0");
    RepositoryPackages pkgs = new RepositoryPackages(ImmutableList.of(), ImmutableList.of(pkg));
    RepoManager mgr = new FakeRepoManager(pkgs);
    mySdkHandler = new AndroidSdkHandler(new File("/emptysdk"), ANDROID_HOME, myFileOp, mgr);
    GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString("com.google.android.gms:play-services:4.+");
    assertNotNull(coordinate);
    assertEquals("4.5.0", resolveDynamicCoordinateVersion(coordinate));
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) RepoManager(com.android.repository.api.RepoManager) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) RemotePackage(com.android.repository.api.RemotePackage) File(java.io.File)

Example 15 with AndroidSdkHandler

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

the class AndroidJpsUtil method getAndroidPlatform.

@Nullable
public static AndroidPlatform getAndroidPlatform(@NotNull JpsModule module, @Nullable CompileContext context, String builderName) {
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> sdk = module.getSdk(JpsAndroidSdkType.INSTANCE);
    if (sdk == null) {
        if (context != null) {
            context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.sdk.not.specified", module.getName())));
        }
        return null;
    }
    final Pair<IAndroidTarget, AndroidSdkHandler> pair = getAndroidTarget(sdk, context, builderName);
    if (pair == null) {
        if (context != null) {
            context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.sdk.invalid", module.getName())));
        }
        return null;
    }
    return new AndroidPlatform(sdk, pair.getFirst(), pair.getSecond());
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable)

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