Search in sources :

Example 16 with AndroidSdkData

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

the class AndroidSdksTest method testSetSdkData.

public void testSetSdkData() {
    AndroidSdkData data = mock(AndroidSdkData.class);
    myAndroidSdks.setSdkData(data);
    assertSame(data, myAndroidSdks.tryToChooseAndroidSdk());
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData)

Example 17 with AndroidSdkData

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

the class AndroidSdksTest method findAndroidTarget.

@NotNull
private IAndroidTarget findAndroidTarget() {
    AndroidSdkData sdkData = getSdkData(mySdkPath);
    assertNotNull(sdkData);
    IAndroidTarget[] targets = sdkData.getTargets(false);
    assertThat(targets).isNotEmpty();
    // Use the latest platform, which is checked-in as a full SDK. Older platforms may not be checked in full, to save space.
    IAndroidTarget result = ContainerUtil.find(targets, target -> target.hashString().equals(TestUtils.getLatestAndroidPlatform()));
    assertThat(result).isNotNull();
    return result;
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IAndroidTarget(com.android.sdklib.IAndroidTarget) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with AndroidSdkData

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

the class AndroidSdksTest method testTryToChooseAndroidSdk.

public void testTryToChooseAndroidSdk() {
    myAndroidSdks.create(findAndroidTarget(), mySdkPath, myJdk, false);
    AndroidSdkData sdkData = myAndroidSdks.tryToChooseAndroidSdk();
    assertSame(getSdkData(mySdkPath), sdkData);
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData)

Example 19 with AndroidSdkData

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

the class IdeSdksTest method assertOneSdkPerAvailableTarget.

private void assertOneSdkPerAvailableTarget(@NotNull List<Sdk> sdks) {
    List<IAndroidTarget> platformTargets = Lists.newArrayList();
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(myAndroidSdkPath);
    assertNotNull(sdkData);
    for (IAndroidTarget target : sdkData.getTargets()) {
        if (target.isPlatform()) {
            platformTargets.add(target);
        }
    }
    assertEquals(platformTargets.size(), sdks.size());
    for (Sdk sdk : sdks) {
        AndroidPlatform androidPlatform = AndroidPlatform.getInstance(sdk);
        assertNotNull(androidPlatform);
        IAndroidTarget target = androidPlatform.getTarget();
        platformTargets.remove(target);
    }
    assertEquals(0, platformTargets.size());
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 20 with AndroidSdkData

use of org.jetbrains.android.sdk.AndroidSdkData 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)

Aggregations

AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)39 IAndroidTarget (com.android.sdklib.IAndroidTarget)15 File (java.io.File)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Sdk (com.intellij.openapi.projectRoots.Sdk)9 NotNull (org.jetbrains.annotations.NotNull)7 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)6 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)6 Nullable (org.jetbrains.annotations.Nullable)6 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)5 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)5 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AndroidVersion (com.android.sdklib.AndroidVersion)3 NewProjectWizardState (com.android.tools.idea.npw.NewProjectWizardState)3 SdkPaths.validateAndroidSdk (com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)3 TemplateWizardState (com.android.tools.idea.wizard.template.TemplateWizardState)3 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)3 ProgressIndicator (com.android.repository.api.ProgressIndicator)2