扩展类androidx.constraintlayout.widget.ConstraintLayout时出错

问题描述 投票:29回答:11

使用Android Studio菜单选项Refactor - > Refactor to Androidx迁移到Androidx软件包后...

我收到以下错误:

Error inflating class androidx.constraintlayout.widget.ConstraintLayout
android androidx
11个回答
58
投票

确保约束布局更新为最新版本:

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

并替换您的xml标记名称

<androidx.constraintlayout.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout>

在使用此快捷方式显示的每个位置:

Windows:CTRL + SHIFT + R.

Mac:COMMAND + SHIFT + R.


0
投票

在Android Studio 3.4中,我不得不降级到

<androidx.constraintlayout.widget.ConstraintLayout
        ...
        >

</androidx.constraintlayout.widget.ConstraintLayout>

让它再次运作。


0
投票

奇怪的是,它适用于我将implementation 'androidx.constraintlayout:constraintlayout:1.1.2' 库升级到的时候

androidx.appcompat:...'在Android Studio 3.3上使用约束布局版本'androidx.appcompat:appcompat:1.1.0-alpha05'


26
投票

在Android Studio 3.3 RC2中我通过升级解决了它 -

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

在build.gradle中(模块:app)

注意:此解决方案也适用于3.3版本(根据FireZenk的评论)


19
投票

只需更换

<androidx.constraintlayout.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout>

在项目的xml文件中。

你可以在mac(⇧⌘F或⇧⌘R)和windows(Ctrl + Shift + R)中使用Replace in Path快捷方式

enter image description here


7
投票

在我的情况下,我已经尝试了解决方案1仍然无法正常工作。然后我使用解决方案2和解决方案1

解决方案1在应用级别build.gradle文件中更新当前版本ConstraintLayout。

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

解决方案2使缓存无效并重新启动Android Studio(如果在应用解决方案1后仍无法正常工作)。

文件 - >使高速缓存/重新启动无效 - >无效并重新启动

我使用了它们,它对我来说很好。

注意:解决方案1很重要。


4
投票

我也面临这个问题。此问题仅适用于constraintlayout依赖项版本。使用qazxsw poi版本并希望您的问题将得到解决:

1.1.3

2
投票

由于Android Studio更新为3.3,因此会弹出此错误。我通过在应用程序级别的implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 中升级约束布局的版本来解决它:

build.gradle

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'


0
投票

Android Studio已更新3.3版。请删除以前版本的constraintLayout

我的情况用过这个

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

谢谢


0
投票

在我的情况下,我只需要将androidx依赖项更新到最新版本。

编辑在build.gradle(app)中,你必须寻找包含androidx的依赖项。 Android studio将向您显示有关这些依赖项的最新版本的信息。使用该信息只需更改依赖关系版本。


0
投票

有两种方法可以添加ConstraintLayout:

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'

然后你需要像这样使用它:

implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha3'

或使用androidx:

<android.support.constraint.ConstraintLayout
        ...>

</android.support.constraint.ConstraintLayout>

那你需要用

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'

不要混合那两个。

© www.soinside.com 2019 - 2024. All rights reserved.