问题描述
我正在使用 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"在安卓工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!