90

I just made a migration to androidx through Android Studio menu option Refactor -> Refactor to AndroidX

I'm getting the following error:

android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout

Any idea?

Stacktrace:

2018-10-19 00:25:58.128 28131-28131/com.midounoo.midounoo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.midounoo.midounoo, PID: 28131
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.midounoo.midounoo/com.midounoo.midounoo.Base.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:203)
        at android.app.ActivityThread.main(ActivityThread.java:6255)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
     Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
     Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.ConstraintLayout
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.midounoo.midounoo-2/base.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.midounoo.midounoo-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.midounoo.midounoo-2/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:609)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.midounoo.midounoo.Base.MainActivity.onCreate(MainActivity.java:43)
        at android.app.Activity.performCreate(Activity.java:6666)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:203)
        at android.app.ActivityThread.main(ActivityThread.java:6255)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
shizhen
  • 12,251
  • 9
  • 52
  • 88
KevinMo
  • 2,740
  • 2
  • 8
  • 14

21 Answers21

183

I solve my problem by changing all occurrences of

androidx.constraintlayout.ConstraintLayout

to

androidx.constraintlayout.widget.ConstraintLayout

Abhinav Saxena
  • 1,990
  • 2
  • 24
  • 55
KevinMo
  • 2,740
  • 2
  • 8
  • 14
  • 12
    Yep, error in Android studio transformations, must change all occurence in xml layout with *androidx.constraintlayout.widget.ConstraintLayout* ... thanks – issamux Nov 21 '18 at 22:56
  • 2
    I have created a new project with androidx support library and I already have androidx.constraintlayout.widget.ConstraintLayout in my main activity but still getting the same error. – Kanchan Mar 04 '19 at 10:34
  • 3
    @Kanchan If you are working in a multi-module project, check if you need to update ConstraintLayout path in any. – Vasudev Mar 05 '19 at 12:39
50

Add androidx.constraintlayout.widget.ConstraintLayout to the dependencies:

dependencies  {
    // https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout
    implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}

It's available on mavenCentral().

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • The second `constraintlayout` does not start by uppercase `C` however. Correct one: `'androidx.constraintlayout:constraintlayout:1.1.3'` – ʍѳђઽ૯ท Oct 19 '18 at 14:35
  • You saved me from a minor headache – vanlooverenkoen Feb 11 '19 at 13:39
  • I had to prioritize mavenCentral, very peculiar that my ide didn't already handle this for me. – i am E Feb 17 '19 at 23:41
  • 2
    Why does this happen on Android Studio? I changed it from 1.1.2 to 1.1.3. Thank you. – BollMose Feb 25 '19 at 09:28
  • 1
    @BollMose - I don't know why, but 1.1.2 just chokes to death. Probably some compatibility program that the nice people Google missed. They tend to do that a lot; welcome to Android programming! – SMBiggs Mar 14 '19 at 07:17
  • 2
    For me, this is should be the only acceptable answer. There's a bug consist of 1.1.2, the 1.1.3, fix this issue. – mochadwi May 20 '19 at 09:01
  • yep seems to be problem w/ 1.1.2. update to 1.1.3 fixed this for me too. thanks! – Mon Nov 19 '19 at 14:03
10

I had the same problem, I resolved it as follows:

In your dependecies if you have added

implementation 'androidx.constraintlayout:constraintlayout:1.x.x' that is correct

but in your xml layout file you have to use the widget as

androidx.constraintlayout.widget.ConstraintLayout

Mirwise Khan
  • 1,317
  • 17
  • 25
7

build.gradle => check dependencies version

implementation 'androidx.constraintlayout:constraintlayout:1.1.1'


to change

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

solved the problem

Dr Mido
  • 2,414
  • 4
  • 32
  • 72
Sakthi Vel
  • 106
  • 1
  • 5
6

I has same issue after:

  • migration support library to androidx;
  • increment targetSdkVesrsion to 29;

I also use:

implementation "uk.co.chrisjenx:calligraphy:2.3.0"

I tried all posts from this question, but none success.

I fix it by adding one string .disableCustomViewInflation() to Calligraphy init:

@Override
public void onCreate() {

    super.onCreate();
    // ...
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/Sans-Regular.ttf")
            .setFontAttrId(R.attr.fontPath)
            .disableCustomViewInflation() // <----- this fix
            .build());
    // ...
}

I hope next release of Calligraphy (Christopher Jenkins thanks for your great job) will fix it inside too.

Tapa Save
  • 4,769
  • 5
  • 32
  • 54
5

If after adding mavenCentral() as a repository in your Gradle file and changing androidx.constraintlayout.ConstraintLayout to androidx.constraintlayout.widget.ConstraintLayout didn't solve your problem then try doing Invalidate cache and restart from the file menu. It worked for me.

Neeraj Sewani
  • 3,952
  • 6
  • 38
  • 55
5

make sure your project migrate to androidx completely , In my case I found :

<android.support.constraint.ConstraintLayout

instead of

  <androidx.constraintlayout.widget.ConstraintLayout

So change it and my problem fixed!

Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
4

