error inflating ConstraintLayout in android studio

前端 未结 8 2162
猫巷女王i
猫巷女王i 2020-12-06 16:25

I\'m having problems with Android Studio. I recently upgraded my SDK Manager to include;

compile \'com.android.support.constraint:constraint-layout:1.0.0-bet         


        
相关标签:
8条回答
  • 2020-12-06 16:48

    I had the same issues. For me, the reason is my project "Automatically convert third-party libraries to use AndroidXhas". What to do? simply following two steps:

    1st step: Please check your gradle.properties, if you see the following lines, you might have the exact same issues as mine. You can firstly delete them.

    android.useAndroidX=true
    android.enableJetifier=true
    

    2nd step: in main activity, I changed

    import androidx.core.app.ActivityCompat;
    import androidx.core.content.ContextCompat;
    

    into

    import android.support.v4.app.ActivityCompat;
    import android.support.v4.content.ContextCompat;
    

    Everything works all of sudden!

    0 讨论(0)
  • 2020-12-06 16:48

    I had the same issue, the app run correctly in other phones but got this exception with a ZTE device. I fixed it by disabling Instant Run in Android Studio.

    0 讨论(0)
  • 2020-12-06 16:49

    I don't know if this was solution 2 and half years ago, but today i had similar error. Found the answer right here: Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx

    Basically only xml tags of constraint layout should be renamed to these ->

    androidx.constraintlayout.widget.ConstraintLayout

    0 讨论(0)
  • 2020-12-06 16:49

    please use ConstraintLayout dependency version '2.0.0-beta5', it has solved my issue.

    0 讨论(0)
  • 2020-12-06 16:58

    If You using androidx, you must use

    androidx.constraintlayout.widget.ConstraintLayout
    
    0 讨论(0)
  • 2020-12-06 17:01

    You should add as below

    <android.support.constraint.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:id="@+id/PLAY_PARENT"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@drawable/greenfelt2"
     android:padding="0dp">
    

    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    For the latest release check here

    check out this project for more on ConstraintLayout Usage

    Update

    For those who are switching from android support to androidx, remember to change android.support.constraint.ConstraintLayout to androidx.constraintlayout.widget.ConstraintLayout

    0 讨论(0)
提交回复
热议问题