问题
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
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/53172571/appbarlayout-inflating-error-after-migrating-to-androidx