Android Studio 3.4.3:无法解析依赖关系

时间:2019-08-02 00:56:58

标签: android gradle build

我的构建文件是这样的:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myapp.xkcd_finder"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.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 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    // https://mvnrepository.com/artifact/com.google/gson
    implementation group: 'com.google', name: 'gson', version: '2.8.5'

}

就目前而言,我遇到了一个错误:

ERROR: Failed to resolve: com.google:gson:2.8.5
Show in Project Structure dialog
Affected Modules: app

我尝试重新启动,但是没有成功-错误仍然存​​在。

该如何解决? (我希望我可以回到过去,不更新Android Studio ...:()

1 个答案:

答案 0 :(得分:2)

错误ERROR: Failed to resolve: com.google:gson:2.8.5表示Gradle无法解决依赖关系,因此,我要做的第一件事是检查存储库中的正确信息(例如https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5)。

这样做,我可以看到您的组名错误,应该是:

implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'