没找到 class "androidx.constraintlayout.ConstraintLayout"

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

我正在为 Android 开发一个库,这个库有一些布局活动。

在布局中,我有下一个代码

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

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

我正在使用 Androidx.

我收到以下错误:

Error inflating class android.support.constraint.ConstraintLayout

解决这个问题的第一个尝试是将android.support.constraint.ConstraintLayout更改为androidx.constraintlayout.widget.ConstraintLayout

但是当我这样做时,出现以下错误:

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

所以我试着改成androidx.constraintlayout.widget.Group

我收到以下错误:

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

我再次对androidx进行了重构,然后出现以下错误:

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

有什么想法吗?

谢谢

按照以下步骤操作

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