Search in sources :

Example 46 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget 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 47 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class VaryingConfiguration method getTarget.

@Override
@Nullable
public IAndroidTarget getTarget() {
    if (isOverridingTarget()) {
        return super.getTarget();
    }
    IAndroidTarget target = myParent.getTarget();
    if (isAlternatingTarget() && target != null) {
        ConfigurationManager manager = getConfigurationManager();
        IAndroidTarget[] targets = manager.getTargets();
        if (targets.length > 0) {
            // Pick a different target: if you're showing the most recent render target,
            // then pick the lowest supported target, and vice versa
            IAndroidTarget mostRecent = manager.getHighestApiTarget();
            if (target.equals(mostRecent)) {
                // Find oldest supported
                AndroidModuleInfo info = AndroidModuleInfo.get(manager.getModule());
                if (info != null) {
                    int minSdkVersion = info.getMinSdkVersion().getFeatureLevel();
                    for (IAndroidTarget t : targets) {
                        if (t.getVersion().getFeatureLevel() >= minSdkVersion && ConfigurationManager.isLayoutLibTarget(t)) {
                            target = t;
                            break;
                        }
                    }
                }
            } else {
                target = mostRecent;
            }
        }
    }
    return target;
}
Also used : AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget 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 49 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class ResolutionUtils method getFolderConfiguration.

/**
   * Gets the {@link FolderConfiguration} of a ResourceValue
   * e.g. if we resolve a drawable using a mdpi configuration, yet that drawable only exists inside xhdpi, this method will return xhdpi
   * @param configuration the FolderConfiguration that was used for resolving the ResourceValue
   * @return the FolderConfiguration of the ResourceValue
   */
@NotNull
public static FolderConfiguration getFolderConfiguration(@NotNull AndroidFacet facet, @NotNull ResourceValue resolvedValue, @NotNull FolderConfiguration configuration) {
    List<? extends Configurable> configurables;
    if (resolvedValue.isFramework()) {
        ConfigurationManager configurationManager = facet.getConfigurationManager();
        // same as getHighestApiTarget();
        IAndroidTarget target = configurationManager.getDefaultTarget();
        assert target != null;
        ResourceRepository resourceRepository = configurationManager.getResolverCache().getFrameworkResources(configuration, target);
        assert resourceRepository != null;
        ResourceItem resourceItem = resourceRepository.getResourceItem(resolvedValue.getResourceType(), resolvedValue.getName());
        configurables = resourceItem.getSourceFileList();
    } else {
        AppResourceRepository appResourceRepository = facet.getAppResources(true);
        configurables = appResourceRepository.getResourceItem(resolvedValue.getResourceType(), resolvedValue.getName());
    }
    Configurable configurable = configuration.findMatchingConfigurable(configurables);
    assert configurable != null;
    return configurable.getConfiguration();
}
Also used : AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) IAndroidTarget(com.android.sdklib.IAndroidTarget) Configurable(com.android.ide.common.resources.configuration.Configurable) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class GradleSpecificInitializer method checkAndSetSources.

private static void checkAndSetSources(@NotNull Sdk sdk) {
    VirtualFile[] storedSources = sdk.getRootProvider().getFiles(OrderRootType.SOURCES);
    if (storedSources.length > 0) {
        return;
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
    if (platform != null) {
        SdkModificator sdkModificator = sdk.getSdkModificator();
        IAndroidTarget target = platform.getTarget();
        AndroidSdks.getInstance().findAndSetPlatformSources(target, sdkModificator);
        sdkModificator.commitChanges();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidSdkUtils.createNewAndroidPlatform(org.jetbrains.android.sdk.AndroidSdkUtils.createNewAndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Aggregations

IAndroidTarget (com.android.sdklib.IAndroidTarget)105 Nullable (org.jetbrains.annotations.Nullable)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Module (com.intellij.openapi.module.Module)17 NotNull (org.jetbrains.annotations.NotNull)16 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)15 Sdk (com.intellij.openapi.projectRoots.Sdk)14 File (java.io.File)13 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)13 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)13 AndroidVersion (com.android.sdklib.AndroidVersion)11 Device (com.android.sdklib.devices.Device)11 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)9 State (com.android.sdklib.devices.State)8 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)8 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)8 Configuration (com.android.tools.idea.configurations.Configuration)7 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)7 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)7 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)6