Version 28 (intended for Android Pie and below) is the last version of the legacy support library, so we recommend that you migrate to AndroidX libraries when using Android Q and moving forward. The IDE can help with this: Refactor > Migrate to AndroidX... less... (Ctrl+F1)
Inspection info:There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion). Issue id: GradleCompatible
總結原因如下:
1.由於Android Studio 版本較高,添加庫依賴已經不支持compile語句,較高的版本應使用implementation或者api語句。
2.若使用api或implementation語句仍然報錯,可能是庫的版本較低,出現了不兼容的現象。
關於報錯信息大概意思:
依賴庫28號版本是Android Pie 以及以下的版本最新的一個版本,對於Android Q以及以上版本應使用AndroidX庫。由於support 庫太亂了,谷歌在新版本中取消了support庫,使用了新的andriodX庫。
解決方案如下:
Refactor->Migrate to AndroidX->點擊左下角 Do Refactor
(refactor:n.重構)(Migrate:v.遷移)
解決前:
解決後: