I use Android Studio 3.1.4 on Ubuntu 18.04.1. I wanted to quickly create the UI of the main (default) activity so I opened the Layout Editor. Some errors have occurred. Then I tried to add a button: it doesn't seem to be displayed in the Blueprint (and the ConstraintLayout
is weirdly displayed too).
Similar StackOverflow questions - Android support library
Similar questions have been asked in StackOverflow. The answers were to use a different version of the Android support library. Currently, I'm using this version:
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
(file: build.gradle(Module: app)
).
Indeed, even if Android Studio recommended me to use 28.0.0-rc02
, I don't see it in this list: https://mvnrepository.com/artifact/com.android.support/design?repo=google .
By the way, I encountered all of the mentionned bugs with 28.0.0-rc02
too. In résumé, I encounter all of these bugs with 28.0.0-rc01
(currently used) and 28.0.0-rc02
. I didn't try other versions for the moment.
Using implementation 'com.android.support:appcompat-v7:27.1.1
With implementation 'com.android.support:appcompat-v7:27.1.1'
, all the problems are solved. However:
It's not the last version (https://mvnrepository.com/artifact/com.android.support/design?repo=google indicates the last version is:
28.0.0-rc01
, Android Studio indicates it's28.0.0-rc02
- both bug)Android studio underlines in red my
implementation
instruction as follows:
Errors opening the Layout Editor
- Render problem
Failed to load AppCompat ActionBar with unknown error.
- The following classes could not be instantiated
- android.support.v7.widget.ActionBarContainer (Open Class, Show Exception, Clear Cache) - android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache) - android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache)
Exception Details:
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:180) at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:61) at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:118) 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:213) at android.support.v7.widget.ActionBarContainer.(ActionBarContainer.java:62) 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:209) 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:730) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:837) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at com.android.layoutlib.bridge.bars.BridgeActionBar.(BridgeActionBar.java:89) at com.android.layoutlib.bridge.bars.AppCompatActionBar.(AppCompatActionBar.java:68) at com.android.layoutlib.bridge.impl.Layout.createActionBar(Layout.java:277) at com.android.layoutlib.bridge.impl.Layout.(Layout.java:161) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:288) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384) at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:544) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:678) 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)
Blueprint problems - What is in my UI?
For the moment, nothing apart the root component (a ConstraintLayout
instance), as you can see (note that the ConstraintLayout
seems to be represented as a very little square in the Blueprint - that's a Blueprint problem, no?):
If I drag'n drop a button with the text "TEST TEST TEST" in the Blueprint, I get this (note that the button... doesn't really appear, only a weird thing is displayed inside the square):
I clicked several time on this square with a weird thing inside. I got this new exception:
Missing Constraints in ConstraintLayout
This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX). These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.
My question
I'm a little lost in the middle of all these mistakes and exceptions. What am I supposed to do? I'm reading again the documentation ( https://developer.android.com/training/basics/firstapp/building-ui) but they don't seem to have this weird behavior (I'm talking about problems displaying my button in the Blueprint and the exceptions I copied/pasted in this question).
Important edit
Which version of Android Support Library should I use? In particular: what should I do to use the latest version? (either rc-1
, or rc-2
- Android Studio recommends the rc-2
but this one doesn't appear in https://mvnrepository.com/artifact/com.android.support/design?repo=google )