ConstraintLayout does not render correctly outside blueprint mode

Zoe picture Zoe · Sep 24, 2016 · Viewed 10.5k times · Source

I started using Android Studio 2.2 and ConstraintLayout today, but I'm having some issues with the rendering. When using Blueprint Mode everything appears fine. When using Design Mode, the objects are stuck at the top left corner all mashed together.

Android Studio warning: onMeasure error

java.lang.NoSuchMethodError: android.support.constraint.solver.widgets.ConstraintWidget.immediateConnect(Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;Landroid/support/constraint/solver/widgets/ConstraintWidget;Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;II)V
    at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:517)
    at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:433)
    at android.support.constraint.ConstraintLayout.onMeasure_Original(ConstraintLayout.java:728)
    at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java)
    at android.view.View.measure(View.java:19731)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:19731)
    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
    at android.view.View.measure(View.java:19731)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:545)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:342)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$72(RenderTask.java:659)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

The dependency:

compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'

Is this an unsolvable error in Android Studio or is there something that is solvable? SDK is updated.

EDIT

XML file:

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:src="@drawable/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView6"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="16dp" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView33"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/imageView6"
        android:layout_marginLeft="16dp" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView34"
        app:layout_constraintRight_toRightOf="@+id/textView33"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/textView33" />
</android.support.constraint.ConstraintLayout>

Answer

amorenew picture amorenew · Sep 24, 2016

as mentioned here Constraint Layout Alpha8 release notes

Note: due to API change, you might have to restart Android Studio 2.2 after upgrading to alpha 8 for layout preview to work.

so From the menu bar, select file and choose invalidate caches / restart