我正在尝试使用android support recyclerView小部件,尽管我已将所有依赖项添加到我的build.gradle文件中(我认为),但行“ import android.support.v7.widget.RecyclerView;”在我的活动中没有解决。我是Android Studio的新手,所以我可能缺少一些非常基础的东西。
到目前为止,我已经尝试在项目构建gradle的所有项目以及模块构建gradle的所有项目中添加google存储库。我也改变了依赖关系,并尝试更改版本号。我尝试使缓存无效并重新启动。我似乎确实可以导入“ import androidx.recyclerview.widget.RecyclerView;”,但是与我所听到的不一样。
这是我的构建gradle文件:
//noinspection GradleCompatible
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.chaos"
minSdkVersion 20
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
customDebugType {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:28.0.0'
//implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
androidTestImplementation 'android.arch.persistence.room:testing:1.1.1'
// implementation 'com.android.support:support-v7'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation ('androidx.test.espresso:espresso-core:3.2.0-alpha02', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
然后这是我在主要活动中尝试的导入。看来我可以导入android.support.v4库,但是v7甚至不是自动完成选项。感谢您的帮助!
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
我希望导入行能够解决,因为目前无法解决。
答案 0 :(得分:1)
如果您使用的是Android X,请尝试使用此依赖项
implementation 'androidx.recyclerview:recyclerview:1.0.0'