Snackbar package in AndroidX

随声附和 提交于 2019-12-23 06:50:11

问题


When migrating a project or switching between branches which are and aren't migrated, Android Studio cannot build projects because it cannot find the android.support.design.widget.Snackbar package. Support/Design packages are removed but the migration table does not list the correct new package for this component.


回答1:


This took a long time to resolve, as until your project successfully builds, autocomplete will not function to lookup packages.

The correct package to use is:

com.google.android.material.snackbar.Snackbar

It is also important to remember to change this on the XML tags as well as the imports if the migration has not worked successfully.




回答2:


Old build artifact com.android.support:design now solves in com.google.android.material:material:1.0.0 for AndroidX build artifact.




回答3:


Add implementation "com.google.android.material:material:1.1.0-alpha02" to your app-level build.gradle.

Also, ensure that your project is set up to migrate old packages to Androidx by including this in your gradle.properties file:

android.useAndroidX=true android.enableJetifier=true




回答4:


Updating to Anko version 0.10.8 will resolve this, it will tell you that snackbar(view, int) is now deprecated, instead of it you will use view.snackbar(int: Message)




回答5:


Import

com.google.android.material.snackbar.Snackbar;

instead of

android.support.design.widget.Snackbar;

if you shifted to androidx and AS couldn't find the package anymore.



来源:https://stackoverflow.com/questions/52593300/snackbar-package-in-androidx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!