Search in sources :

Example 56 with AndroidVersion

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

the class ImportModule method getLatestVersion.

@Nullable
public GradleCoordinate getLatestVersion(String artifact) {
    int compileVersion = GradleImport.CURRENT_COMPILE_VERSION;
    AndroidVersion version = getCompileSdkVersion();
    if (version != AndroidVersion.DEFAULT) {
        compileVersion = version.getFeatureLevel();
    }
    // from version 18 (earliest version where we have all the libs in the m2 repository)
    if (compileVersion < 18) {
        compileVersion = 18;
    }
    String compileVersionString = Integer.toString(compileVersion);
    if (myImporter.getSdkLocation() != null) {
        @SuppressWarnings("UnnecessaryLocalVariable") String filter = compileVersionString;
        GradleCoordinate max = SdkMavenRepository.ANDROID.getHighestInstalledVersion(myImporter.getSdkLocation(), SUPPORT_GROUP_ID, artifact, filter, true);
        if (max != null) {
            return max;
        }
    }
    String coordinate = SUPPORT_GROUP_ID + ':' + artifact + ':' + compileVersionString + ".+";
    return GradleCoordinate.parseCoordinateString(coordinate);
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) AndroidVersion(com.android.sdklib.AndroidVersion) Nullable(com.android.annotations.Nullable)

Example 57 with AndroidVersion

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

the class JdkModuleSetupStep method setUpInAndroidStudio.

@VisibleForTesting
void setUpInAndroidStudio(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    AndroidProject androidProject = androidModel.getAndroidProject();
    String compileTarget = androidProject.getCompileTarget();
    AndroidVersion version = AndroidTargetHash.getPlatformVersion(compileTarget);
    if (version != null && version.getFeatureLevel() >= 21) {
        Sdk jdk = myIdeSdks.getJdk();
        if (jdk != null && !myJdks.isApplicableJdk(jdk, JDK_1_7)) {
            Project project = module.getProject();
            SyncMessage msg;
            String text = "compileSdkVersion " + compileTarget + " requires compiling with JDK 7 or newer.";
            VirtualFile buildFile = getGradleBuildFile(module);
            if (buildFile != null) {
                msg = reportWrongJdkError(project, text, buildFile);
            } else {
                msg = reportWrongJdkError(project, text);
            }
            SyncMessages.getInstance(project).report(msg);
            GradleSyncState.getInstance(project).getSummary().setWrongJdkFound(true);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AndroidProject(com.android.builder.model.AndroidProject) AndroidProject(com.android.builder.model.AndroidProject) Sdk(com.intellij.openapi.projectRoots.Sdk) AndroidVersion(com.android.sdklib.AndroidVersion) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 58 with AndroidVersion

use of com.android.sdklib.AndroidVersion 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 59 with AndroidVersion

use of com.android.sdklib.AndroidVersion 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 60 with AndroidVersion

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

the class AndroidDrawableDomUtil method getPossibleRoots.

public static List<String> getPossibleRoots(AndroidFacet facet) {
    AndroidVersion sdkVersion = AndroidModuleInfo.get(facet).getBuildSdkVersion();
    List<String> result = Lists.newArrayListWithExpectedSize(DRAWABLE_ROOTS_V1.length + DRAWABLE_ROOTS_V21.length);
    Collections.addAll(result, DRAWABLE_ROOTS_V1);
    if (sdkVersion == null || sdkVersion.getFeatureLevel() >= 21 || ApplicationManager.getApplication().isUnitTestMode()) {
        Collections.addAll(result, DRAWABLE_ROOTS_V21);
    }
    return result;
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)89 Test (org.junit.Test)21 NotNull (org.jetbrains.annotations.NotNull)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)12 IDevice (com.android.ddmlib.IDevice)11 Nullable (org.jetbrains.annotations.Nullable)9 MockPlatformTarget (com.android.sdklib.internal.androidTarget.MockPlatformTarget)8 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)8 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)6 Project (com.intellij.openapi.project.Project)5 Abi (com.android.sdklib.devices.Abi)4 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 OutputFile (com.android.build.OutputFile)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3