[英]How to fix "Failed to resolve: com.google.gson:gson:2.8.5" in Android studio
I am creating an android application using android studio.我正在使用 android studio 创建一个 android 应用程序。 I want to use the following dependence 'com.google.gson:gson:2.8.5'.我想使用以下依赖项“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我将它添加到我的应用程序的 build.gradle 中,但遇到以下错误:无法解决:com.google.gson:gson:2.8.5
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我尝试了以下操作: - 降级依赖项的版本 - 降级 buildToolsVersion 的版本 - 安装 SDK 中可用的所有 Google 包 - 将 mavenCentral() 添加到我的 build.gradle 项目
My build.gradle app :我的 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
}
My build.gradle project :我的 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
}
Thank you very much for your help非常感谢您的帮助
The groupID should be com.google.code.gson instead of com.google.gson. groupID应该是com.google.code.gson,而不是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. 将其更改为上述内容,重新同步项目,错误应消失。
Try this - 尝试这个 -
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.google.code.gson:gson:2.8.0'
And in project gradle - 在项目gradle中-
classpath 'com.google.gms:google-services:4.2.0'
Alternatively: gradle
doesn't play nice with what you need here. 或者: gradle
不能很好地满足您的需求。 I would try replacing the line implementation 'com.google.gson:gson:2.8.5'
with this: 我会尝试用以下代码替换行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.