Search in sources :

Example 86 with IAndroidTarget

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

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

the class EmulatorTargetChooser method chooseAvd.

@Nullable
private String chooseAvd() {
    IAndroidTarget buildTarget = myFacet.getConfiguration().getAndroidTarget();
    assert buildTarget != null;
    AvdInfo[] avds = myFacet.getValidCompatibleAvds();
    if (avds.length > 0) {
        return avds[0].getName();
    }
    final Project project = myFacet.getModule().getProject();
    AvdManager manager;
    try {
        manager = myFacet.getAvdManager(new AvdManagerLog() {

            @Override
            public void error(Throwable t, String errorFormat, Object... args) {
                super.error(t, errorFormat, args);
                if (errorFormat != null) {
                    final String msg = String.format(errorFormat, args);
                    LOG.error(msg);
                }
            }
        });
    } catch (final AndroidLocation.AndroidLocationException e) {
        LOG.info(e);
        UIUtil.invokeLaterIfNeeded(new Runnable() {

            @Override
            public void run() {
                Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
            }
        });
        return null;
    }
    final AvdManager finalManager = manager;
    assert finalManager != null;
    return UIUtil.invokeAndWaitIfNeeded(new Computable<String>() {

        @Override
        public String compute() {
            int result = Messages.showDialog(project, "To run using the emulator, you must have an AVD defined.", "Define AVD", new String[] { "Cancel", "Create AVD" }, 1, null);
            AvdInfo createdAvd = null;
            if (result == 1) {
                AvdOptionsModel avdOptionsModel = new AvdOptionsModel(null);
                ModelWizardDialog dialog = AvdWizardUtils.createAvdWizard(null, project, avdOptionsModel);
                if (dialog.showAndGet()) {
                    createdAvd = avdOptionsModel.getCreatedAvd();
                }
            }
            return createdAvd == null ? null : createdAvd.getName();
        }
    });
}
Also used : AvdManagerLog(org.jetbrains.android.sdk.AvdManagerLog) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) AvdOptionsModel(com.android.tools.idea.avdmanager.AvdOptionsModel) Project(com.intellij.openapi.project.Project) AvdManager(com.android.sdklib.internal.avd.AvdManager) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) AndroidLocation(com.android.prefs.AndroidLocation) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with IAndroidTarget

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

the class StateListPicker method doValidate.

/**
   * Returns a {@link ValidationInfo} in the case one of the state list state has a value that does not resolve to a valid resource,
   * or a value that is a private framework value. or if one of the state list component requires an API level higher than minApi.
   */
@Nullable
public /*if there is no error*/
ValidationInfo doValidate(int minApi) {
    IAndroidTarget target = myConfiguration.getRealTarget();
    assert target != null;
    final AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, myModule);
    assert androidTargetData != null;
    ResourceRepository frameworkResources = myConfiguration.getFrameworkResources();
    assert frameworkResources != null;
    for (StateComponent component : myStateComponents) {
        ValidationInfo error = component.doValidate(minApi, androidTargetData);
        if (error != null) {
            return error;
        }
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) IAndroidTarget(com.android.sdklib.IAndroidTarget) ResourceRepository(com.android.ide.common.resources.ResourceRepository) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with IAndroidTarget

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

the class RenderErrorContributorTest method getRenderOutput.

private List<RenderErrorModel.Issue> getRenderOutput(@NotNull VirtualFile file, @Nullable LogOperation logOperation) {
    assertNotNull(file);
    AndroidFacet facet = AndroidFacet.getInstance(myModule);
    PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
    assertNotNull(psiFile);
    assertNotNull(facet);
    ConfigurationManager configurationManager = facet.getConfigurationManager();
    assertNotNull(configurationManager);
    IAndroidTarget target = getTestTarget(configurationManager);
    assertNotNull(target);
    configurationManager.setTarget(target);
    Configuration configuration = configurationManager.getConfiguration(file);
    assertSame(target, configuration.getRealTarget());
    if (!LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
        // TODO: Remove this after http://b.android.com/203392 is released
        // If we are using the embedded layoutlib, use a recent theme to avoid missing styles errors.
        configuration.setTheme("android:Theme.Material");
    }
    RenderService renderService = RenderService.get(facet);
    RenderLogger logger = renderService.createLogger();
    final RenderTask task = renderService.createTask(psiFile, configuration, logger, null);
    assertNotNull(task);
    task.disableSecurityManager();
    RenderResult render = RenderTestBase.renderOnSeparateThread(task);
    assertNotNull(render);
    if (logOperation != null) {
        logOperation.addErrors(logger, render);
    }
    return RenderErrorModelFactory.createErrorModel(render, null).getIssues().stream().sorted().collect(Collectors.toList());
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) PsiFile(com.intellij.psi.PsiFile) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 90 with IAndroidTarget

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

the class RenderErrorContributorTest method getTestTarget.

@Nullable
private IAndroidTarget getTestTarget(@NotNull ConfigurationManager configurationManager) {
    String platformDir = TestUtils.getLatestAndroidPlatform();
    for (IAndroidTarget target : configurationManager.getTargets()) {
        if (!ConfigurationManager.isLayoutLibTarget(target)) {
            continue;
        }
        String path = target.getPath(IAndroidTarget.ANDROID_JAR);
        if (path == null) {
            continue;
        }
        File f = new File(path);
        if (f.getParentFile() != null && f.getParentFile().getName().equals(platformDir)) {
            return target;
        }
    }
    return null;
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

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