【问题标题】:How to fix "Failed to resolve: com.google.gson:gson:2.8.5" in Android studio如何在 Android Studio 中修复“无法解析:com.google.gson:gson:2.8.5”
【发布时间】:2019-06-26 18:04:51
【问题描述】:

我正在使用 android studio 创建一个 android 应用程序。我想使用以下依赖 'com.google.gson:gson:2.8.5'。我将它添加到我的应用程序的 build.gradle 中,但遇到以下错误: 无法解析:com.google.gson:gson:2.8.5

我尝试了以下方法: - 降级依赖版本 - 降级 buildToolsVersion 的版本 - 安装 SDK 中所有可用的 Google 软件包 - 将 mavenCentral() 添加到我的 build.gradle 项目中

我的 build.gradle 应用:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.example.topquiz"
        minSdkVersion 15
        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 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'org.jetbrains:annotations-java5:15.0'
    implementation 'com.google.gson:gson:2.8.5' //Store object into SharedPreferences
}

我的 build.gradle 项目:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

非常感谢您的帮助

【问题讨论】:

    标签: java android android-studio gson


    【解决方案1】:

    groupID 应该是 com.google.code.gson 而不是 com.google.gson。

    implementation 'com.google.code.gson:gson:2.8.5'
    

    改成上面的,重新同步项目,错误应该就消失了。

    【讨论】:

    • 非常感谢!我花了很多时间搜索潜水主题,你终于给了我正确的答案!
    • 当我按以下顺序列出存储库时,我开始工作了:jcenter(); google() 在 bulid.gradle 文件的 buildscript { repositories { 块中
    【解决方案2】:

    试试这个 -

    implementation 'com.android.support:multidex:1.0.1'
    implementation 'com.google.code.gson:gson:2.8.0'
    

    并且在项目 gradle 中 -

    classpath 'com.google.gms:google-services:4.2.0'
    

    【讨论】:

      猜你喜欢
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 2019-06-15
      • 2019-03-29
      • 2016-09-17
      相关资源
      最近更新 更多