Android sdk 29中导入recyclerview的问题

本人在跟着《第一行代码》(第二版)进行学习当中。进入到学习recyclerview控件时,按照书上的操作,在build.gradle中的dependencies中添加导入语句,如下:

dependencies { complie 'com.android.support:recyclerview-v7:24.2.1' implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05' } 

添加compile语句后,提示错误:
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。
解决方法:
在android sdk29中已经不再这样引入recyclerview。应该采用如下方法。
在android studio的菜单栏中点击File-Project Structure-Dependencies-app-加号-Library Dependency.
然后搜索recycleview,查找最新版本的。点击OK即可。
Android sdk 29中导入recyclerview的问题_第1张图片
使用时这样写:

 <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content"/> 

你可能感兴趣的:(Android sdk 29中导入recyclerview的问题)