如何解决“在现有项目中发现依赖项不一致”的问题?

时间:2019-10-13 16:13:59

标签: android kotlin android-recyclerview dependencies

我正在通过观看youtube上的一些教程来学习编写android应用程序。我按照教程进行操作,并尝试在xml文件中添加recyclerview。当我单击recyclerview旁边的下载按钮时,显示以下消息:

“此操作需要库androidx.recyclerview:recyclerview:+。

问题:发现现有项目依赖项中的不一致。 之间的版本不兼容: -androidx.appcompat:appcompat:1.1.0@aar 和: -androidx.core:core-ktx:1.1.0@aar

具有依赖性: -androidx.annotation::1.1.0 与: -androidx.annotation::2.0.0

添加此库后,项目可能无法编译。 您是否仍要添加?”

如果我选择“确定”并继续,则预览屏幕将变为灰色。

我应该怎么做才能解决问题?

当我想在xml文件中添加cardview时,会发生相同的问题。

先谢谢!!!!

build.gradle如下:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.smartherd.msgshareapp"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

1 个答案:

答案 0 :(得分:0)

只需再次构建项目并手动刷新布局即可。 :)