Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConstraintLayout not working in GUI editor Android Studio 3.0 - Canary 4

I'm running into problems when editing layouts that contain a ConstraintLayout element in Android Studio 3.0.

My dependencies are as follows:

        project.ext.support_library_version = '26.0.0-beta2'

        dependencies {
            compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
            compile "com.android.support:palette-v7:${project.ext.support_library_version}"
            compile "com.android.support:support-v13:${project.ext.support_library_version}"
            compile "com.android.support:customtabs:${project.ext.support_library_version}"
            compile "com.android.support:cardview-v7:${project.ext.support_library_version}"
         ...
}

The error showing in the UI editor is:

The following classes could not be instantiated:
- android.support.constraint.ConstraintLayout (Open Class, Show Exception, Clear Cache)
 Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.  If this is an unexpected error you can also try to build the project, then manually refresh the layout.

The stacktrace showing is the following:

java.lang.AssertionError: Entries for a declare-styleable should be after the array declaration.
    at com.android.tools.idea.res.AppResourceRepository.getDeclaredArrayValues(AppResourceRepository.java:634)
    at com.android.tools.idea.res.ResourceClassGenerator.generateStyleable(ResourceClassGenerator.java:249)
    at com.android.tools.idea.res.ResourceClassGenerator.generate(ResourceClassGenerator.java:120)
    at com.android.tools.idea.res.ResourceClassRegistry.findClassDefinition(ResourceClassRegistry.java:102)
    at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:101)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:215)
    at android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:494)
    at android.support.constraint.ConstraintLayout.<init>(ConstraintLayout.java:466)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:264)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:222)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:206)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:337)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:348)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:248)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:334)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:382)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:591)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:739)
    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)

Cleaning/building/invalidate caches etc. Does not help. Note that the app is functioning perfectly, it's only the UI Editor that is not working anymore. Who faces the same issue, or has a solution for this?

like image 485
Peter Avatar asked Jun 16 '17 13:06

Peter


People also ask

What is Androidx ConstraintLayout widget ConstraintLayout?

A Barrier references multiple widgets as input, and creates a virtual guideline based on the most extreme widget on the specified side. ConstraintLayout. A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way.

How do I change ConstraintLayout?

Open the layout file (activity_main. xml) in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click LinearLayout and then choose Convert layout to ConstraintLayout from the context menu.

Can we use RelativeLayout inside ConstraintLayout?

Constraints define the relation between two different view elements, and chains can be used dictate the spacing between them. In addition, guidelines can be used to create percentage-based layouts. Most of what can be achieved in LinearLayout and RelativeLayout can be done in ConstraintLayout.

Can we use linear layout in ConstraintLayout?

ConstraintLayout has dual power of both Relative Layout as well as Linear layout: Set relative positions of views ( like Relative layout ) and also set weights for dynamic UI (which was only possible in Linear Layout).

What is constraintlayout in Android Studio?

1. Before you begin In this codelab, you'll learn how to use the Android Studio Layout Editor with ConstraintLayout—a new, flexible, and efficient layout available in the Android Support repository. The Layout Editor uses ConstraintLayout to determine the position of a UI element.

How do I use constraintlayout in the layout editor?

All the power of ConstraintLayout is available directly from the Layout Editor's visual tools, because the layout API and the Layout Editor were specially built for each other. So you can build your layout with ConstraintLayout entirely by drag-and-dropping instead of editing the XML.

What's new in constraintlayout 2?

ConstraintLayout 2.0 adds new features for layouts (virtual layouts, etc.) and a new class for simplifying animation of views, MotionLayout. androidx.constraintlayout:constraintlayout:2.0.4 is released. This releases fixes a potential NPE that may happen when removing a child view at runtime. It is recommended to update to this version.

What can you do with the layout editor in Android Studio?

By the end of this codelab, you'll have enough experience with the Layout Editor in Android Studio to be able to build a complex layout such as the one shown below. Learn to automatically constrain UI elements to the layout. How to place and resize elements in the layout.


1 Answers

There's a problem with support library 26.0.0-beta2 -- you need to switch back to beta 1 in order for things to work in Android Studio.

like image 179
Nicolas Roard Avatar answered Oct 08 '22 08:10

Nicolas Roard