Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx

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)
like image 613
KevinMo Avatar asked Oct 18 '18 21:10

KevinMo


4 Answers

I solve my problem by changing all occurrences of

androidx.constraintlayout.ConstraintLayout

to

androidx.constraintlayout.widget.ConstraintLayout

like image 131
KevinMo Avatar answered Oct 17 '22 08:10

KevinMo


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().

like image 33
Martin Zeitler Avatar answered Oct 17 '22 09:10

Martin Zeitler


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

like image 10
Mirwise Khan Avatar answered Oct 17 '22 09:10

Mirwise Khan


build.gradle => check dependencies version

implementation 'androidx.constraintlayout:constraintlayout:1.1.1'


to change

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

solved the problem

like image 6
Sakthi Vel Avatar answered Oct 17 '22 09:10

Sakthi Vel