如何解决“无法解决:com.google.gson:gson:2.8.5"在Android Studio中 [英] How to fix "Failed to resolve: com.google.gson:gson:2.8.5" in Android studio

查看:1943
本文介绍了如何解决“无法解决:com.google.gson:gson:2.8.5"在Android Studio中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating an android application using android studio. I want to use the following dependence 'com.google.gson:gson:2.8.5'. I add it into my build.gradle of my app but I encountered the following error : Failed to resolve: com.google.gson:gson:2.8.5

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

I tried the following : - downgrade the version of the dependence - downgrade the version of the buildToolsVersion - install all Google packages available in the SDK - add mavenCentral() to my build.gradle project

我的build.gradle应用程序:

My build.gradle app :

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项目:

My build.gradle project :

// 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
}

非常感谢您的帮助

推荐答案

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

The groupID should be com.google.code.gson instead of com.google.gson.

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

将其更改为以上内容,重新同步项目,错误应消失.

Change it to the above, resync the project, and the error should go away.

这篇关于如何解决“无法解决:com.google.gson:gson:2.8.5"在Android Studio中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