1

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:

  1. 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's 28.0.0-rc02 - both bug)

  2. Android studio underlines in red my implementation instruction as follows:

enter image description here

Errors opening the Layout Editor

  1. Render problem

Failed to load AppCompat ActionBar with unknown error.

  1. 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?):

enter image description here

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):

enter image description here

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 )

JarsOfJam-Scheduler
  • 2,809
  • 3
  • 31
  • 70
  • Why do you want to use those release candidates so badly? Wouldn't it be better to use the stable release? – Roddy of the Frozen Peas Sep 05 '18 at 20:53
  • @RoddyoftheFrozenPeas When I want to use `27.1.1` instead of `28.0.0-rc01` (latest version according to https://mvnrepository.com/artifact/com.android.support/design?repo=google ) and instead of `28.0.0-rc02` (latest version according to Android Studio), another problem appears (and replaces all the others): please see "*Similar StackOverflow questions - Android support library > Using `implementation 'com.android.support:appcompat-v7:27.1.1`*". – JarsOfJam-Scheduler Sep 06 '18 at 17:01
  • 1
    28.0.0-rc02 is the *release candidate*. That's what RC means. That means it's still in development and is not finished bug testing so you're going to potentially encounter issues with it that will not be in the final version of 28.0.0. It's not the latest release, it's just the latest available dev branch. – Roddy of the Frozen Peas Sep 06 '18 at 17:09
  • 1
    This might help i suppose: https://stackoverflow.com/a/52020244/4409113 Also, in your second option of your edited question, if you set `27.1.1`, you'll also need to set `compilesdkversion` in your `build.gradle` so i suggest using my answer as i already linked. – ʍѳђઽ૯ท Sep 06 '18 at 17:11
  • @RoddyoftheFrozenPeas I know. But it's noramally less bugued than alpha, and than beta. – JarsOfJam-Scheduler Sep 06 '18 at 17:11
  • 1
    Well yes. But usually there's no good reason to be using anything other than the stable release version unless you're specifically trying to take advantage of a bug fix or a new feature. Which is why I asked *why* it was so important to use the RC. – Roddy of the Frozen Peas Sep 06 '18 at 17:22
  • Because if I choose the `27.1.1` stable version, Android displays a warning, please see *Android support library > Using `implementation 'com.android.support:appcompat-v7:27.1.1`* - and it scares me. – JarsOfJam-Scheduler Sep 06 '18 at 17:23

2 Answers2

1

Latest Versions of Support libraries is still under development and may contain bugs

Until it ends you can downgrade version to 28.0.0-alpha1

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
5ec20ab0
  • 742
  • 6
  • 15
0

I had the same problem with the blueprints, my solution was to select preview and blueprint at the same time.

Also try to add the button with xml text and add some constraints:

app:layout_constraintEnd_toEndOf="parent"

should do.

rusito23
  • 995
  • 8
  • 20