Java “如何修复”;未能解析:com.google.gson:gson:2.8.5“;在安卓工作室
我正在使用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项目中 My build.gradle应用程序:Java “如何修复”;未能解析:com.google.gson:gson:2.8.5“;在安卓工作室,java,android,android-studio,gson,Java,Android,Android Studio,Gson,我正在使用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项目中 My build.
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
}
非常感谢您的帮助试试这个-
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'
groupID应该是com.google.code.gson,而不是com.google.gson
implementation 'com.google.code.gson:gson:2.8.5'
将其更改为上述内容,重新同步项目,错误就会消失。非常感谢!我花了很多时间搜索潜水员的话题,你终于给了我正确的答案!当我按以下顺序列出存储库时,我的开始工作:
jcenter();google()
位于bulid.gradle文件的buildscript{repositories{
块中