Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After migrating to AndroidX, Error inflating class android.support.design.widget.AppBarLayout

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 android.support.design.widget.AppBarLayout.

The offending line in the layout file is: <android.support.design.widget.AppBarLayout

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 'com.google.android.material:material:1.1.0-alpha03'
    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.

like image 924
Robert Lewis Avatar asked Feb 05 '19 03:02

Robert Lewis


4 Answers

You need to use com.google.android.material.appbar.AppBarLayout.

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

Add dependency implementation 'com.google.android.material:material:1.0.0'

See Material Component integration for latest release version. And use

<com.google.android.material.appbar.AppBarLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

</com.google.android.material.appbar.AppBarLayout>

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

like image 178
ADM Avatar answered Nov 05 '22 23:11

ADM


Please go through this old to new class mappings

eg;- Use com.google.android.material.appbar.AppBarLayout instead of android.support.design.widget.AppBarLayout

For AppBarLayout

enter image description here

For Toolbar

enter image description here

like image 20
Basi Avatar answered Nov 05 '22 21:11

Basi


Androidx inflating class <android.support.design.widget.TabLayout/> will not work it's not exist so replace it with <com.google.android.material.tabs.TabLayout/> it will work fine and don't forgot to add

implementation 'com.google.android.material:material:1.1.0-alpha07'

to your dependencies

like image 9
eng mohamed emam Avatar answered Nov 05 '22 23:11

eng mohamed emam


According to the AndroidX migration docs, the androidx replacement for AppBarLayout is com.google.android.material.appbar.AppBarLayout. 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.

like image 7
Ben P. Avatar answered Nov 05 '22 23:11

Ben P.