[Solved] After migrating to AndroidX, Error inflating class

After using Android Studio to migrate my project to AndroidX (and manually fixing a lot of import errors), I’m getting no compile errors but when the app starts I get a crash with:

Error inflating class

The offending line in the layout file is:

My dependencies in build.gradle are:

dependencies {
    def lifecycle_version = '2.1.0-alpha02'
    // used below--will be different for androidx (migrated 2019-02-04)
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'

    implementation ''
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'com.squareup.okio:okio:1.15.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
    implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.0'
    // Relay class
    implementation 'com.jakewharton.rx2:replaying-share:2.1.0'
    // ReplayingShare
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
    // RxBinding
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"  // see def above
    // includes ViewModel and LiveData
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    // for tuples like Triple
    implementation 'com.androidplot:androidplot-core:1.5.6'
    // AndroidPlot

I’m guessing that I’m missing something but I can’t find what it is.

Solution #1:

You need to use

Version 1.0.0 is already out So you can use implementation 'androidx.appcompat:appcompat:1.0.0'

Add dependency implementation ''

See Material Component integration for latest release version.
And use



For other artifact and Class Mapping see the AndroidX migration Doc.

Respondent: ADM

Solution #2:

Please go through this old to new class mappings

eg;- Use instead of

For AppBarLayout

enter image description here

For Toolbar

enter image description here

Respondent: Basi

Solution #3:

Androidx inflating class <> will not work
it’s not exist so replace it with <>
it will work fine
and don’t forgot to add

implementation ''

to your dependencies

Respondent: eng mohamed emam

Solution #4:

According to the AndroidX migration docs, the androidx replacement for AppBarLayout is Try replacing your AppBarLayout tag with this instead.

As for why compiling/building works, I assume it’s something to do with Jetifier, but I’m not certain.

Respondent: Ben P.

Solution #5:

if you are using Kotlin DSL you have to add this to build.gradle.kts


and in your layout use <>

Respondent: foroogh Varmazyar

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy