Search in sources :

Example 41 with AndroidPlatform

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

the class AndroidRunConfigurationBase method canInstantRun.

@NotNull
private InstantRunGradleSupport canInstantRun(@NotNull Module module, @NotNull List<AndroidDevice> targetDevices) {
    if (targetDevices.size() != 1) {
        return CANNOT_BUILD_FOR_MULTIPLE_DEVICES;
    }
    AndroidDevice device = targetDevices.get(0);
    AndroidVersion version = device.getVersion();
    if (!InstantRunManager.isInstantRunCapableDeviceVersion(version)) {
        return API_TOO_LOW_FOR_INSTANT_RUN;
    }
    IDevice targetDevice = MakeBeforeRunTaskProvider.getLaunchedDevice(device);
    if (targetDevice != null) {
        if (MultiUserUtils.hasMultipleUsers(targetDevice, 200, TimeUnit.MILLISECONDS, false)) {
            if (// run config explicitly specifies launching as a different user
            getUserIdFromAmParameters() != MultiUserUtils.PRIMARY_USERID || !MultiUserUtils.isCurrentUserThePrimaryUser(targetDevice, 200, TimeUnit.MILLISECONDS, true)) {
                // activity manager says current user is not primary
                return CANNOT_DEPLOY_FOR_SECONDARY_USER;
            }
        }
    }
    InstantRunGradleSupport irSupportStatus = InstantRunGradleUtils.getIrSupportStatus(InstantRunGradleUtils.getAppModel(module), version);
    if (irSupportStatus != SUPPORTED) {
        return irSupportStatus;
    }
    // Gradle will instrument against the runtime android.jar (see commit 353f46cbc7363e3fca44c53a6dc0b4d17347a6ac).
    // This means that the SDK platform corresponding to the device needs to be installed, otherwise the build will fail.
    // We do this as the last check because it is actually possible to recover from this failure. In the future, maybe issues
    // that have fixes will have to be handled in a more generic way.
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        return SUPPORTED;
    }
    IAndroidTarget[] targets = platform.getSdkData().getTargets();
    for (int i = targets.length - 1; i >= 0; i--) {
        if (!targets[i].isPlatform()) {
            continue;
        }
        if (targets[i].getVersion().equals(version)) {
            return SUPPORTED;
        }
    }
    return TARGET_PLATFORM_NOT_INSTALLED;
}
Also used : IDevice(com.android.ddmlib.IDevice) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with AndroidPlatform

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

the class AndroidRootUtil method addAnnotationsJar.

private static void addAnnotationsJar(@NotNull Module module, @NotNull OrderedSet<VirtualFile> libs) {
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null || !AndroidSdks.getInstance().isAndroidSdk(sdk)) {
        return;
    }
    String sdkHomePath = sdk.getHomePath();
    if (sdkHomePath == null) {
        return;
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform != null && platform.needToAddAnnotationsJarToClasspath()) {
        String annotationsJarPath = toSystemIndependentName(sdkHomePath) + ANNOTATIONS_JAR_RELATIVE_PATH;
        VirtualFile annotationsJar = LocalFileSystem.getInstance().findFileByPath(annotationsJarPath);
        if (annotationsJar != null) {
            libs.add(annotationsJar);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 43 with AndroidPlatform

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

the class ViewLoaderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Module module = myFacet.getModule();
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    assertNotNull(platform);
    myLayoutLib = RenderService.getLayoutLibrary(module, ConfigurationManager.create(module).getHighestApiTarget());
    assertNotNull(myLayoutLib);
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module)

Example 44 with AndroidPlatform

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

the class AndroidSdksTest method testCreateSdkWithoutAddingRoots.

public void testCreateSdkWithoutAddingRoots() {
    IAndroidTarget target = findAndroidTarget();
    String name = "testSdk";
    Sdk sdk = myAndroidSdks.create(target, mySdkPath, name, myJdk, false);
    assertNotNull(sdk);
    assertEquals(name, sdk.getName());
    verifyCorrectPath(sdk);
    AndroidSdkAdditionalData androidData = getAndroidSdkAdditionalData(sdk);
    assertSame(myJdk, androidData.getJavaSdk());
    AndroidPlatform androidPlatform = androidData.getAndroidPlatform();
    assertNotNull(androidPlatform);
    assertSame(target, androidPlatform.getTarget());
    VirtualFile[] sdkRoots = sdk.getSdkModificator().getRoots(CLASSES);
    assertThat(sdkRoots).isEmpty();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetHash.getTargetHashString(com.android.sdklib.AndroidTargetHash.getTargetHashString) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 45 with AndroidPlatform

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

the class GraphicsLayoutRendererTest method testInflateAndRender.

public void testInflateAndRender() throws InitializationException, ParserConfigurationException, IOException, SAXException {
    VirtualFile layout = myFixture.copyFileToProject("themeEditor/theme_preview_layout.xml", "res/layout/theme_preview_layout.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(layout);
    DomPullParser parser = new DomPullParser(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(layout.getInputStream()).getDocumentElement());
    AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
    assertNotNull(facet);
    AndroidPlatform platform = AndroidPlatform.getInstance(myModule);
    assertNotNull(platform);
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    GraphicsLayoutRenderer renderer = GraphicsLayoutRenderer.create(facet, platform, myModule.getProject(), configuration, parser, Color.BLACK, SessionParams.RenderingMode.V_SCROLL, false);
    // The first render triggers a render (to a NOP Graphics object) so we expect sizes to have been initialized.
    Dimension initialSize = renderer.getPreferredSize();
    assertNotEquals("Expected layout dimensions after create", EMPTY_DIMENSION, initialSize);
    assertTrue(renderer.render((Graphics2D) image.getGraphics()));
    // We haven't changed the layout so, after the render, we expect the same dimensions.
    assertEquals(initialSize, renderer.getPreferredSize());
    renderer.setSize(new Dimension(50, 50));
    assertTrue(renderer.render((Graphics2D) image.getGraphics()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) DomPullParser(com.android.tools.idea.rendering.DomPullParser) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) BufferedImage(java.awt.image.BufferedImage)

Aggregations

AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)46 Module (com.intellij.openapi.module.Module)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 Nullable (org.jetbrains.annotations.Nullable)11 Project (com.intellij.openapi.project.Project)10 Sdk (com.intellij.openapi.projectRoots.Sdk)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 File (java.io.File)9 IOException (java.io.IOException)9 AndroidVersion (com.android.sdklib.AndroidVersion)8 NotNull (org.jetbrains.annotations.NotNull)6 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)5 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 RenderingException (com.android.tools.idea.layoutlib.RenderingException)3 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)3 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)3 SourceProvider (com.android.builder.model.SourceProvider)2 IDevice (com.android.ddmlib.IDevice)2