Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class androidx.constraintlayout.widget.ConstraintLayout

After migrating to Androidx packages using Android Studio menu option Refactor -> Refactor to Androidx...

I'm getting the following error:

Error inflating class androidx.constraintlayout.widget.ConstraintLayout 
like image 823
Arturo Mejia Avatar asked Jun 10 '18 12:06

Arturo Mejia


People also ask

What is Androidx ConstraintLayout widget ConstraintLayout?

ConstraintLayout. A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. ConstraintLayout.LayoutParams. This class contains the different attributes specifying how a view want to be laid out inside a ConstraintLayout .

What is Androidx ConstraintLayout widget barrier?

androidx.constraintlayout.widget.Barrier. Added in 1.1. A Barrier references multiple widgets as input, and creates a virtual guideline based on the most extreme widget on the specified side. For example, a left barrier will align to the left of all the referenced views.

How do you fix missing constraints in constraint layout?

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.


2 Answers

Make sure constraint layout is updated to latest version:

implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 

And replace your xml tag names

<androidx.constraintlayout.ConstraintLayout> 

with

<androidx.constraintlayout.widget.ConstraintLayout> 

in every place where it appears using this shortcut:

Windows: CTRL + SHIFT + R

Mac: COMMAND + SHIFT + R

like image 113
hannes ach Avatar answered Sep 28 '22 16:09

hannes ach


In AndroidStudio 3.3 RC2 I got it resolved by upgrading -

implementation 'androidx.constraintlayout:constraintlayout:1.1.2' 

to

implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 

in build.gradle (Module: app)

Note: This solution is also valid for the release version 3.3 (as per below comment by FireZenk), 3.5.2 (as per below comment by user2350644)

like image 36
Devarshi Avatar answered Sep 28 '22 17:09

Devarshi