Tlaloc-ES
Tlaloc-ES

Reputation: 5302

Didn't find class "androidx.constraintlayout.ConstraintLayout"

I am developing a library for Android, and this library has some activities with its layouts.

In the layout, I have the next code

...
  <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.floatingactionbutton.FloatingActionButton
...

I am using Androidx.

An I get the following error:

Error inflating class android.support.constraint.ConstraintLayout

The first attempt to solve this was to changeandroid.support.constraint.ConstraintLayout to androidx.constraintlayout.widget.ConstraintLayout

But when I do this I get the following error:

androidx.constraintlayout.widget.ConstraintLayout cannot be cast to androidx.constraintlayout.widget.Group

So I try to change to androidx.constraintlayout.widget.Group

I get the following error:

androidx.constraintlayout.widget.Group cannot be cast to android.view.ViewGroup

I did a refactor again to androidx and then I get the following error:

Didn't find class "androidx.constraintlayout.ConstraintLayout"

Any idea?

Thanks

Upvotes: 2

Views: 6061

Answers (1)

AskNilesh
AskNilesh

Reputation: 69754

Follow this steps

First add below dependencies in your Build.Gradle file

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Use this ConstraintLayout like this

<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="wrap_content">

</androidx.constraintlayout.widget.ConstraintLayout>

Make sure you have correct imports of ConstraintLayout for in your activity if you have used

import androidx.constraintlayout.widget.ConstraintLayout

Upvotes: 5

Related Questions