【问题标题】:RecyclerView and CardView don't support compileSdkVersion [closed]RecyclerView 和 CardView 不支持 compileSdkVersion [关闭]
【发布时间】:2018-03-16 16:03:10
【问题描述】:

最近我在 gradle 文件中实现了 RecyclerViewCardView 但它们的版本与 compileSdkVersion 不匹配这是我的 build.gradle 文件:

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.mostafa.tostrategies"
        minSdkVersion 24
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'

}

【问题讨论】:

  • 当你使版本匹配时会发生什么?

标签: android android-recyclerview build.gradle android-cardview


【解决方案1】:

替换这些

implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'

implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'

【讨论】:

  • 谢谢,它成功了。
  • 非常欢迎!如果有效,那么您可以接受它作为答案吗
  • 完成完成。
【解决方案2】:

您可以查看official doc

注意:28.0.0-alpha1 是支持 Android P 开发者预览版的预发布版本。

要全面测试您的应用与 Android P 的兼容性并开始使用您必须使用的新 API:

android {
    compileSdkVersion 'android-P'

    defaultConfig {
        targetSdkVersion 'P'
    }
    ...
}

还要注意使用相同版本的支持库。

如果您想使用 v26 版本,只需使用:

implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'

【讨论】:

    【解决方案3】:

    支持库的主版本和recyclerviewcardview必须等于compileSdkVersion

    例如,如果您使用 recyclerview-v7:xx.yy.zz,则您的 compileSdkVersion 必须是 xx

    【讨论】:

    • appcompat 实现中的错误 (com.android.support:appcompat-v7:26.1.0)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 2014-08-18
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 2016-09-23
    相关资源
    最近更新 更多