Search in sources :

Example 21 with IAndroidTarget

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

the class AndroidVersionsInfo method loadInstalledVersions.

/**
   * Load the installed android versions from the installed SDK
   */
public void loadInstalledVersions() {
    myInstalledVersions.clear();
    IAndroidTarget highestInstalledTarget = null;
    for (IAndroidTarget target : getCompilationTargets()) {
        if (target.isPlatform() && target.getVersion().getFeatureLevel() >= SdkVersionInfo.LOWEST_COMPILE_SDK_VERSION && (highestInstalledTarget == null || target.getVersion().getFeatureLevel() > highestInstalledTarget.getVersion().getFeatureLevel() && !target.getVersion().isPreview())) {
            highestInstalledTarget = target;
        }
        if (target.getVersion().isPreview() || !target.getAdditionalLibraries().isEmpty()) {
            myInstalledVersions.add(target.getVersion());
        }
    }
    myHighestInstalledApiTarget = highestInstalledTarget;
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 22 with IAndroidTarget

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

the class AndroidPropertyFilesUpdater method updateProjectPropertiesIfNecessary.

@Nullable
private static Pair<VirtualFile, List<Runnable>> updateProjectPropertiesIfNecessary(@NotNull AndroidFacet facet) {
    if (facet.isDisposed()) {
        return null;
    }
    final Module module = facet.getModule();
    final Pair<PropertiesFile, VirtualFile> pair = AndroidRootUtil.findPropertyFile(module, SdkConstants.FN_PROJECT_PROPERTIES);
    if (pair == null) {
        return null;
    }
    final PropertiesFile projectProperties = pair.getFirst();
    final VirtualFile projectPropertiesVFile = pair.getSecond();
    final Pair<Properties, VirtualFile> localProperties = AndroidRootUtil.readPropertyFile(module, SdkConstants.FN_LOCAL_PROPERTIES);
    final List<Runnable> changes = new ArrayList<Runnable>();
    final IAndroidTarget androidTarget = facet.getConfiguration().getAndroidTarget();
    final String androidTargetHashString = androidTarget != null ? androidTarget.hashString() : null;
    final VirtualFile[] dependencies = collectDependencies(module);
    final String[] dependencyPaths = toSortedPaths(dependencies);
    final List<Object> newState = Arrays.asList(androidTargetHashString, facet.getProjectType(), Arrays.asList(dependencyPaths), facet.getProperties().ENABLE_MANIFEST_MERGING, facet.getProperties().ENABLE_PRE_DEXING);
    final List<Object> state = facet.getUserData(ANDROID_PROPERTIES_STATE_KEY);
    if (state == null || !Comparing.equal(state, newState)) {
        updateTargetProperty(facet, projectProperties, changes);
        updateProjectTypeProperty(facet, projectProperties, changes);
        updateManifestMergerProperty(facet, projectProperties, changes);
        updateDependenciesInPropertyFile(projectProperties, localProperties, dependencies, changes);
        facet.putUserData(ANDROID_PROPERTIES_STATE_KEY, newState);
    }
    return changes.size() > 0 ? Pair.create(projectPropertiesVFile, changes) : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IAndroidTarget(com.android.sdklib.IAndroidTarget) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with IAndroidTarget

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

the class TargetApiConverter method getHighestKnownApi.

private static int getHighestKnownApi(@NotNull ConvertContext context) {
    Module module = context.getModule();
    if (module == null) {
        return HIGHEST_KNOWN_API;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return HIGHEST_KNOWN_API;
    }
    IAndroidTarget apiTarget = facet.getConfigurationManager().getHighestApiTarget();
    if (apiTarget == null) {
        return HIGHEST_KNOWN_API;
    }
    return Math.max(apiTarget.getVersion().getApiLevel(), HIGHEST_KNOWN_API);
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 24 with IAndroidTarget

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

the class GradleSyncTest method sdkCreationForAddons.

// https://code.google.com/p/android/issues/detail?id=185313
@Test
public void sdkCreationForAddons() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    Project project = ideFrame.getProject();
    Module appModule = ideFrame.getModule("app");
    GradleBuildFile buildFile = GradleBuildFile.get(appModule);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            runWriteCommandAction(project, () -> buildFile.setValue(BuildFileKey.COMPILE_SDK_VERSION, "Google Inc.:Google APIs:24"));
        }
    });
    ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
    Sdk sdk = ModuleRootManager.getInstance(appModule).getSdk();
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    assertThat(data).isInstanceOf(AndroidSdkAdditionalData.class);
    AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
    IAndroidTarget buildTarget = androidSdkData.getBuildTarget(sdkData);
    // By checking that there are no additional libraries in the SDK, we are verifying that an additional SDK was not created for add-ons.
    assertThat(buildTarget.getAdditionalLibraries()).hasSize(0);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) Test(org.junit.Test)

Example 25 with IAndroidTarget

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

the class Configuration method syncFolderConfig.

/**
   * Updates the folder configuration such that it reflects changes in
   * configuration state such as the device orientation, the UI mode, the
   * rendering target, etc.
   */
protected void syncFolderConfig() {
    Device device = getDevice();
    if (device == null) {
        return;
    }
    // get the device config from the device/state combos.
    State deviceState = getDeviceState();
    if (deviceState == null) {
        deviceState = device.getDefaultState();
    }
    FolderConfiguration config = getFolderConfig(getModule(), deviceState, getLocale(), getTarget());
    // replace the config with the one from the device
    myFullConfig.set(config);
    // sync the selected locale
    Locale locale = getLocale();
    myFullConfig.setLocaleQualifier(locale.qualifier);
    if (myEditedConfig.getLayoutDirectionQualifier() != null) {
        myFullConfig.setLayoutDirectionQualifier(myEditedConfig.getLayoutDirectionQualifier());
    } else if (!locale.hasLanguage()) {
        // Avoid getting the layout library if the locale doesn't have any language.
        myFullConfig.setLayoutDirectionQualifier(new LayoutDirectionQualifier(LayoutDirection.LTR));
    } else {
        LayoutLibrary layoutLib = RenderService.getLayoutLibrary(getModule(), getTarget());
        if (layoutLib != null) {
            if (layoutLib.isRtl(locale.toLocaleId())) {
                myFullConfig.setLayoutDirectionQualifier(new LayoutDirectionQualifier(LayoutDirection.RTL));
            } else {
                myFullConfig.setLayoutDirectionQualifier(new LayoutDirectionQualifier(LayoutDirection.LTR));
            }
        }
    }
    // Replace the UiMode with the selected one, if one is selected
    UiMode uiMode = getUiMode();
    myFullConfig.setUiModeQualifier(new UiModeQualifier(uiMode));
    // Replace the NightMode with the selected one, if one is selected
    NightMode nightMode = getNightMode();
    myFullConfig.setNightModeQualifier(new NightModeQualifier(nightMode));
    // replace the API level by the selection of the combo
    IAndroidTarget target = getTarget();
    if (target != null) {
        int apiLevel = target.getVersion().getFeatureLevel();
        myFullConfig.setVersionQualifier(new VersionQualifier(apiLevel));
    }
    myFolderConfigDirty = 0;
    myProjectStateVersion = myManager.getStateVersion();
}
Also used : Locale(com.android.tools.idea.rendering.Locale) LayoutLibrary(com.android.ide.common.rendering.LayoutLibrary) Device(com.android.sdklib.devices.Device) IAndroidTarget(com.android.sdklib.IAndroidTarget) State(com.android.sdklib.devices.State)

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