Search in sources :

Example 76 with IAndroidTarget

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

the class AndroidLintOldTargetApiInspection method getHighestApi.

private static int getHighestApi(PsiElement element) {
    int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
    AndroidFacet instance = AndroidFacet.getInstance(element);
    if (instance != null) {
        AndroidSdkData sdkData = instance.getSdkData();
        if (sdkData != null) {
            for (IAndroidTarget target : sdkData.getTargets()) {
                if (target.isPlatform()) {
                    AndroidVersion version = target.getVersion();
                    if (version.getApiLevel() > max && !version.isPreview()) {
                        max = version.getApiLevel();
                    }
                }
            }
        }
    }
    return max;
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 77 with IAndroidTarget

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

the class IdeSdks method createAndroidSdkPerAndroidTarget.

/**
   * Creates a set of IntelliJ SDKs (one for each build target) corresponding to the Android SDK in the given directory, if SDKs with the
   * default naming convention and each individual build target do not already exist. If IntelliJ SDKs do exist, they are not updated.
   */
@NotNull
private List<Sdk> createAndroidSdkPerAndroidTarget(@NotNull File androidSdkPath, @Nullable Sdk javaSdk) {
    AndroidSdkData sdkData = getSdkData(androidSdkPath);
    if (sdkData == null) {
        return Collections.emptyList();
    }
    IAndroidTarget[] targets = sdkData.getTargets(false);
    if (targets.length == 0) {
        return Collections.emptyList();
    }
    List<Sdk> sdks = new ArrayList<>();
    Sdk ideJdk = javaSdk != null ? javaSdk : getJdk();
    if (ideJdk != null) {
        for (IAndroidTarget target : targets) {
            if (target.isPlatform() && !doesIdeAndroidSdkExist(target)) {
                String name = myAndroidSdks.chooseNameForNewLibrary(target);
                Sdk sdk = myAndroidSdks.create(target, sdkData.getLocation(), name, ideJdk, true);
                if (sdk != null) {
                    sdks.add(sdk);
                }
            }
        }
    }
    return sdks;
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) ArrayList(java.util.ArrayList) IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with IAndroidTarget

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

the class IdeSdks method doesIdeAndroidSdkExist.

/**
   * @return {@code true} if an IntelliJ SDK with the default naming convention already exists for the given Android build target.
   */
private boolean doesIdeAndroidSdkExist(@NotNull IAndroidTarget target) {
    for (Sdk sdk : getEligibleAndroidSdks()) {
        IAndroidTarget platformTarget = getTarget(sdk);
        AndroidVersion version = target.getVersion();
        AndroidVersion existingVersion = platformTarget.getVersion();
        if (existingVersion.equals(version)) {
            return true;
        }
    }
    return false;
}
Also used : SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 79 with IAndroidTarget

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

the class AndroidSdks method tryToCreate.

@Nullable
public Sdk tryToCreate(@NotNull File sdkPath, @NotNull String targetHashString) {
    AndroidSdkData sdkData = getSdkData(sdkPath);
    if (sdkData != null) {
        sdkData.getSdkHandler().getSdkManager(new StudioLoggerProgressIndicator(AndroidSdks.class)).markInvalid();
        IAndroidTarget target = sdkData.findTargetByHashString(targetHashString);
        if (target != null) {
            return create(target, sdkData.getLocation(), true);
        }
    }
    return null;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 80 with IAndroidTarget

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

the class AndroidSdks method chooseNameForNewLibrary.

@NotNull
public String chooseNameForNewLibrary(@NotNull IAndroidTarget target) {
    if (target.isPlatform()) {
        return SDK_NAME_PREFIX + target.getVersion().toString() + " Platform";
    }
    IAndroidTarget parentTarget = target.getParent();
    String name = SDK_NAME_PREFIX;
    if (parentTarget != null) {
        name = name + parentTarget.getVersionName() + ' ';
    }
    return name + target.getName();
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) NotNull(org.jetbrains.annotations.NotNull)

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