After clicking on Refactor -> Migrate to AndroidX , Make sure your all dependencies in the build.gradle(Module:app) is marked to the newest version.

If its not, dependency will appear in yellow highlighted color and you can change it by hovering the mouse over it.

Secondly, Change the ConstraintLayout tag in all XML layout files to

androidx.constraintlayout.widget.ConstraintLayout

For more safer option, clean your project and sync it again after the above steps.

Akshay Chopra
  • 1,035
  • 14
  • 10
2

Make Sure you have added the dependency for constraint layout

 dependencies  {
    implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}

and have made the changes to

<androidx.constraintlayout.widget.ConstraintLayout instead of

<android.support.constraint.ConstraintLayout
Ravi
  • 2,277
  • 3
  • 22
  • 37
1

I copied and pasted an existing ConstraintLayout tag from the xml, which was causing the issue for me. Simply deleting, and re-adding the ConstraintLayout tags in AndroidStudio from scratch fixed the issue for me.

Abhas Arya
  • 470
  • 1
  • 5
  • 19
1

Make sure to change to

<androidx.constraintlayout.widget.ConstraintLayout

instead of

<android.support.constraint.ConstraintLayout

and

<androidx.constraintlayout.widget.Barrier

instead of

<android.support.constraint.Barrier
kumar
  • 1,814
  • 1
  • 24
  • 35
1

I had this issue with Android Studio 4.0. I used android studio 4.0 for a couple of days without problems. Seemingly out of nowhere the designer view stopped working. I could only fix this by uninstalling android studio and installing the newest android studio version.

TruckerCat
  • 1,437
  • 2
  • 16
  • 39
1

Since my implementation was already androidx.constraintlayout.ConstraintLayout, just using a Clean Project solved my problem.

Leonardo Sibela
  • 1,613
  • 1
  • 18
  • 39
0

yepp. mavenCentral() and correct dependencies solve my same problems

Ya Si
  • 819
  • 7
  • 12
0

I had a similar error.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2757)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:163)
        at android.app.ActivityThread.main(ActivityThread.java:6393)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
    Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:652)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.myapp.MainActivity.onCreate(MainActivity.java:23)
        at android.app.Activity.performCreate(Activity.java:6858)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2710)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2818)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:163)
        at android.app.ActivityThread.main(ActivityThread.java:6393)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
    Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/constraintlayout/widget/R$styleable;
        at androidx.constraintlayout.widget.ConstraintLayout.init(ConstraintLayout.java:590)
        at androidx.constraintlayout.widget.ConstraintLayout.<init>(ConstraintLayout.java:567)
        ... 23 more
    Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.constraintlayout.widget.R$styleable" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        ... 25

Following the recomendations:

add androidx.constraintlayout.ConstraintLayout to the dependencies:

dependencies  {
    implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}

And the repository mavenCentral().

Works for me. I could compile the APK.

0

I updated the dependency, yet it did not resolve the error. Then I did a clean project and build and it is working now.

Bishoy Kamel
  • 2,327
  • 2
  • 17
  • 29
0
  1. Find all default before to click Refactor -> Refactor to AndroidX
  2. Open this https://developer.android.com/jetpack/androidx/migrate/class-mappings and find "android.support.v4.widget.DrawerLayout". In same line AndroidX class name is "androidx.drawerlayout.widget.DrawerLayout" copy it.

enter image description here

  1. Replace all "android.support.v4.widget.DrawerLayout" to "androidx.drawerlayout.widget.DrawerLayout" in your project"s code, layout and menu. After all replace it will work.

I mean find mapping and use it in whole project.

ethemsulan
  • 2,241
  • 27
  • 19
0

change your constraint layout dependancy to implementation 'androidx.constraintlayout:constraintlayout:2.0.2'

0

None of the solution worked for me, looking closely at the exception stack trace:

 Caused by: android.content.res.Resources$NotFoundException: Resource "com.XXX.XXX:drawable/walpaper" (7f0800aa)  is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0800aa a=-1 r=0x7f0800aa}
    at android.content.res.Resources.loadDrawableForCookie(Resources.java:2690)
    at android.content.res.Resources.loadDrawable(Resources.java:2614)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
    at android.view.View.<init>(View.java:3791)
    at android.view.ViewGroup.<init>(ViewGroup.java:524)
    at android.view.ViewGroup.<init>(ViewGroup.java:520)
    at android.view.ViewGroup.<init>(ViewGroup.java:516)

drawable background image loading was causing some issue on my old test device (newer devices load it just fine). Just removed the following line from my layouts it is working fine now, need to figure out how to set the background now..

 android:background="@drawable/walpaper"
Bakavani
  • 101
  • 5
0

I had the issue with ImageFilterView converting jpg images to png solved the issue for me.

RHS.Dev
  • 412
  • 6
  • 18
0

In my case, the issue was resolved by correctly setting the colors in the application. We carefully monitor the API version in each color used and simply change the color in case of a version higher than the minimum allowed. In the attributes, select Pick a Resource of the color that you want to check and pay attention here: check API version