9

When migrating to AndroidX I faced this problem:

Java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.mandarine.android/com.mandarine.android.features.root.RootActivity}:
android.view.InflateException: Binary XML file line #18: Binary XML file line #18:
Error inflating class android.support.design.widget.AppBarLayout
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
Morozov
  • 4,968
  • 6
  • 39
  • 70

2 Answers2

37

I used AS 3.2 Migrate to AndroidX wizard. But it failed to migrate some classes. Below are some I have encountered on my project. The second entry is the correct one

android.support.design.widget.BottomSheetDialog
com.google.android.material.bottomsheet.BottomSheetDialog 

android.support.design.widget.TextInputLayout
com.google.android.material.textfield.TextInputLayout 

android.support.design.widget.CoordinatorLayout
androidx.coordinatorlayout.widget.CoordinatorLayout

android.support.design.widget.NavigationView
com.google.android.material.navigation.NavigationView

androidx.core.view.ViewPager
androidx.viewpager.widget.ViewPager

android.support.design.widget.BottomSheetBehavior
com.google.android.material.bottomsheet.BottomSheetBehavior 

android.support.v7.widget.Toolbar
androidx.appcompat.widget.Toolbar 

android.support.design.internal.BottomNavigationItemView
com.google.android.material.bottomnavigation.BottomNavigationItemView

android.support.design.internal.BottomNavigationMenuView
com.google.android.material.bottomnavigation.BottomNavigationMenuView 

androidx.appcompat.widget.CardView
androidx.cardview.widget.CardView 

android.support.design.widget.BottomNavigationView
com.google.android.material.bottomnavigation.BottomNavigationView

androidx.core.view.ViewPager
androidx.viewpager.widget.ViewPager

importandroidx.core.widget.DrawerLayout
androidx.drawerlayout.widget.DrawerLayout 

androidx.appcompat.widget.RecyclerView
androidx.recyclerview.widget.RecyclerView 

androidx.core.view.PagerAdapter
androidx.viewpager.widget.PagerAdapter

importandroidx.core.app.FragmentManager
importandroidx.fragment.app.FragmentManager
makata
  • 2,188
  • 2
  • 28
  • 23
  • Also you should replace these lines `android.support.design.widget.FloatingActionButton` with `com.google.android.material.floatingactionbutton.FloatingActionButton` – mDonmez Sep 04 '19 at 05:21
  • 1
    and also `android.support.v7.widget.AppCompatCheckBox` with `androidx.appcompat.widget.AppCompatCheckBox`. – mDonmez Sep 04 '19 at 13:23
  • Also for error `android.support.design.R.id.snackbar_text` use `com.google.android.material.R.id.snackbar_text` – makata Mar 16 '20 at 12:01
13

Unless you implement the old support libraries and enable Jetifier, you have to rename all your support classes in XML.

android.support.design.widget.AppBarLayout is now com.google.android.material.appbar.AppBarLayout.

You may need to use implementation 'com.google.android.material:material:1.0.0-beta01' in your build.gradle for this.

Look for any other Views in XML using the support library and rename the tags to match their AndroidX versions. You can simply search "ClassName AndroidX" in Google and you'll find the documentation for that class.

TheWanderer
  • 16,775
  • 6
  • 49
  • 63
  • Thx, now we can use `implementation 'com.google.android.material:material:1.0.0'` . But could you throw a link where i can find the name of the classes, as for example for `Space` again, I find it difficult to find. Perhaps somewhere there is a complete list of something like https://developer.android.com/jetpack/androidx/migrate – Morozov Nov 06 '18 at 13:38
  • Like I said, you can just Google the class name followed by "AndroidX." – TheWanderer Nov 06 '18 at 13:41
  • Ok, space became`( )`, as a bonus, you may be able to suggest and for `SwipeMenuRecyclerView`? – Morozov Nov 06 '18 at 13:46