Search in sources :

Example 6 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData 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 7 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class SdksCleanupStep method shouldRemoveAnnotationsJar.

/*
   * Indicates whether annotations.jar should be removed from the given SDK (if it is an Android SDK.)
   * There are 2 issues:
   * 1. annotations.jar is not needed for API level 16 and above. The annotations are already included in android.jar. Until recently, the
   *    IDE added annotations.jar to the IDEA Android SDK definition unconditionally.
   * 2. Because annotations.jar is in the classpath, the IDE locks the file on Windows making automatic updates of SDK Tools fail. The
   *    update not only fails, it corrupts the 'tools' folder in the SDK.
   * From now on, creating IDEA Android SDKs will not include annotations.jar if API level is 16 or above, but we still need to remove
   * this jar from existing IDEA Android SDKs.
   */
private boolean shouldRemoveAnnotationsJar(@NotNull Sdk sdk) {
    if (myAndroidSdks.isAndroidSdk(sdk)) {
        AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
        AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
        boolean needsAnnotationsJar = false;
        if (additionalData != null && sdkData != null) {
            IAndroidTarget target = additionalData.getBuildTarget(sdkData);
            if (target != null) {
                needsAnnotationsJar = myAndroidSdks.needsAnnotationsJarInClasspath(target);
            }
        }
        for (VirtualFile library : sdk.getRootProvider().getFiles(CLASSES)) {
            // annotations.jar and res folder.
            if (library.getName().equals(FN_ANNOTATIONS_JAR) && library.exists() && !needsAnnotationsJar) {
                return true;
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 8 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class GradleSpecificInitializer method setupSdks.

private static void setupSdks() {
    IdeSdks ideSdks = IdeSdks.getInstance();
    File androidHome = ideSdks.getAndroidSdkPath();
    if (androidHome != null) {
        String androidHomePath = androidHome.getAbsolutePath();
        ValidationResult result = validateLocation(androidHomePath, "Android SDK location", false, WritableCheckMode.DO_NOT_CHECK);
        if (result.isError()) {
            notifyInvalidSdk();
        }
        // Do not prompt user to select SDK path (we have one already.) Instead, check SDK compatibility when a project is opened.
        return;
    }
    // If running in a GUI test we don't want the "Select SDK" dialog to show up when running GUI tests.
    if (AndroidPlugin.isGuiTestingMode()) {
        // This is good enough. Later on in the GUI test we'll validate the given SDK path.
        return;
    }
    Sdk sdk = findFirstCompatibleAndroidSdk();
    if (sdk != null) {
        String sdkHomePath = sdk.getHomePath();
        assert sdkHomePath != null;
        ideSdks.createAndroidSdkPerAndroidTarget(new File(toSystemDependentName(sdkHomePath)));
        return;
    }
    // Called in a 'invokeLater' block, otherwise file chooser will hang forever.
    ApplicationManager.getApplication().invokeLater(() -> {
        File androidSdkPath = getAndroidSdkPath();
        if (androidSdkPath == null) {
            return;
        }
        FirstRunWizardMode wizardMode = AndroidStudioWelcomeScreenProvider.getWizardMode();
        // Only show "Select SDK" dialog if the "First Run" wizard is not displayed.
        boolean promptSdkSelection = wizardMode == null;
        Sdk sdk1 = createNewAndroidPlatform(androidSdkPath.getPath(), promptSdkSelection);
        if (sdk1 != null) {
            // Rename the SDK to fit our default naming convention.
            String sdkNamePrefix = AndroidSdks.SDK_NAME_PREFIX;
            if (sdk1.getName().startsWith(sdkNamePrefix)) {
                SdkModificator sdkModificator = sdk1.getSdkModificator();
                sdkModificator.setName(sdkNamePrefix + sdk1.getName().substring(sdkNamePrefix.length()));
                sdkModificator.commitChanges();
                // Rename the JDK that goes along with this SDK.
                AndroidSdkAdditionalData additionalData = AndroidSdks.getInstance().getAndroidSdkAdditionalData(sdk1);
                if (additionalData != null) {
                    Sdk jdk = additionalData.getJavaSdk();
                    if (jdk != null) {
                        sdkModificator = jdk.getSdkModificator();
                        sdkModificator.setName(DEFAULT_JDK_NAME);
                        sdkModificator.commitChanges();
                    }
                }
                // Fill out any missing build APIs for this new SDK.
                ideSdks.createAndroidSdkPerAndroidTarget(androidSdkPath);
            }
        }
    });
}
Also used : IdeSdks(com.android.tools.idea.sdk.IdeSdks) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) FirstRunWizardMode(com.android.tools.idea.welcome.config.FirstRunWizardMode) Sdk(com.intellij.openapi.projectRoots.Sdk) ValidationResult(com.android.tools.idea.npw.WizardUtils.ValidationResult) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 9 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class AndroidSdksTest method getAndroidSdkAdditionalData.

@NotNull
private AndroidSdkAdditionalData getAndroidSdkAdditionalData(@NotNull Sdk sdk) {
    // Indirectly tests AndroidSdks#getAndroidSdkAdditionalData
    AndroidSdkAdditionalData data = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
    assertNotNull(data);
    return data;
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with AndroidSdkAdditionalData

use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.

the class AndroidSdksTest method testFindSuitableAndroidSdk.

public void testFindSuitableAndroidSdk() {
    IAndroidTarget target = findAndroidTarget();
    Sdk sdk = myAndroidSdks.create(target, mySdkPath, myJdk, false);
    assertNotNull(sdk);
    String hash = getTargetHashString(target);
    Sdk foundSdk = myAndroidSdks.findSuitableAndroidSdk(hash);
    assertNotNull(foundSdk);
    assertEquals(sdk.getHomePath(), foundSdk.getHomePath());
    AndroidSdkAdditionalData data = getAndroidSdkAdditionalData(foundSdk);
    assertEquals(hash, data.getBuildTargetHashString());
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) IAndroidTarget(com.android.sdklib.IAndroidTarget) Sdk(com.intellij.openapi.projectRoots.Sdk) AndroidTargetHash.getTargetHashString(com.android.sdklib.AndroidTargetHash.getTargetHashString)

Aggregations

AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)22 Sdk (com.intellij.openapi.projectRoots.Sdk)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)8 File (java.io.File)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)5 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)5 AndroidTargetHash.getTargetHashString (com.android.sdklib.AndroidTargetHash.getTargetHashString)4 Nullable (org.jetbrains.annotations.Nullable)4 SdkPaths.validateAndroidSdk (com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)3 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)3 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)3 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)3 AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)2 FirstRunWizardMode (com.android.tools.idea.welcome.config.FirstRunWizardMode)2 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 AndroidVersion (com.android.sdklib.AndroidVersion)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1