27

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-beta5'

classpath is

 classpath 'com.android.tools.build:gradle:2.2.3'

Project builds fine. Intellisense and documentation works fine. But when I try to run (in debug) the app on my phone I get this error;

 Caused by: android.view.InflateException: Binary XML file line #2:
 Binary XML file line #2: Error inflating class ConstraintLayout
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                   at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                   at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:443)
                   at android.app.Activity.setContentView(Activity.java:2172)

I've synced gradle. I've restarted Android Studio. I've cleaned and rebuilt the project.

Any ideas on how to fix this? thanks!

-edit- XML looks like this;

<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">
logeshpalani31
  • 1,416
  • 12
  • 33
ausgeorge
  • 975
  • 1
  • 12
  • 23

8 Answers8

51

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

arjun
  • 3,514
  • 4
  • 27
  • 48
  • Doing so results in this error; "using version 1.0.0-beta5, this version of the constraint library is obsolete. It's just a damn intellisense error. It still builds and runs... (I didn't even try running once I saw that error...). Thanks. – ausgeorge Feb 28 '17 at 07:06
  • check out this project for more on ConstraintLayout https://github.com/Arjun-sna/android-constraintlayout-demo – arjun May 27 '17 at 17:33
  • If you have warnings, use current version: 'com.android.support.constraint:constraint-layout:1.0.2' – chntgomez Jan 25 '18 at 15:33
  • just an update. New version of the constraint layout is been out. `1.1.0` – ASN Apr 16 '18 at 02:00
  • 12
    For those who are switching from android support to androidx, remember to change `android.support.constraint.ConstraintLayout` to `androidx.constraintlayout.widget.ConstraintLayout` – undefinedman Sep 05 '19 at 14:48
7

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

zulu_papa
  • 415
  • 6
  • 12
4

If You using androidx, you must use

androidx.constraintlayout.widget.ConstraintLayout
Izzamed
  • 83
  • 4
2

It may be number of reasons

  1. dependency version issue (same like above)

  2. out-of-memory issue : In my case I was added the high resolution image for background of the constraint-layout or in the same page(.xml file) we used the high resolution image for any imageview source.

Kona Suresh
  • 1,836
  • 1
  • 15
  • 25
1

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!

Tao
  • 366
  • 1
  • 3
  • 15
1

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

BISHWAJEET
  • 61
  • 6
0

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.

manuel
  • 356
  • 2
  • 9
0

add to your app/build.gradle

dependencies {
    ...
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    ...
}
Fethi Pounct
  • 1,059
  • 5
  • 6