我应该在依赖项中使用什么版本的 recyclerview?

What version of recyclerview should I use in dependecies?

我想在我的应用程序中包含 recyclerview,我已经更新了整个 sdk。 android 支持库是版本 17,android 支持库是版本 23。我在 sdk\extras\android\support\v7 目录中有 recyclerview 文件夹。

为了添加库,我将它们放在依赖项中:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:recyclerview-v7:21.0.0.+'
}

当我重建项目时,它显示了这个错误:

   Error:(24, 13) Failed to resolve: com.android.support:recyclerview-v7:21.0.0.+
<a href="install.m2.repo">Install Repository and sync project</a><br><a href="openFile">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>

我应该在依赖项中使用什么版本的 recyclerview?怎么知道呢?

编辑 我在朋友的帮助下解决了最后一个问题,这是新的 gradle :

    dependencies {
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:recyclerview-v7:21.0.0'
}

现在我得到这个错误:

 F:\AndroidStudioProjects\recycleView\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7.0.0\res\values-v17\values-v17.xml
Error:(6, 21) No resource found that matches the given name: attr 'android:textAlignment'.
Error:(10, 21) No resource found that matches the given name: attr 'android:paddingEnd'...............

如何解决这个问题?

最好使用 android 支持的最新依赖项来获取 Android 提供的最新功能和修复。要添加依赖项,请按照以下步骤操作:

  • 在项目资源管理器中右键单击您的应用程序模块。

  • Select "Module Settings" 来自选项菜单。

  • 单击 "Dependency" 选项卡。

  • 单击“+”或“-”按钮添加或删除依赖项。

  • 单击 + 并通过提供名称搜索依赖项,然后单击适当的依赖项。

这样您将获得 android 支持的最新依赖项。

使用 23.0.0

compile 'com.android.support:recyclerview-v7:23.0.0'

你遇到这个问题是因为

compile 'com.android.support:recyclerview-v7:21.0.0.+'

错了

您可以使用

compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.android.support:recyclerview-v7:+'

但是你不能使用

compile 'com.android.support:recyclerview-v7:21.0.0.+'

当然我建议你使用最后一个支持库,目前是 23.1.0

compile 'com.android.support:recyclerview-v7:23.1.0'

注意。这需要用 API 23.

编译

此外,我建议您避免使用 +。这不是一个好的选择,因为这样你以后就不能复制你的构建了。