Search in sources :

Example 1 with UnsupportedJavaRuntimeException

use of com.android.tools.idea.layoutlib.UnsupportedJavaRuntimeException in project android by JetBrains.

the class RenderService method createTask.

/**
   * Creates a new {@link RenderService} associated with the given editor.
   *
   * @return a {@link RenderService} which can perform rendering services
   */
@Nullable
public RenderTask createTask(@Nullable final PsiFile psiFile, @NotNull final Configuration configuration, @NotNull final RenderLogger logger, @Nullable final EditorDesignSurface surface) {
    Module module = myFacet.getModule();
    final Project project = module.getProject();
    AndroidPlatform platform = getPlatform(module, logger);
    if (platform == null) {
        return null;
    }
    IAndroidTarget target = configuration.getTarget();
    if (target == null) {
        logger.addMessage(RenderProblem.createPlain(ERROR, "No render target was chosen"));
        return null;
    }
    warnIfObsoleteLayoutLib(module, logger, surface, target);
    LayoutLibrary layoutLib;
    try {
        layoutLib = platform.getSdkData().getTargetData(target).getLayoutLibrary(project);
        if (layoutLib == null) {
            String message = AndroidBundle.message("android.layout.preview.cannot.load.library.error");
            logger.addMessage(RenderProblem.createPlain(ERROR, message));
            return null;
        }
    } catch (UnsupportedJavaRuntimeException e) {
        RenderProblem.Html javaVersionProblem = RenderProblem.create(ERROR);
        javaVersionProblem.getHtmlBuilder().add(e.getPresentableMessage()).newline().addLink("Install a supported JDK", JDK_INSTALL_URL);
        logger.addMessage(javaVersionProblem);
        return null;
    } catch (RenderingException e) {
        String message = e.getPresentableMessage();
        message = message != null ? message : AndroidBundle.message("android.layout.preview.default.error.message");
        logger.addMessage(RenderProblem.createPlain(ERROR, message, module.getProject(), logger.getLinkManager(), e));
        return null;
    } catch (IOException e) {
        final String message = e.getMessage();
        logger.error(null, "I/O error: " + (message != null ? ": " + message : ""), e);
        return null;
    }
    if (psiFile != null && TAG_PREFERENCE_SCREEN.equals(AndroidPsiUtils.getRootTagName(psiFile)) && !layoutLib.supports(Features.PREFERENCES_RENDERING)) {
        // This means that user is using an outdated version of layoutlib. A warning to update has already been
        // presented in warnIfObsoleteLayoutLib(). Just log a plain message asking users to update.
        logger.addMessage(RenderProblem.createPlain(ERROR, "This version of the rendering library does not support rendering Preferences. " + "Update it using the SDK Manager"));
        return null;
    }
    Device device = configuration.getDevice();
    if (device == null) {
        logger.addMessage(RenderProblem.createPlain(ERROR, "No device selected"));
        return null;
    }
    try {
        RenderTask task = new RenderTask(this, configuration, logger, layoutLib, device, myCredential, CrashReporter.getInstance());
        if (psiFile != null) {
            task.setPsiFile(psiFile);
        }
        task.setDesignSurface(surface);
        return task;
    } catch (IncorrectOperationException | AssertionError e) {
        // We can get this exception if the module/project is closed while we are updating the model. Ignore it.
        assert myFacet.isDisposed();
    }
    return null;
}
Also used : LayoutLibrary(com.android.ide.common.rendering.LayoutLibrary) Device(com.android.sdklib.devices.Device) UnsupportedJavaRuntimeException(com.android.tools.idea.layoutlib.UnsupportedJavaRuntimeException) RenderingException(com.android.tools.idea.layoutlib.RenderingException) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 Device (com.android.sdklib.devices.Device)1 RenderingException (com.android.tools.idea.layoutlib.RenderingException)1 UnsupportedJavaRuntimeException (com.android.tools.idea.layoutlib.UnsupportedJavaRuntimeException)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 IOException (java.io.IOException)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1 Nullable (org.jetbrains.annotations.Nullable)1