Saturday, August 03, 2019

Androidx Migration solved android.view.InflateException: Error inflating class androidx.constraintlayout.widget.constraintLayout

Encountered this error when starting a new project in android,

FATAL EXCEPTION: main
    Process: com.kameshapps.panchangamdaily, PID: 11397
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.k......../com............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:2646)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)


After browsing a few posts, the following steps helped resolve. Hope it helps someone

1. Add mavencentral() to repositories in build.gradle(project), like so

repositories {
    google()
    jcenter()
    mavenCentral()
}

2 Following changes in the layout.xml (note the capitalization of ConstraintLayout)..

From, <androidx.constraintlayout.constraintLayout> 

to, <androidx.constraintlayout.widget.ConstraintLayout

3. Add the following 

implementation "androidx.constraintlayout:constraintlayout:1.1.3" build.gradle ( app)


Hope it helps someone