繁体   English   中英

如何修复 Android Studio 中的“无法解析:com.google.gson:gson:2.8.5”

[英]How to fix "Failed to resolve: com.google.gson:gson:2.8.5" in Android studio

我正在使用 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
}

非常感谢您的帮助

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

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

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

尝试这个 -

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'

或者: gradle不能很好地满足您的需求。 我会尝试用以下代码替换行implementation 'com.google.gson:gson:2.8.5'

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM